From 851d05b32b8515c7c1f1ff0cbb812df62251cd2f Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Thu, 24 Apr 2025 11:56:25 +0800 Subject: [PATCH] [fix][log]Fix compaction service log's wrong condition --- .../pulsar/compaction/CompactedTopicImpl.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java index 5105889a25972..0256b7988c699 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java @@ -84,13 +84,20 @@ public CompletableFuture newCompactedLedger(Position p, l // delete the ledger from the old context once the new one is open return compactedTopicContext.thenCompose(ctx -> { - if (ctx != null && ctx.getLedger() != null && ctx.getLedger().getId() == compactedLedgerId) { - // Print an error log here, which is not expected. - log.error("[__compaction] Using the same compacted ledger to override the old one, which is not" - + " expected and it may cause a ledger lost error. {} -> {}", compactedLedgerId, - ctx.getLedger().getId()); + if (previousContext != null) { + previousContext.thenAccept(previousCtx -> { + // Print an error log here, which is not expected. + if (previousCtx != null && previousCtx.getLedger() != null + && previousCtx.getLedger().getId() == compactedLedgerId) { + log.error("[__compaction] Using the same compacted ledger to override the old one, which is" + + " not expected and it may cause a ledger lost error. {} -> {}", compactedLedgerId, + ctx.getLedger().getId()); + } + }); + return previousContext; + } else { + return CompletableFuture.completedFuture(null); } - return previousContext != null ? previousContext : CompletableFuture.completedFuture(null); }); } }