Search in sources :

Example 1 with CompactionJob

use of org.apache.accumulo.core.spi.compaction.CompactionJob in project accumulo by apache.

the class CompactionService method submitCompactionJob.

private void submitCompactionJob(CompactionPlan plan, Compactable.Files files, Compactable compactable, Consumer<Compactable> completionCallback) {
    // log error if tablet is metadata and compaction is external
    var execIds = plan.getJobs().stream().map(cj -> (CompactionExecutorIdImpl) cj.getExecutor());
    if (compactable.getExtent().isMeta() && execIds.anyMatch(ceid -> ceid.isExternalId())) {
        log.error("Compacting metadata tablets on external compactors is not supported, please change " + "config for compaction service ({}) and/or table ASAP.  {} is not compacting, " + "ignoring plan {}", myId, compactable.getExtent(), plan);
        return;
    }
    Set<CompactionJob> jobs = new HashSet<>(plan.getJobs());
    Collection<SubmittedJob> submitted = submittedJobs.getOrDefault(compactable.getExtent(), List.of());
    if (!submitted.isEmpty()) {
        submitted.removeIf(sj -> {
            // to avoid race conditions, only read status once and use local var for the two compares
            var status = sj.getStatus();
            return status != Status.QUEUED && status != Status.RUNNING;
        });
    }
    if (reconcile(jobs, submitted)) {
        for (CompactionJob job : jobs) {
            CompactionExecutor executor = executors.get(job.getExecutor());
            var submittedJob = executor.submit(myId, job, compactable, completionCallback);
            // its important that the collection created in computeIfAbsent supports concurrency
            submittedJobs.computeIfAbsent(compactable.getExtent(), k -> new ConcurrentLinkedQueue<>()).add(submittedJob);
        }
        if (!jobs.isEmpty()) {
            log.trace("Submitted compaction plan {} id:{} files:{} plan:{}", compactable.getExtent(), myId, files, plan);
        }
    } else {
        log.trace("Did not submit compaction plan {} id:{} files:{} plan:{}", compactable.getExtent(), myId, files, plan);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) CompactionPlan(org.apache.accumulo.core.spi.compaction.CompactionPlan) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompactionExecutorIdImpl(org.apache.accumulo.core.util.compaction.CompactionExecutorIdImpl) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) CompactableFile(org.apache.accumulo.core.client.admin.compaction.CompactableFile) PlanningParameters(org.apache.accumulo.core.spi.compaction.CompactionPlanner.PlanningParameters) ConfigurationTypeHelper(org.apache.accumulo.core.conf.ConfigurationTypeHelper) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CompactionKind(org.apache.accumulo.core.spi.compaction.CompactionKind) Map(java.util.Map) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) CompactionExecutorId(org.apache.accumulo.core.spi.compaction.CompactionExecutorId) Status(org.apache.accumulo.tserver.compactions.SubmittedJob.Status) ExecutorService(java.util.concurrent.ExecutorService) CompactionPlanner(org.apache.accumulo.core.spi.compaction.CompactionPlanner) Logger(org.slf4j.Logger) EnumMap(java.util.EnumMap) ServerContext(org.apache.accumulo.server.ServerContext) Collection(java.util.Collection) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) CompactionExecutorsMetrics(org.apache.accumulo.tserver.metrics.CompactionExecutorsMetrics) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) ThreadPools(org.apache.accumulo.core.util.threads.ThreadPools) CompactionPlanImpl(org.apache.accumulo.core.util.compaction.CompactionPlanImpl) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CompactionPlannerInitParams(org.apache.accumulo.core.util.compaction.CompactionPlannerInitParams) CType(org.apache.accumulo.tserver.compactions.CompactionExecutor.CType) CompactionJob(org.apache.accumulo.core.spi.compaction.CompactionJob) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) CompactionServiceId(org.apache.accumulo.core.spi.compaction.CompactionServiceId) RateLimiter(org.apache.accumulo.core.util.ratelimit.RateLimiter) SharedRateLimiterFactory(org.apache.accumulo.core.util.ratelimit.SharedRateLimiterFactory) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompactionJob(org.apache.accumulo.core.spi.compaction.CompactionJob) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HashSet(java.util.HashSet)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1