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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to