{"record":{"id":"31a4e75be2683ff6","repo":"apache/cassandra","slug":"unable-to-cancel-in-progress-compactions-for","errorCode":null,"errorMessage":"Unable to cancel in-progress compactions for ","messagePattern":"Unable to cancel in-progress compactions for ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/db/compaction/CompactionManager.java","lineNumber":1252,"sourceCode":"        Callable<CompactionTasks> taskCreator = () -> {\n            Collection<SSTableReader> sstables = sstablesFn.get();\n            if (sstables == null || sstables.isEmpty())\n            {\n                logger.debug(\"No sstables found for the provided token range\");\n                return CompactionTasks.empty();\n            }\n            return cfStore.getCompactionStrategyManager().getUserDefinedTasks(sstables, cfStore.getDefaultGcBefore(FBUtilities.nowInSeconds()));\n        };\n\n        try (CompactionTasks tasks = cfStore.runWithCompactionsDisabled(taskCreator,\n                                                                        sstablesPredicate,\n                                                                        OperationType.MAJOR_COMPACTION,\n                                                                        false,\n                                                                        false,\n                                                                        false))\n        {\n            if (tasks == null)\n                throw new RuntimeException(\"Unable to cancel in-progress compactions for \" + cfStore.getKeyspaceName() + '.' + cfStore.getTableName() + \". Usually retrying will work.\");\n\n            if (tasks.isEmpty())\n                return;\n\n            Runnable runnable = new WrappedRunnable()\n            {\n                protected void runMayThrow()\n                {\n                    for (AbstractCompactionTask task : tasks)\n                        if (task != null)\n                        {\n                            task.setCompactionType(OperationType.MAJOR_COMPACTION);\n                            task.execute(active);\n                        }\n                }\n            };\n\n            FBUtilities.waitOnFuture(executor.submitIfRunning(runnable, \"force compaction for token range\"));","sourceCodeStart":1234,"sourceCodeEnd":1270,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compaction/CompactionManager.java#L1234-L1270","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nforceCompaction(cfStore, sstablesFn, predicate); // throws when compactions busy\n// after\ntry { forceCompaction(cfStore, sstablesFn, predicate); }\ncatch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to cancel\")) { Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS); retry(); } else throw e; }","handlingStrategy":"retry","validationCode":"// check compaction activity first via JMX / StorageService\nboolean busy = !CompactionManager.instance.getCompactions().isEmpty();\nif (busy) throw new IllegalStateException(\"compactions in progress; defer major compaction\");","typeGuard":null,"tryCatchPattern":"try { forceCompaction(cfs, fn, pred); }\ncatch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to cancel in-progress compactions\")) {\n    Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);\n    // retry with bounded attempts\n  } else throw e;\n}","preventionTips":["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"],"tags":["compaction","retryable","runtime","cassandra"],"backgroundTag":"invalid-state-transition","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}