Search in sources :

Example 1 with SeedStore

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

the class TestStateStoreLauncherAndProvider method setUp.

// setup for test provider
@BeforeTest
private void setUp() throws IOException {
    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(LOCALHOST + ":" + PORT3);
    when(mockSeedStore.get()).thenReturn(seeds);
    factory = new HazelcastStateStoreFactory();
    stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
    stateStoreProvider.addStateStoreFactory(factory);
}
Also used : SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) HashSet(java.util.HashSet) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with SeedStore

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

the class SeedStoreManager method refreshSeeds.

private void refreshSeeds(SeedStoreSubType subType) {
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    for (Map.Entry<String, Seed> entry : refreshableSeedsMap.entrySet()) {
        long newTime = System.currentTimeMillis();
        LOG.debug("seed=%s refresh with oldTimestamp=%s and newTimestamp=%s", entry.getKey(), entry.getValue().getTimestamp(), newTime);
        Seed newSeed = seedStore.create(ImmutableMap.of(Seed.LOCATION_PROPERTY_NAME, entry.getKey(), Seed.TIMESTAMP_PROPERTY_NAME, String.valueOf(newTime)));
        try {
            seedStore.add(Lists.newArrayList(newSeed));
            entry.setValue(newSeed);
        } catch (IOException | RuntimeException e) {
            LOG.warn("Error refresh seed=%s with error message: %s, will refresh in next %s milliseconds", entry.getKey(), e.getMessage(), seedHeartBeat);
            continue;
        }
    }
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with SeedStore

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

the class SeedStoreManager method addSeed.

/**
 * Add seed to seed store. If refreshable is enabled, seed will be refreshed periodically
 *
 * @param refreshable
 * @return a collection of seeds in the seed store
 * @throws IOException
 */
public Collection<Seed> addSeed(SeedStoreSubType subType, String seedLocation, boolean refreshable) throws IOException {
    Collection<Seed> seeds = new HashSet<>();
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    Seed seed = seedStore.create(ImmutableMap.of(Seed.LOCATION_PROPERTY_NAME, seedLocation, Seed.TIMESTAMP_PROPERTY_NAME, String.valueOf(System.currentTimeMillis())));
    seeds = addSeed(subType, seed);
    if (refreshable) {
        refreshableSeedsMap.put(seedLocation, seed);
    }
    LOG.debug("Seed=%s added to 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 4 with SeedStore

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

the class SeedStoreManager method updateSeed.

/**
 * Update the existing seed at seedLocation with new properties
 * @param subType
 * @param seedLocation
 * @param updatedProperties
 */
public void updateSeed(SeedStoreSubType subType, String seedLocation, Map<String, String> updatedProperties) {
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    try {
        Collection<Seed> existingSeeds = seedStore.get();
        List<Seed> toUpdate = existingSeeds.stream().filter(s -> {
            return s.getLocation().equals(seedLocation);
        }).collect(Collectors.toList());
        LOG.debug("SeedStoreManager::updateSeed toUpdate.size() is %s", Integer.toString(toUpdate.size()));
        for (Seed s : toUpdate) {
            seedStore.remove(ImmutableList.of(s));
            Seed newSeed = seedStore.create(updatedProperties);
            addSeed(subType, newSeed);
        }
    } catch (IOException e) {
        LOG.warn("Update seed %s failed with error: %s", seedLocation, 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) IOException(java.io.IOException)

Example 5 with SeedStore

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

the class SeedStoreManager method getAllSeeds.

/**
 * Get all seeds from seed store
 *
 * @return a collection of seeds in the seed store
 * @throws IOException
 */
public Collection<Seed> getAllSeeds(SeedStoreSubType subType) throws IOException {
    SeedStore seedStore = getSeedStore(subType);
    if (seedStore == null) {
        throw new PrestoException(SEED_STORE_FAILURE, "Seed store is null");
    }
    Collection<Seed> seeds = seedStore.get();
    return seeds;
}
Also used : Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) PrestoException(io.prestosql.spi.PrestoException)

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