[fix][broker] Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException#26184
[fix][broker] Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException#26184Technoboy- wants to merge 5 commits into
getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException#26184Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a production warning where ManagedCursorImpl#getEstimatedSizeSinceMarkDeletePosition() could throw IllegalArgumentException when the cursor’s markDeletePosition is ahead of the ledger’s lastPosition (creating an invalid Guava Range), which caused compaction checks to be skipped.
Changes:
- Add an early-return guard in
getEstimatedSizeSinceMarkDeletePosition()whenmarkDeletePositionisnullor>= lastPosition, preventing invalidRangeconstruction. - Reuse a single
lastPositionsnapshot when computing the backlog range for both deleted-message counting and entry counting. - Add a unit test covering the “cursor markDeletePosition ahead of lastPosition” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java | Prevent invalid (markDelete..last] ranges by returning 0 when mark-delete is at/after last position; use a consistent lastPosition snapshot for range calculations. |
| managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java | Adds regression test ensuring estimated unacked size returns 0 (and doesn’t throw) when the cursor is ahead of the ledger last position. |
getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentExceptiongetEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException
|
I think we should distinguish The problematic case is when the cursor is ahead of the ledger last position, for example:
This can happen when the cursor has consumed the previous ledger and has been advanced to the beginning of a new empty ledger. In that case, constructing But
There is no backlog, so Could we handle equality as |
Thanks for reviewing. addressed |
|
It looks like we currently only cover the |
Motivation
Modifications
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes