use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class SeedStoreManager method removeSeed.
/**
* remove seed from seed store
*
* @param seedLocation
* @return a collection of seeds in the seed store
* @throws IOException
*/
public Collection<Seed> removeSeed(SeedStoreSubType subType, String seedLocation) throws IOException {
Collection<Seed> seeds = new HashSet<>();
SeedStore seedStore = getSeedStore(subType);
if (seedStore == null) {
throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
}
refreshableSeedsMap.remove(seedLocation);
Optional<Seed> seedOptional;
if (subType == SeedStoreSubType.ON_YARN) {
seedOptional = seedStore.get().stream().filter(s -> {
return s.getLocation().equals(seedLocation) || s.getUniqueInstanceId().equals(seedLocation);
}).findFirst();
} else {
seedOptional = seedStore.get().stream().filter(s -> s.getLocation().equals(seedLocation)).findFirst();
}
if (seedOptional.isPresent()) {
seeds = seedStore.remove(Lists.newArrayList(seedOptional.get()));
LOG.debug("Seed=%s removed from seed store", seedLocation);
}
return seeds;
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestSeedStoreManager method testAddToSeedStore.
@Test
public void testAddToSeedStore() throws Exception {
String location1 = "location1";
String location2 = "location2";
seedStoreManager.loadSeedStore();
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location1, false);
seedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, location2, true);
Collection<Seed> result = seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST);
Assert.assertEquals(result.size(), 2);
Assert.assertTrue(result.stream().anyMatch(s -> s.getLocation().equals(location1)));
Assert.assertTrue(result.stream().anyMatch(s -> s.getLocation().equals(location2)));
long timestamp1Old = result.stream().filter(s -> s.getLocation().equals(location1)).findAny().get().getTimestamp();
long timestamp2Old = result.stream().filter(s -> s.getLocation().equals(location2)).findAny().get().getTimestamp();
// wait 2 seconds, seed2 will be updated with new timestamp
Thread.sleep(2000);
result = seedStoreManager.getAllSeeds(SeedStoreSubType.HAZELCAST);
long timestamp1New = result.stream().filter(s -> s.getLocation().equals(location1)).findAny().get().getTimestamp();
long timestamp2New = result.stream().filter(s -> s.getLocation().equals(location2)).findAny().get().getTimestamp();
Assert.assertTrue(timestamp1Old == timestamp1New);
Assert.assertTrue(timestamp2Old < timestamp2New);
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestDynamicFilterSourceOperator method prepareConfigFiles.
@BeforeTest
private void prepareConfigFiles() throws Exception {
File launcherConfigFile = new File(STATE_STORE_CONFIGURATION_PATH);
if (launcherConfigFile.exists()) {
launcherConfigFile.delete();
}
launcherConfigFile.createNewFile();
FileWriter configWriter = new FileWriter(STATE_STORE_CONFIGURATION_PATH);
configWriter.write("state-store.type=hazelcast\n" + "state-store.name=test\n" + "state-store.cluster=test-cluster\n" + "hazelcast.discovery.mode=tcp-ip\n" + "hazelcast.discovery.port=7980\n");
configWriter.close();
Set<Seed> seeds = new HashSet<>();
SeedStore mockSeedStore = mock(SeedStore.class);
Seed mockSeed = mock(Seed.class);
seeds.add(mockSeed);
SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
when(mockSeed.getLocation()).thenReturn("127.0.0.1:6991");
when(mockSeedStore.get()).thenReturn(seeds);
StateStoreFactory factory = new HazelcastStateStoreFactory();
stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
stateStoreProvider.addStateStoreFactory(factory);
createStateStoreCluster("6991");
stateStoreProvider.loadStateStore();
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestHazelcastClusterLifecycleListener method testClusterShutdown.
@Test
void testClusterShutdown() throws InterruptedException {
final long sleep = 30000L;
isClusterShutdownEventCaptured = false;
final StateStore member1 = createStateStoreCluster(PORT1);
final StateStore member2 = createStateStoreCluster(PORT2);
HashSet<Seed> seeds = new HashSet<>(0);
seeds.add(new MockSeed(MEMBER_1_ADDRESS));
seeds.add(new MockSeed(MEMBER_2_ADDRESS));
StateStore client = createStateStoreClient(seeds);
assertFalse(isClusterShutdownEventCaptured);
((HazelcastStateStore) member1).shutdown();
assertFalse(isClusterShutdownEventCaptured);
((HazelcastStateStore) member2).shutdown();
Thread.sleep(sleep);
assertTrue(isClusterShutdownEventCaptured);
}
use of io.prestosql.spi.seedstore.Seed in project hetu-core by openlookeng.
the class TestHazelcastStateStoreFactory method testTcpipCreate.
/**
* Test state store creation with tcp-ip mode
*
* @throws IOException IOException thrown if seedStore read write errors happen
*/
@Test
public void testTcpipCreate() throws IOException {
HazelcastStateStoreFactory factory = new HazelcastStateStoreFactory();
assertEquals(factory.getName(), HAZELCAST);
SeedStoreFactory seedStoreFactory = new FileBasedSeedStoreFactory();
assertEquals(seedStoreFactory.getName(), "filebased");
Map<String, String> properties = new HashMap<>(0);
properties.put(STATE_STORE_CLUSTER_CONFIG_NAME, TEST_CLUSTER_NAME);
properties.put(DISCOVERY_MODE_CONFIG_NAME, DISCOVERY_MODE_TCPIP);
SeedStore seedStore = mock(SeedStore.class);
Seed seed = new FileBasedSeed(MEMBER_ADDRESS, 0);
when(seedStore.get()).thenReturn(ImmutableList.of(seed));
setupHazelcastInstance();
StateStore stateStore = factory.create(TEST_STATE_STORE_NAME, seedStore, properties);
assertEquals(stateStore.getName(), TEST_STATE_STORE_NAME);
StateCollection collection = stateStore.createStateCollection("test", StateCollection.Type.MAP);
((StateMap<String, String>) collection).put(TEST_KEY, TEST_VALUE);
assertEquals(collection.size(), 1);
assertEquals(((StateMap<String, String>) collection).get(TEST_KEY), TEST_VALUE);
((HazelcastStateStore) stateStore).shutdown();
}
Aggregations