Search in sources :

Example 1 with SeedStoreSubType

use of io.prestosql.spi.seedstore.SeedStoreSubType 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 2 with SeedStoreSubType

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

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Inject (com.google.inject.Inject)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 ConfigurationLoader.loadPropertiesFrom (io.airlift.configuration.ConfigurationLoader.loadPropertiesFrom)2 Logger (io.airlift.log.Logger)2 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)2 PrestoException (io.prestosql.spi.PrestoException)2 SEED_STORE_FAILURE (io.prestosql.spi.StandardErrorCode.SEED_STORE_FAILURE)2 ThreadContextClassLoader (io.prestosql.spi.classloader.ThreadContextClassLoader)2 HetuFileSystemClient (io.prestosql.spi.filesystem.HetuFileSystemClient)2 Seed (io.prestosql.spi.seedstore.Seed)2 SeedStore (io.prestosql.spi.seedstore.SeedStore)2 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)2 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)2 StateStoreConstants (io.prestosql.statestore.StateStoreConstants)2 File (java.io.File)2