Skip to content

Commit

Permalink
Prevent race condition while calculating unack-msg offset stats (apac…
Browse files Browse the repository at this point in the history
…he#3015)

* Prevent race condition while calculating unack-msg offset stats

* local var
  • Loading branch information
rdhabalia authored and merlimat committed Nov 20, 2018
1 parent 31345de commit 5fde6f3
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,13 @@ public long getNumberOfEntries() {

@Override
public long getNumberOfEntriesSinceFirstNotAckedMessage() {
return ledger.getNumberOfEntries(Range.openClosed(markDeletePosition, readPosition));
// sometimes for already caught up consumer: due to race condition markDeletePosition > readPosition. so,
// validate it before preparing range
PositionImpl markDeletePosition = this.markDeletePosition;
PositionImpl readPosition = this.readPosition;
return (markDeletePosition.compareTo(readPosition) < 0)
? ledger.getNumberOfEntries(Range.openClosed(markDeletePosition, readPosition))
: 0;
}

@Override
Expand Down

0 comments on commit 5fde6f3

Please sign in to comment.