Skip to content

[fix] [ml] The atomicity of multiple fields of ml is broken - #19346

Merged
Technoboy- merged 2 commits into
apache:masterfrom
poorbarcode:fix/atomic_for_ml_fields
Jan 29, 2023
Merged

[fix] [ml] The atomicity of multiple fields of ml is broken#19346
Technoboy- merged 2 commits into
apache:masterfrom
poorbarcode:fix/atomic_for_ml_fields

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Jan 29, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@mattisonchao mattisonchao left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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