Repository navigation
[fix][managed-ledger] Persist partial batch ACKs on flush - #26765
codelipenghui merged 3 commits into
Conversation
A cumulative ACK can insert a bitmap between the separate get() and computeIfAbsent(), causing the existingBitSet==null branch to skip the required bitmap merge. Always merge against whatever bitmap computeIfAbsent returns, and supply a fresh BitSet when creating. Signed-off-by: Asthenia0412 <[email protected]>
|
@codelipenghui Addressed your feedback — pushed 8 commit updates:
|
|
@codelipenghui Fix pushed (26db1d8): removed the racy |
|
@codelipenghui Good catch on the race condition — fixed and pushed. The original separate get()+computeIfAbsent() pattern could miss a concurrent bitmap update; now we always merge against whatever bitmap computeIfAbsent returns, creating a fresh BitSet for new entries so the stored value is independent. Please re-review when you have time. |
|
@codelipenghui Fixed the race you pointed out — removed the racy separate get() and always merge against whatever bitmap computeIfAbsent returns. See latest push. Ready for re-review. |
codelipenghui
left a comment
There was a problem hiding this comment.
Thanks @Asthenia0412—the earlier separate get()/computeIfAbsent() merge race is resolved in 26db1d8c47.
One issue remains: [P1] newly inserted batch bitmaps are not counted as changed, as explained in the latest inline review.
For a previously unseen batch, computeIfAbsent initializes the stored bitmap with the incoming value. Cloning it and ANDing with that same value changes nothing (2 & 2 == 2), leaving batchAckChanged false. When a clean cursor has no individual-delete ranges, it therefore never becomes dirty and flush() still skips the first partial ACK. The original duplicate-redelivery risk after a broker crash remains.
The added testFlushPersistsPartialBatchAckWithoutIndividualRanges fails on 26db1d8c47 with a five-second timeout waiting for a cursor-ledger write. The focused recovery/empty-ACK/inactivity-flush run completed with 11 passing tests and this one failure, with retries disabled.
Please count insertion as a state change while preserving the merge against the actual computeIfAbsent result, without reintroducing the separate lookup, and rerun the regression. This is distinct from the already-resolved merge race.
When computeIfAbsent creates a new entry for a previously unseen batch, the subsequent clone-and-AND produces no delta (newBitSet AND givenBitSet == givenBitSet), leaving batchAckChanged false. This caused the cursor dirty state to be incorrect when a partial batch ack created state from nothing. Fix: check containsKey before computeIfAbsent. If the batch didn't exist before, set batchAckChanged=true unconditionally. If it existed, fall back to the clone/AND/compare merge to detect changes. Signed-off-by: Trae Agent <[email protected]>
075fe57 to
6e43231
Compare
codelipenghui
left a comment
There was a problem hiding this comment.
Re-reviewed the complete change at 6e43231fc0. Both previous findings are resolved: newly inserted batch bitmaps now mark the cursor dirty, and ACK merging still uses the actual computeIfAbsent result.
Forced a fresh focused test run with retries disabled: all 12 tests passed, including the previously failing partial-ACK flush regression, recovery tests, empty-ACK deletion, and inactivity flushing. git diff --check also passed.
No actionable findings identified within the reviewed scope. LGTM, subject to required CI passing.
|
@dao-jun Hello I think the pr could be merged |
(cherry picked from commit fa28230)
(cherry picked from commit fa28230)
(cherry picked from commit fa28230)
(cherry picked from commit fa28230)
Fixes #26498
Motivation
asyncDeleteupdates the batch ACK bitmap for a partial acknowledgment. When this does not create an individual-delete range, the method completes without marking the cursor dirty, so the periodic flush skips the changed bitmap. A broker restart can then redeliver a message that was already acknowledged.Modifications
Track whether a batch ACK bitmap actually changes. When the no-range path completes after such a change, mark the cursor dirty and update its latest mark-delete entry so the existing flush persists the bitmap without advancing the cursor. Add a regression test that reads the persisted cursor-ledger entry after a flush and verifies the bitmap while the individual-delete range set remains empty.
Verification
./gradlew :managed-ledger:test --tests org.apache.bookkeeper.mledger.impl.ManagedCursorBatchAckRecoveryTest.testFlushPersistsPartialBatchAckWithoutIndividualRanges -PtestRetryCount=0 --no-daemon./gradlew :managed-ledger:test --tests org.apache.bookkeeper.mledger.impl.ManagedCursorBatchAckRecoveryTest --tests org.apache.bookkeeper.mledger.impl.ManagedCursorTest.testDeleteBatchedMessageWithEmptyAckSet --tests org.apache.bookkeeper.mledger.impl.ManagedCursorTest.testFlushCursorAfterIndividualDeleteInactivity -PtestRetryCount=0 --no-daemon./gradlew quickCheck --no-daemongit diff --check