-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Move newPosition to nextValidLedger:-1 to avoid cursor position and ledger inconsistency in ManagedCursorImpl #25117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…position and ledger inconsistency in ManagedCursorImpl
…ce condition, add comments
…hTimestampNonRecoverableException() test
…mestampNonRecoverableException test
…TopicUnloading test
…ursorLedgerFailed test
…ursorLedgerFailed test
…TimeQuotaWithEmptyLedger test
…meBasedBacklogQuotaCheckWhenNoBacklog test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes cursor position and ledger inconsistency in ManagedCursorImpl by moving the mark delete position to nextValidLedger:-1 when all entries in the current ledger are consumed. This addresses potential inconsistencies where the cursor position and ledger state could become misaligned.
Key Changes
- Modified
ManagedCursorImpl.asyncMarkDelete()to intelligently move cursor position tonextValidLedger:-1when appropriate - Added snapshot positions to local variables to prevent race conditions
- Added four comprehensive test cases to verify the new mark delete behavior
- Updated existing tests to reflect the new cursor positioning behavior
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java |
Core logic change to move cursor position to nextValidLedger:-1 when ledger entries are fully consumed; snapshots positions to avoid race conditions |
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java |
Added four new test cases (testAsyncMarkDeleteMoveToNextLedgerInNonRolloverScenario, testAsyncMarkDeleteMayMoveToNextLedgerInRolloverScenario, testAsyncMarkDeleteMoveToNextLedgerOneByOne, testAsyncMarkDeleteNextLedgerMinusOneEntryIdPosition) and updated existing tests to use relaxed assertions |
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java |
Updated testNoRetention test to use Awaitility for proper async handling and updated assertions for cursor position validation; fixed flaky tests |
pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactedTopicTest.java |
Updated test assertions to expect cursor position at currentLedgerId:-1 after compaction |
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicProtectedMethodsTest.java |
Changed exact equality assertions to greater-than-or-equal assertions for mark delete position |
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentMessageFinderTest.java |
Updated message expiry tests to expect mark delete position at nextLedgerId:-1 |
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessageTTLTest.java |
Fixed spelling from "exacly" to "exactly" and updated test to expect cursor at currentLedgerId:-1 |
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BacklogQuotaManagerTest.java |
Updated assertions to reflect that mark deleting moves cursor to nextLedgerId:-1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactedTopicTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/MessageTTLTest.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25117 +/- ##
============================================
+ Coverage 74.44% 74.48% +0.03%
- Complexity 34046 34050 +4
============================================
Files 1899 1899
Lines 149655 149666 +11
Branches 17393 17397 +4
============================================
+ Hits 111412 111477 +65
+ Misses 29368 29313 -55
- Partials 8875 8876 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Motivation
Since
nextValidLedger:-1is a validmarkDeletePosition, we should movenewPositiontonextValidLedger:-1to avoid cursor position and ledger inconsistency inManagedCursorImplwhenever possible.PR #25087 also made this change.
Modifications
ManagedCursorImpl.asyncMarkDelete()method, movenewPositiontonextValidLedger:-1if we reach the following conditions:a. if
lastConfirmedEntry >= newPosition, and next ledger exists, and current ledger entries are all consumed.b. if
lastConfirmedEntry < newPosition, next ledger exists, andnewPosition == nextValidLedger:-1.I think the previous code might have a little problem. If
newPosition == nextValidLedger:n, n is an non-negative number, we might set newnewPositiontonextValidLedger:nwhich is greater thanlastConfirmedEntry.pulsar/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Lines 2184 to 2195 in ab65faa
And snapshot positions into a local variable to avoid race condition.
Add
testAsyncMarkDeleteMoveToNextLedgerInNonRolloverScenario,testAsyncMarkDeleteMayMoveToNextLedgerInRolloverScenario,testAsyncMarkDeleteMoveToNextLedgerOneByOne,testAsyncMarkDeleteNextLedgerMinusOneEntryIdPositiontests inManagedCursorImplto verify the code change.Fix tests due to this PR's code change.
Fix some flaky tests introduced by PR [fix][broker] Fix cursor position persistence in ledger trimming #25087.
Verifying this change
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: oneby-wang#19