Search in sources :

Example 1 with CompactionPlan

use of org.apache.accumulo.core.spi.compaction.CompactionPlan 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)

Example 2 with CompactionPlan

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

the class CompactionService method submitCompaction.

/**
 * Get compaction plan for the provided compactable tablet and possibly submit for compaction.
 * Plans get added to the planning queue before calling the planningExecutor to get the plan. If
 * no files are selected, return. Otherwise, submit the compaction job.
 */
public void submitCompaction(CompactionKind kind, Compactable compactable, Consumer<Compactable> completionCallback) {
    Objects.requireNonNull(compactable);
    // add tablet to planning queue and use planningExecutor to get the plan
    if (queuedForPlanning.get(kind).putIfAbsent(compactable.getExtent(), compactable) == null) {
        try {
            planningExecutor.execute(() -> {
                try {
                    Optional<Compactable.Files> files = compactable.getFiles(myId, kind);
                    if (files.isEmpty() || files.get().candidates.isEmpty()) {
                        log.trace("Compactable returned no files {} {}", compactable.getExtent(), kind);
                    } else {
                        CompactionPlan plan = getCompactionPlan(kind, files.get(), compactable);
                        submitCompactionJob(plan, files.get(), compactable, completionCallback);
                    }
                } finally {
                    queuedForPlanning.get(kind).remove(compactable.getExtent());
                }
            });
        } catch (RejectedExecutionException e) {
            queuedForPlanning.get(kind).remove(compactable.getExtent());
            throw e;
        }
    }
}
Also used : CompactionPlan(org.apache.accumulo.core.spi.compaction.CompactionPlan) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with CompactionPlan

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

the class CompactionService method getCompactionPlan.

private CompactionPlan getCompactionPlan(CompactionKind kind, Compactable.Files files, Compactable compactable) {
    PlanningParameters params = new CpPlanParams(kind, compactable, files);
    log.trace("Planning compactions {} {} {} {}", planner.getClass().getName(), compactable.getExtent(), kind, files);
    CompactionPlan plan;
    try {
        plan = planner.makePlan(params);
    } catch (RuntimeException e) {
        log.debug("Planner failed {} {} {} {}", planner.getClass().getName(), compactable.getExtent(), kind, files, e);
        throw e;
    }
    return convertPlan(plan, kind, files.allFiles, files.candidates);
}
Also used : CompactionPlan(org.apache.accumulo.core.spi.compaction.CompactionPlan) PlanningParameters(org.apache.accumulo.core.spi.compaction.CompactionPlanner.PlanningParameters)

Aggregations

CompactionPlan (org.apache.accumulo.core.spi.compaction.CompactionPlan)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 PlanningParameters (org.apache.accumulo.core.spi.compaction.CompactionPlanner.PlanningParameters)2 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