Search in sources :

Example 6 with Seed

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;
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException) HashSet(java.util.HashSet)

Example 7 with Seed

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);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) HetuFileSystemClient(io.prestosql.spi.filesystem.HetuFileSystemClient) SeedStoreSubType(io.prestosql.spi.seedstore.SeedStoreSubType) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) BeforeTest(org.testng.annotations.BeforeTest) Map(java.util.Map) ImmutableSet(com.google.common.collect.ImmutableSet) SeedStore(io.prestosql.spi.seedstore.SeedStore) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) FileWriter(java.io.FileWriter) Seed(io.prestosql.spi.seedstore.Seed) Set(java.util.Set) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) Objects(java.util.Objects) Matchers.any(org.mockito.Matchers.any) HAZELCAST_DISCOVERY_TCPIP_SEEDS(io.prestosql.statestore.StateStoreConstants.HAZELCAST_DISCOVERY_TCPIP_SEEDS) Assert(io.prestosql.testing.assertions.Assert) HAZELCAST_DISCOVERY_TCPIP_PROFILE(io.prestosql.statestore.StateStoreConstants.HAZELCAST_DISCOVERY_TCPIP_PROFILE) Mockito.mock(org.mockito.Mockito.mock) Seed(io.prestosql.spi.seedstore.Seed) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with Seed

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();
}
Also used : LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) Seed(io.prestosql.spi.seedstore.Seed) FileWriter(java.io.FileWriter) SeedStore(io.prestosql.spi.seedstore.SeedStore) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) File(java.io.File) HashSet(java.util.HashSet) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) StateStoreFactory(io.prestosql.spi.statestore.StateStoreFactory) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with Seed

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);
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) StateStore(io.prestosql.spi.statestore.StateStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with Seed

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();
}
Also used : FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) StateCollection(io.prestosql.spi.statestore.StateCollection) StateMap(io.prestosql.spi.statestore.StateMap) StateStore(io.prestosql.spi.statestore.StateStore) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Seed(io.prestosql.spi.seedstore.Seed) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) SeedStore(io.prestosql.spi.seedstore.SeedStore) FileBasedSeedStoreFactory(io.hetu.core.seedstore.filebased.FileBasedSeedStoreFactory) Test(org.testng.annotations.Test)

Aggregations

Seed (io.prestosql.spi.seedstore.Seed)29 SeedStore (io.prestosql.spi.seedstore.SeedStore)21 HashSet (java.util.HashSet)20 IOException (java.io.IOException)15 Map (java.util.Map)12 PrestoException (io.prestosql.spi.PrestoException)11 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 HetuFileSystemClient (io.prestosql.spi.filesystem.HetuFileSystemClient)8 Set (java.util.Set)8 Test (org.testng.annotations.Test)8 Logger (io.airlift.log.Logger)7 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)7 File (java.io.File)7 Collectors (java.util.stream.Collectors)7 BeforeTest (org.testng.annotations.BeforeTest)7 FileBasedLock (io.prestosql.spi.filesystem.FileBasedLock)6 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)6 Paths (java.nio.file.Paths)6 Lock (java.util.concurrent.locks.Lock)6