apache/pulsar · warning · org.apache.pulsar.broker.service.AlreadyRunningException
Compaction already in progress
Error message
Compaction already in progress
What it means
A topic can run only one compaction at a time; PersistentTopic tracks the in-flight compaction via a currentCompaction CompletableFuture. If triggerCompaction is called while a previous compaction has not finished, it throws AlreadyRunningException('Compaction already in progress'). This prevents two compaction runs from racing on the same ledger/topic.
Source
Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:4925
return;
}
if (strategicCompactionMap.containsKey(topic)) {
currentCompaction = brokerService.pulsar().getStrategicCompactor()
.compact(topic, strategicCompactionMap.get(topic));
} else {
currentCompaction = topicCompactionService.compact().thenApply(x -> null);
}
} finally {
lock.readLock().unlock();
}
currentCompaction.whenComplete((ignore, ex) -> {
if (ex != null) {
log.warn().exception(ex).log("Compaction failure.");
}
});
} else {
throw new AlreadyRunningException("Compaction already in progress");
}
}
public synchronized LongRunningProcessStatus compactionStatus() {
final CompletableFuture<Long> current;
synchronized (this) {
current = currentCompaction;
}
if (!current.isDone()) {
return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.RUNNING);
} else {
try {
if (Objects.equals(current.join(), COMPACTION_NEVER_RUN)) {
return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.NOT_RUN);
} else {
return LongRunningProcessStatus.forStatus(LongRunningProcessStatus.Status.SUCCESS);
}
} catch (CancellationException | CompletionException e) {View on GitHub (pinned to 820761864e)
Solutions
- Poll admin topics().compactionStatus() and only trigger when the status is NOT running (NOT_RUN/SUCCESS/ERROR)
- Skip triggering on AlreadyRunningException and treat it as 'compaction already handled'
- Reduce trigger frequency for scheduled compaction or add jitter/locking around the trigger call
- Investigate why compaction is slow (huge backlog, resource limits) if it seems permanently stuck
Example fix
// before
admin.topics().triggerCompaction(topic); // throws if already running
// after
if (!LongRunningProcessStatus.Status.RUNNING.equals(admin.topics().compactionStatus(topic).status)) {
admin.topics().triggerCompaction(topic);
} Defensive patterns
Strategy: try-catch
Validate before calling
LongRunningProcessStatus st = admin.topics().compactionStatus(topic);
if (st.status == LongRunningProcessStatus.Status.RUNNING) {
return; // skip trigger
} Type guard
boolean canTriggerCompaction(LongRunningProcessStatus s) {
return s != null && s.status != LongRunningProcessStatus.Status.RUNNING;
} Try / catch
try {
admin.topics().triggerCompaction(topic);
} catch (PulsarAdminException e) {
if (e.getCause() instanceof AlreadyRunningException) {
log.info("Compaction already running on {}", topic);
} else throw e;
} Prevention
- Poll compactionStatus() before every trigger
- Make scheduled compaction jobs idempotent (skip if RUNNING)
- Use intervals longer than worst-case compaction duration for large topics
When it happens
Trigger: Calling admin topics().triggerCompaction() (REST or CLI) on a topic whose currentCompaction future is not yet done — e.g. invoking it twice in a row, or an automated job firing while a long-running compaction is still active.
Common situations: Scheduled compaction jobs overlapping with manually triggered compaction; very large topics where compaction takes hours; CI scripts retrying triggerCompaction without checking status; cron intervals shorter than compaction duration.
Related errors
- Offload already in progress
- The topic has a max partition index of %d, the number of par
- entryFilterNames can't be empty. To remove entry filters use
- The offloadPolicies must be specified for namespace offload.
- The driver is not supported, support value: ${supportedDrive
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/cecda634cbbbc7f1.
Report an issue: GitHub.