apache/pulsar · error · PulsarAdminException

Error compacting: ${lastError}

Error message

Error compacting: ${lastError}

What it means

During manual topic compaction, the command polls compaction status; if the status transitions to ERROR, it prints 'Error in compaction' and throws PulsarAdminException embedding the broker-reported lastError. This indicates the compaction itself failed server-side, not a CLI input problem.

Source

Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:1325

                while (wait && status.status == LongRunningProcessStatus.Status.RUNNING) {
                    Thread.sleep(1000);
                    status = getTopics().compactionStatus(persistentTopic);
                }

                switch (status.status) {
                case NOT_RUN:
                    System.out.println("Compaction has not been run for " + persistentTopic
                                       + " since broker startup");
                    break;
                case RUNNING:
                    System.out.println("Compaction is currently running");
                    break;
                case SUCCESS:
                    System.out.println("Compaction was a success");
                    break;
                case ERROR:
                    System.out.println("Error in compaction");
                    throw new PulsarAdminException("Error compacting: " + status.lastError);
                }
            } catch (InterruptedException e) {
                throw new PulsarAdminException(e);
            }
        }
    }

    static MessageId findFirstLedgerWithinThreshold(List<PersistentTopicInternalStats.LedgerInfo> ledgers,
                                                    long sizeThreshold) {
        long suffixSize = 0L;

        ledgers = Lists.reverse(ledgers);
        long previousLedger = ledgers.get(0).ledgerId;
        for (PersistentTopicInternalStats.LedgerInfo l : ledgers) {
            suffixSize += l.size;
            if (suffixSize > sizeThreshold) {
                return new MessageIdImpl(previousLedger, 0L, -1);
            }

View on GitHub (pinned to 820761864e)

Solutions

  1. Inspect the message's ${lastError} suffix and the broker logs for the root cause
  2. Check BookKeeper health (disk space, ledger availability) for the ledgers backing the topic
  3. Verify the compaction worker/executor is configured and running on the broker
  4. Fix the underlying issue and re-run the compaction command

Example fix

// before
pulsar-admin topics compact persistent://my-tenant/my-ns/my-topic   # fails with 'Error compacting: ...'
// after
# after fixing broker/BK issue
pulsar-admin topics compact persistent://my-tenant/my-ns/my-topic
Defensive patterns

Strategy: try-catch

Validate before calling

// Check compaction status before/after triggering
CompactionStatus status = admin.topics().compactionStatus(topic);
if (status.getStatus() == CompactionStatus.Status.ERROR) {
    log.error("Compaction failed: {}", status.getLastError());
}

Try / catch

try {
    admin.topics().compact(topic);
    admin.topics().compactionStatus(topic).waitForCompletion();
} catch (org.apache.pulsar.client.admin.PulsarAdminException e) {
    log.error("Compaction failed server-side: {}", e.getMessage(), e);
    // inspect broker logs / BookKeeper health
}

Prevention

When it happens

Trigger: Running `pulsar-admin topics compact` (and waiting/`status`) when the broker-side compaction fails — e.g. bookkeeper write errors, ledger read failures, or the compaction worker being unavailable.

Common situations: BookKeeper cluster issues (disk full, ledger corruption); compaction service not deployed/misconfigured; topic ledgers unreadable during compaction.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/464a5ce21d90e67a. Report an issue: GitHub.