You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/28 07:32:55 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #19017: [fix][broker] Fix estimateBacklogFromPosition if position is greater than the greatest ledgerId

AnonHxy commented on code in PR #19017:
URL: https://github.com/apache/pulsar/pull/19017#discussion_r1058121801


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -1269,14 +1269,15 @@ public long getEstimatedBacklogSize(PositionImpl pos) {
 
     long estimateBacklogFromPosition(PositionImpl pos) {
         synchronized (this) {
-            LedgerInfo ledgerInfo = ledgers.get(pos.getLedgerId());
-            if (ledgerInfo == null) {
-                return getTotalSize(); // position no longer in managed ledger, so return total size
+            Map<Long, LedgerInfo> tailLedgerInfos = ledgers.tailMap(pos.getLedgerId());
+            if (tailLedgerInfos.isEmpty()) { // pos is greater than the greatest ledgerId in ledgers
+                return 0;
             }
-            long sizeBeforePosLedger = ledgers.values().stream().filter(li -> li.getLedgerId() < pos.getLedgerId())
-                    .mapToLong(LedgerInfo::getSize).sum();
-            long size = getTotalSize() - sizeBeforePosLedger;
-
+            LedgerInfo ledgerInfo = tailLedgerInfos.get(pos.getLedgerId());
+            if (ledgerInfo == null) { // pos is smaller than the smallest ledgerId in ledgers

Review Comment:
   Fixed @congbobo184 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org