Search before reporting
Read release policy
User environment
- Broker version: 4.2.4
- Present on
master (9ba61bd95de); line numbers below are master.
Issue Description
pulsar_compaction_succeed_count and pulsar_compaction_failed_count do not account for the whole compaction attempt. Compactor.compact() creates the raw reader outside the block that records the counters:
public CompletableFuture<Long> compact(String topic) {
return RawReader.create(pulsar, topic, COMPACTION_SUBSCRIPTION, false, false) // :58
.thenComposeAsync(this::compactAndCloseReader, scheduler);
}
private CompletableFuture<Long> compactAndCloseReader(RawReader reader) {
CompletableFuture<Long> promise = new CompletableFuture<>();
mxBean.addCompactionStartOp(reader.getTopic()); // :64
...
mxBean.addCompactionEndOp(reader.getTopic(), false); // :76
Compactor.java:58-80 → CompactorMXBeanImpl.addCompactionEndOp() → CompactionRecord.compactionFailedCount.
Any failure of RawReader.create() — lookup, connection, authorization, topic-not-found, a client-side error — happens before addCompactionStartOp, so it increments neither counter. The only trace is the Compaction failure. WARN in PersistentTopic's currentCompaction.whenComplete(...) (PersistentTopic.java:4921 on master).
Why it matters
pulsar_compaction_failed_count == 0 is routinely read as "no compaction attempt has failed", and it is used that way when triaging compaction problems. It does not mean that. A topic whose compaction never gets as far as opening a reader looks identical to a topic that is not being compacted at all — both show zero for both counters.
The same applies to any subclass that does work before delegating to Compactor.compact().
Error messages
[<topic>] Compaction failure.
(WARN, from PersistentTopic.java:4921; no counter moves)
Reproducing the issue
Analysis is from code:
- Trigger compaction on a topic where
RawReader.create() will fail — for example revoke the broker client's permission to subscribe, or point compaction at a topic that is being deleted concurrently.
- Observe
pulsar_compaction_failed_count for that topic stays at 0 while the run clearly failed.
Additional information
Suggested fix: move mxBean.addCompactionStartOp(topic) ahead of RawReader.create() (the topic name is already available in compact(String topic)), and record a failure if the reader cannot be created. Alternatively add a distinct counter for setup failures so they are not silently invisible.
Are you willing to submit a PR?
Search before reporting
Read release policy
masterbranch.User environment
master(9ba61bd95de); line numbers below aremaster.Issue Description
pulsar_compaction_succeed_countandpulsar_compaction_failed_countdo not account for the whole compaction attempt.Compactor.compact()creates the raw reader outside the block that records the counters:Compactor.java:58-80→CompactorMXBeanImpl.addCompactionEndOp()→CompactionRecord.compactionFailedCount.Any failure of
RawReader.create()— lookup, connection, authorization, topic-not-found, a client-side error — happens beforeaddCompactionStartOp, so it increments neither counter. The only trace is theCompaction failure.WARN inPersistentTopic'scurrentCompaction.whenComplete(...)(PersistentTopic.java:4921onmaster).Why it matters
pulsar_compaction_failed_count == 0is routinely read as "no compaction attempt has failed", and it is used that way when triaging compaction problems. It does not mean that. A topic whose compaction never gets as far as opening a reader looks identical to a topic that is not being compacted at all — both show zero for both counters.The same applies to any subclass that does work before delegating to
Compactor.compact().Error messages
(WARN, from
PersistentTopic.java:4921; no counter moves)Reproducing the issue
Analysis is from code:
RawReader.create()will fail — for example revoke the broker client's permission to subscribe, or point compaction at a topic that is being deleted concurrently.pulsar_compaction_failed_countfor that topic stays at 0 while the run clearly failed.Additional information
Suggested fix: move
mxBean.addCompactionStartOp(topic)ahead ofRawReader.create()(the topic name is already available incompact(String topic)), and record a failure if the reader cannot be created. Alternatively add a distinct counter for setup failures so they are not silently invisible.Are you willing to submit a PR?