You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by yo...@apache.org on 2021/03/01 12:07:14 UTC

[pulsar] 02/02: [Issue #8204][pulsar-broker] Fixes first automatic compaction issue (#8209)

This is an automated email from the ASF dual-hosted git repository.

yong pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit cab1d08df8238166b1af4e6c98bd4a2ba760612a
Author: Fernando Miguélez Palomo <fe...@gmail.com>
AuthorDate: Fri Feb 26 09:16:09 2021 +0100

    [Issue #8204][pulsar-broker] Fixes first automatic compaction issue (#8209)
    
    Fixes #8204
    
    ### Motivation
    
    Details are described in the issue and also on previous pull request #8205
    
    ### Modifications
    
    If we have no durable subscriptions yet (e.g. when using `Reader` instead of `Consumer`) use ledger total size instead of estimated backlog size that will always be equal to 0 in this case.
    
    Co-authored-by: Sijie Guo <si...@apache.org>
    Co-authored-by: xiaolong.ran <rx...@apache.org>
    Co-authored-by: penghui <pe...@apache.org>
    Co-authored-by: Miguelez <Mi...@host.docker.internal>
    Co-authored-by: Yong Zhang <zh...@gmail.com>
    (cherry picked from commit 6e6d5b99707166d4c6ce29cfa11c9dbf7e1dbb27)
---
 .../apache/pulsar/broker/service/persistent/PersistentTopic.java   | 7 +++++--
 .../java/org/apache/pulsar/broker/service/PersistentTopicTest.java | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
index 89075df..154471d 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
@@ -1240,8 +1240,11 @@ public class PersistentTopic extends AbstractTopic implements Topic, AddEntryCal
                 if (compactionSub != null) {
                     backlogEstimate = compactionSub.estimateBacklogSize();
                 } else {
-                    // compaction has never run, so take full backlog size
-                    backlogEstimate = ledger.getEstimatedBacklogSize();
+                    // compaction has never run, so take full backlog size,
+                    // or total size if we have no durable subs yet.
+                    backlogEstimate = subscriptions.isEmpty()
+                            ? ledger.getTotalSize()
+                            : ledger.getEstimatedBacklogSize();
                 }
 
                 if (backlogEstimate > compactionThreshold) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
index d2f58fc..b955f2e 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentTopicTest.java
@@ -1534,6 +1534,7 @@ public class PersistentTopicTest extends MockedBookKeeperTestCase {
 
         verify(compactor, times(0)).compact(anyString());
 
+        doReturn(10L).when(ledgerMock).getTotalSize();
         doReturn(10L).when(ledgerMock).getEstimatedBacklogSize();
 
         topic.checkCompaction();