apache/cassandra · warning · RuntimeException
Unable to cancel in-progress compactions for
Error message
Unable to cancel in-progress compactions for
What it means
CompactionManager.forceCompaction (and similar forced-compaction paths) must first pause in-flight compactions via ColumnFamilyStore.runWithCompactionsDisabled. That helper returns null when it fails to obtain the compaction lock (i.e. it could not cancel/disable running compactions within its wait window). Cassandra throws this RuntimeException rather than silently proceeding, because running a forced compaction concurrently with in-flight compactions would corrupt lifecycle assumptions.
Source
Thrown at src/java/org/apache/cassandra/db/compaction/CompactionManager.java:1252
Callable<CompactionTasks> taskCreator = () -> {
Collection<SSTableReader> sstables = sstablesFn.get();
if (sstables == null || sstables.isEmpty())
{
logger.debug("No sstables found for the provided token range");
return CompactionTasks.empty();
}
return cfStore.getCompactionStrategyManager().getUserDefinedTasks(sstables, cfStore.getDefaultGcBefore(FBUtilities.nowInSeconds()));
};
try (CompactionTasks tasks = cfStore.runWithCompactionsDisabled(taskCreator,
sstablesPredicate,
OperationType.MAJOR_COMPACTION,
false,
false,
false))
{
if (tasks == null)
throw new RuntimeException("Unable to cancel in-progress compactions for " + cfStore.getKeyspaceName() + '.' + cfStore.getTableName() + ". Usually retrying will work.");
if (tasks.isEmpty())
return;
Runnable runnable = new WrappedRunnable()
{
protected void runMayThrow()
{
for (AbstractCompactionTask task : tasks)
if (task != null)
{
task.setCompactionType(OperationType.MAJOR_COMPACTION);
task.execute(active);
}
}
};
FBUtilities.waitOnFuture(executor.submitIfRunning(runnable, "force compaction for token range"));View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Retry the operation after a short delay - the message itself notes 'Usually retrying will work'
- Reduce concurrent compaction pressure (lower concurrent_compactors or compaction_throughput is not needed; wait for backlog to shrink)
- Use nodetool stop COMPACTION to halt current compactions, then retry
- Schedule major compactions during low-write windows
Example fix
// before
forceCompaction(cfStore, sstablesFn, predicate); // throws when compactions busy
// after
try { forceCompaction(cfStore, sstablesFn, predicate); }
catch (RuntimeException e) { if (e.getMessage().startsWith("Unable to cancel")) { Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS); retry(); } else throw e; } Defensive patterns
Strategy: retry
Validate before calling
// check compaction activity first via JMX / StorageService
boolean busy = !CompactionManager.instance.getCompactions().isEmpty();
if (busy) throw new IllegalStateException("compactions in progress; defer major compaction"); Try / catch
try { forceCompaction(cfs, fn, pred); }
catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Unable to cancel in-progress compactions")) {
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
// retry with bounded attempts
} else throw e;
} Prevention
- Schedule major compactions during low-write windows
- Check nodetool compactionstats for active compactions before forcing
- Bound retries with exponential backoff
- Avoid forcing compaction during repair or bulk loads
When it happens
Trigger: Calling forceCompaction / nodetool-triggered major compaction (or compact with token ranges) on a table that has active compactions that cannot be cancelled within runWithCompactionsDisabled's timeout; the returned CompactionTasks is null.
Common situations: Tables under heavy continuous write load with constant background compaction; large compaction storms after bulk loading; issuing major compaction while incremental repair or anticompaction is running; repeated compact requests on a busy node.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Unable to cancel in-progress compactions for {keyspace}.{tab
- concurrent_compactors should be strictly greater than 0, but
- Could not set new local compaction strategy: <cause message>
- The min_compaction_threshold cannot be larger than the max_c
- Disabling compaction by setting min_compaction_threshold or
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/31a4e75be2683ff6.
Report an issue: GitHub.