Skip to content

Commit

Permalink
[fix][broker] Check the markDeletePosition and calculate the backlog (a…
Browse files Browse the repository at this point in the history
…pache#22947)

Signed-off-by: Zixuan Liu <nodeces@gmail.com>
(cherry picked from commit 82b8d98)
  • Loading branch information
nodece committed Jun 21, 2024
1 parent 73cf1d9 commit 6b6cfac
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,13 @@ public long getEstimatedSizeSinceMarkDeletePosition() {
return ledger.estimateBacklogFromPosition(markDeletePosition);
}

private long getNumberOfEntriesInBacklog() {
if (markDeletePosition.compareTo(ledger.getLastPosition()) >= 0) {
return 0;
}
return getNumberOfEntries(Range.openClosed(markDeletePosition, ledger.getLastPosition()));
}

@Override
public long getNumberOfEntriesInBacklog(boolean isPrecise) {
if (log.isDebugEnabled()) {
Expand All @@ -1025,16 +1032,13 @@ public long getNumberOfEntriesInBacklog(boolean isPrecise) {
messagesConsumedCounter, markDeletePosition, readPosition);
}
if (isPrecise) {
if (markDeletePosition.compareTo(ledger.getLastPosition()) >= 0) {
return 0;
}
return getNumberOfEntries(Range.openClosed(markDeletePosition, ledger.getLastPosition()));
return getNumberOfEntriesInBacklog();
}

long backlog = ManagedLedgerImpl.ENTRIES_ADDED_COUNTER_UPDATER.get(ledger) - messagesConsumedCounter;
if (backlog < 0) {
// In some case the counters get incorrect values, fall back to the precise backlog count
backlog = getNumberOfEntries(Range.openClosed(markDeletePosition, ledger.getLastPosition()));
backlog = getNumberOfEntriesInBacklog();
}

return backlog;
Expand Down

0 comments on commit 6b6cfac

Please sign in to comment.