Search in sources :

Example 11 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore 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)

Example 12 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class SeedStoreManager method clearExpiredSeeds.

/**
 * Clear expired seed in the seed store
 *
 * @throws IOException
 */
public void clearExpiredSeeds(SeedStoreSubType subType) throws IOException {
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    try {
        Collection<Seed> expiredSeeds = seedStore.get().stream().filter(s -> (System.currentTimeMillis() - s.getTimestamp() > seedHeartBeatTimeout)).collect(Collectors.toList());
        if (expiredSeeds.size() > 0) {
            LOG.info("Expired seeds=%s will be cleared", expiredSeeds);
            seedStore.remove(expiredSeeds);
        }
    } catch (RuntimeException e) {
        LOG.warn("clearExpiredSeed failed with following message: %s", e.getMessage());
    }
}
Also used : Logger(io.airlift.log.Logger) HetuFileSystemClient(io.prestosql.spi.filesystem.HetuFileSystemClient) SEED_STORE_FAILURE(io.prestosql.spi.StandardErrorCode.SEED_STORE_FAILURE) Inject(com.google.inject.Inject) SeedStoreSubType(io.prestosql.spi.seedstore.SeedStoreSubType) HashMap(java.util.HashMap) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) ConfigurationLoader.loadPropertiesFrom(io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) InvalidParameterException(java.security.InvalidParameterException) Locale(java.util.Locale) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PrestoException(io.prestosql.spi.PrestoException) SeedStore(io.prestosql.spi.seedstore.SeedStore) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Seed(io.prestosql.spi.seedstore.Seed) IOException(java.io.IOException) ThreadContextClassLoader(io.prestosql.spi.classloader.ThreadContextClassLoader) Collectors(java.util.stream.Collectors) File(java.io.File) String.format(java.lang.String.format) SeedStoreFactory(io.prestosql.spi.seedstore.SeedStoreFactory) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Paths(java.nio.file.Paths) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) StateStoreConstants(io.prestosql.statestore.StateStoreConstants) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException)

Example 13 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class SeedStoreManager method addSeed.

private Collection<Seed> addSeed(SeedStoreSubType subType, Seed seed) throws IOException {
    int retryTimes = 0;
    long retryInterval = 0L;
    Collection<Seed> seeds = null;
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    do {
        try {
            TimeUnit.MILLISECONDS.sleep(retryInterval);
            seeds = seedStore.add(Lists.newArrayList(seed));
        } catch (InterruptedException | RuntimeException e) {
            LOG.warn("add seed=%s failed: %s, will retry at times: %s", seed, e.getMessage(), retryTimes);
        } finally {
            retryTimes++;
            retryInterval += SEED_RETRY_INTERVAL;
        }
    } while (retryTimes <= SEED_RETRY_TIMES && (seeds == null || seeds.size() == 0));
    if (seeds == null || seeds.size() == 0) {
        throw new PrestoException(SEED_STORE_FAILURE, String.format(Locale.ROOT, "add seed=%s to seed store failed after retry:%d", seed.getLocation(), SEED_RETRY_TIMES));
    }
    return seeds;
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException)

Example 14 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class SeedStoreManager method getLatestSeedLocation.

/**
 * Get all seeds from seed store
 *
 * @return the latest seed location in the seed store - https or http
 * @throws IOException
 */
public String getLatestSeedLocation(SeedStoreSubType subType, boolean httpsRequired) throws IOException {
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    Collection<Seed> seeds = seedStore.get();
    if (seeds.isEmpty()) {
        return null;
    }
    ArrayList<Seed> list = seeds.stream().filter(seed -> {
        if (httpsRequired) {
            return seed.getLocation().contains("https:");
        } else {
            return seed.getLocation().contains("http:");
        }
    }).sorted(Comparator.comparing(Seed::getTimestamp)).collect(toCollection(ArrayList::new));
    if (list.isEmpty()) {
        return null;
    } else {
        return list.get(list.size() - 1).getLocation();
    }
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException)

Example 15 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestStateStoreLauncherAndProvider method testLaunchAndFailure.

// Test Launcher
@Test
public void testLaunchAndFailure() throws Exception {
    Set<Seed> seeds = new HashSet<>();
    SeedStore mockSeedStore = mock(SeedStore.class);
    Seed mockSeed1 = mock(Seed.class);
    Seed mockSeed2 = mock(Seed.class);
    seeds.add(mockSeed1);
    seeds.add(mockSeed2);
    when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
    when(mockSeed2.getLocation()).thenReturn(LOCALHOST + ":" + PORT2);
    when(mockSeedStore.get()).thenReturn(seeds);
    SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
    when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
    when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
    when(mockSeedStoreManager.getFileSystemClient()).thenReturn(new HetuLocalFileSystemClient(new LocalConfig(new Properties()), Paths.get("/")));
    InternalCommunicationConfig mockInternalCommunicationConfig = mock(InternalCommunicationConfig.class);
    HttpServerInfo mockHttpServerInfo = mock(HttpServerInfo.class);
    when(mockHttpServerInfo.getHttpsUri()).thenReturn(new URI("https://" + LOCALHOST + ":" + PORT1));
    when(mockInternalCommunicationConfig.isHttpsRequired()).thenReturn(true);
    EmbeddedStateStoreLauncher launcher = new EmbeddedStateStoreLauncher(mockSeedStoreManager, mockInternalCommunicationConfig, mockHttpServerInfo, new HetuConfig());
    StateStoreBootstrapper bootstrapper = new HazelcastStateStoreBootstrapper();
    launcher.addStateStoreBootstrapper(bootstrapper);
    launcher.launchStateStore();
    StateStore second = setupSecondInstance();
    // mock "remove" second instance from cluster (delete from seed store)
    seeds.remove(mockSeed2);
    when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
    when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
    ((HazelcastStateStore) second).shutdown();
    // Allow the first node to handle failure
    Thread.sleep(3000L);
}
Also used : HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) LocalConfig(io.hetu.core.filesystem.LocalConfig) StateStore(io.prestosql.spi.statestore.StateStore) HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) Properties(java.util.Properties) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) URI(java.net.URI) HetuConfig(io.prestosql.utils.HetuConfig) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) HetuLocalFileSystemClient(io.hetu.core.filesystem.HetuLocalFileSystemClient) HttpServerInfo(io.airlift.http.server.HttpServerInfo) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) StateStoreBootstrapper(io.prestosql.spi.statestore.StateStoreBootstrapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Aggregations

SeedStore (io.prestosql.spi.seedstore.SeedStore)18 Seed (io.prestosql.spi.seedstore.Seed)15 PrestoException (io.prestosql.spi.PrestoException)9 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)7 Map (java.util.Map)6 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SeedStoreManager (io.prestosql.seedstore.SeedStoreManager)4 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)4 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)4 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Logger (io.airlift.log.Logger)3 ThreadContextClassLoader (io.prestosql.spi.classloader.ThreadContextClassLoader)3 StateStore (io.prestosql.spi.statestore.StateStore)3 LocalStateStoreProvider (io.prestosql.statestore.LocalStateStoreProvider)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 Test (org.testng.annotations.Test)3