congbobo184 commented on code in PR #19017:
URL: https://github.com/apache/pulsar/pull/19017#discussion_r1056093208
##########
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:
if the ledger doesn't exist in this `ManagedLedgerImpl`, the ledger into
also null, and we may be can't return the `getTotalSize()`, We should find the
closest ledger by this position
--
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]