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);
}
}
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;
}
}
}
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);
}
Aggregations