Search in sources :

Example 1 with CLEANABLE_SHARDS_BATCH_SIZE

use of com.facebook.presto.raptor.metadata.ShardDao.CLEANABLE_SHARDS_BATCH_SIZE in project presto by prestodb.

the class ShardCleaner method cleanBackupShards.

@VisibleForTesting
void cleanBackupShards() {
    Set<UUID> processing = newConcurrentHashSet();
    BlockingQueue<UUID> completed = new LinkedBlockingQueue<>();
    boolean fill = true;
    while (!Thread.currentThread().isInterrupted()) {
        // get a new batch if any completed and we are under the batch size
        Set<UUID> uuids = ImmutableSet.of();
        if (fill && (processing.size() < CLEANABLE_SHARDS_BATCH_SIZE)) {
            uuids = dao.getCleanableShardsBatch(maxTimestamp(backupCleanTime));
            fill = false;
        }
        if (uuids.isEmpty() && processing.isEmpty()) {
            break;
        }
        // skip any that are already processing and mark remaining as processing
        uuids = ImmutableSet.copyOf(difference(uuids, processing));
        processing.addAll(uuids);
        // execute deletes
        for (UUID uuid : uuids) {
            runAsync(() -> backupStore.get().deleteShard(uuid), backupExecutor).thenAccept(v -> completed.add(uuid)).whenComplete((v, e) -> {
                if (e != null) {
                    log.error(e, "Error cleaning backup shard: %s", uuid);
                    backupJobErrors.update(1);
                    processing.remove(uuid);
                }
            });
        }
        // get the next batch of completed deletes
        int desired = min(100, processing.size());
        Collection<UUID> done = drain(completed, desired, 100, MILLISECONDS);
        if (done.isEmpty()) {
            continue;
        }
        // remove completed deletes from database
        processing.removeAll(done);
        dao.deleteCleanedShards(done);
        backupShardsCleaned.update(done.size());
        fill = true;
    }
}
Also used : Nested(org.weakref.jmx.Nested) Logger(io.airlift.log.Logger) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CounterStat(io.airlift.stats.CounterStat) HashMap(java.util.HashMap) CLEANABLE_SHARDS_BATCH_SIZE(com.facebook.presto.raptor.metadata.ShardDao.CLEANABLE_SHARDS_BATCH_SIZE) BackupStore(com.facebook.presto.raptor.backup.BackupStore) Duration(io.airlift.units.Duration) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) Managed(org.weakref.jmx.Managed) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StorageService(com.facebook.presto.raptor.storage.StorageService) DaoSupplier(com.facebook.presto.raptor.util.DaoSupplier) ExecutorService(java.util.concurrent.ExecutorService) Collectors.toSet(java.util.stream.Collectors.toSet) CompletableFuture.runAsync(java.util.concurrent.CompletableFuture.runAsync) ImmutableSet(com.google.common.collect.ImmutableSet) NodeManager(com.facebook.presto.spi.NodeManager) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) CLEANUP_TRANSACTIONS_BATCH_SIZE(com.facebook.presto.raptor.metadata.ShardDao.CLEANUP_TRANSACTIONS_BATCH_SIZE) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) UUID(java.util.UUID) Math.min(java.lang.Math.min) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Ticker(com.google.common.base.Ticker) GuardedBy(javax.annotation.concurrent.GuardedBy) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SECONDS(java.util.concurrent.TimeUnit.SECONDS) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BackupStore (com.facebook.presto.raptor.backup.BackupStore)1 CLEANABLE_SHARDS_BATCH_SIZE (com.facebook.presto.raptor.metadata.ShardDao.CLEANABLE_SHARDS_BATCH_SIZE)1 CLEANUP_TRANSACTIONS_BATCH_SIZE (com.facebook.presto.raptor.metadata.ShardDao.CLEANUP_TRANSACTIONS_BATCH_SIZE)1 StorageService (com.facebook.presto.raptor.storage.StorageService)1 DaoSupplier (com.facebook.presto.raptor.util.DaoSupplier)1 NodeManager (com.facebook.presto.spi.NodeManager)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Ticker (com.google.common.base.Ticker)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets.difference (com.google.common.collect.Sets.difference)1 Sets.newConcurrentHashSet (com.google.common.collect.Sets.newConcurrentHashSet)1 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)1 Logger (io.airlift.log.Logger)1 CounterStat (io.airlift.stats.CounterStat)1 Duration (io.airlift.units.Duration)1 File (java.io.File)1 Math.min (java.lang.Math.min)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1