-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix] [ml] The atomicity of multiple fields of ml is broken #19346
[fix] [ml] The atomicity of multiple fields of ml is broken #19346
Conversation
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
Outdated
Show resolved
Hide resolved
As #16420 cherry-picked into the previous branches, I've added labels too. |
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.
LGTM
synchronized (ManagedLedgerImpl.this) { | ||
ledgers.put(lh.getId(), newLedger); | ||
currentLedger = lh; | ||
currentLedgerEntries = 0; | ||
currentLedgerSize = 0; | ||
updateLedgersIdsComplete(); | ||
mbean.addLedgerSwitchLatencySample(System.currentTimeMillis() |
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.
Is it necessary to move updateLedgersIdsComplete()
into the synchronized block? I see before #16420 this method is out of synchronized too.
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.
Yes, it is not necessary. But it should be executed after these fields changes.
Codecov Report
@@ Coverage Diff @@
## master #19346 +/- ##
=============================================
+ Coverage 32.45% 64.01% +31.56%
- Complexity 6348 25871 +19523
=============================================
Files 1644 1818 +174
Lines 123737 133112 +9375
Branches 13494 14644 +1150
=============================================
+ Hits 40162 85218 +45056
+ Misses 77654 40085 -37569
- Partials 5921 7809 +1888
Flags with carried forward coverage won't be shown. Click here to find out more.
|
(cherry picked from commit e2851da)
Motivation
ML uses synchronized to guarantee the atomicity of modifications to variables
ledgers,
currentLedger
,currentLedgerEntries
andcurrentLedgerSize
, but PR #16420 breaks atomicity, resulting in incorrect results when using those variables(E.g calculate backlog size by special position)https://github.com/apache/pulsar/pull/16420/files#diff-f6a849bd8fdb782ef6c17a2e07a2c54c3dc7d1655c00ec3546d5f3b3fc61e970L1485-R1499
Modifications
Make changes to these variables within the synchronized block.
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: