Skip to content
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

Merged
merged 2 commits into from
Jan 29, 2023

Conversation

poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Jan 29, 2023

Motivation

ML uses synchronized to guarantee the atomicity of modifications to variables ledgers, currentLedger, currentLedgerEntries and currentLedgerSize, 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:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jan 29, 2023
@mattisonchao
Copy link
Member

As #16420 cherry-picked into the previous branches, I've added labels too.

Copy link
Member

@mattisonchao mattisonchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 1557 to 1563
synchronized (ManagedLedgerImpl.this) {
ledgers.put(lh.getId(), newLedger);
currentLedger = lh;
currentLedgerEntries = 0;
currentLedgerSize = 0;
updateLedgersIdsComplete();
mbean.addLedgerSwitchLatencySample(System.currentTimeMillis()
Copy link
Contributor

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.

Copy link
Contributor Author

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-commenter
Copy link

Codecov Report

Merging #19346 (baab882) into master (fcecca4) will increase coverage by 31.56%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              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     
Flag Coverage Δ
inttests 24.92% <53.33%> (-0.05%) ⬇️
systests 25.69% <100.00%> (+0.03%) ⬆️
unittests 61.19% <100.00%> (+43.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...pache/pulsar/broker/admin/v2/PersistentTopics.java 75.37% <ø> (+65.74%) ⬆️
...in/java/org/apache/pulsar/admin/cli/CmdTopics.java 80.16% <ø> (+80.16%) ⬆️
...mon/policies/data/stats/SubscriptionStatsImpl.java 74.74% <ø> (+32.32%) ⬆️
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 78.03% <100.00%> (+37.46%) ⬆️
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 78.48% <100.00%> (+34.09%) ⬆️
...rg/apache/bookkeeper/mledger/impl/OpReadEntry.java 72.44% <100.00%> (+5.43%) ⬆️
...ker/service/persistent/PersistentSubscription.java 69.13% <100.00%> (+22.75%) ⬆️
...in/java/org/apache/pulsar/common/api/AuthData.java 71.42% <0.00%> (ø)
...ava/org/apache/pulsar/client/api/schema/Field.java 80.00% <0.00%> (ø)
.../apache/pulsar/broker/namespace/LookupOptions.java 87.50% <0.00%> (ø)
... and 1223 more

@Technoboy- Technoboy- merged commit e2851da into apache:master Jan 29, 2023
liangyepianzhou pushed a commit that referenced this pull request Feb 9, 2023
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants