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][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated #20984

Merged
merged 9 commits into from
Aug 16, 2023

Conversation

coderzc
Copy link
Member

@coderzc coderzc commented Aug 12, 2023

Motivation

In #20697, we remove the lock of get compactedTopicContext and asyncReadEntries, but compactionHorizon has been updated before compactedTopicContext is updated. In concurrent cases, this may lead to cursor skip messages of newly compacted or getting an NPE when reading compacted entries.

Modifications

Ensure compactionHorizon is updated after compactedTopicContext.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

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 Aug 12, 2023
@coderzc coderzc added this to the 3.1.0 milestone Aug 12, 2023
@coderzc coderzc added type/bug The PR fixed a bug or issue reported a bug area/broker and removed doc-not-needed Your PR changes do not impact docs labels Aug 12, 2023
@coderzc coderzc self-assigned this Aug 12, 2023
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Aug 12, 2023
@coderzc coderzc changed the title [fix][broker] Fix get old compactedTopicContext after compactionHorizon been updated [fix][broker] Fix get compactedTopicContext older than last compaction position Aug 12, 2023
@coderzc coderzc changed the title [fix][broker] Fix get compactedTopicContext older than last compaction position [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated Aug 12, 2023
@coderzc coderzc closed this Aug 12, 2023
@coderzc coderzc reopened this Aug 12, 2023
@coderzc coderzc force-pushed the fix_compacted_topic branch from df7ddae to 89445e9 Compare August 12, 2023 10:59
@coderzc coderzc added the release/blocker Indicate the PR or issue that should block the release until it gets resolved label Aug 12, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 12, 2023

Codecov Report

Merging #20984 (0995f30) into master (d6734b7) will increase coverage by 36.29%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #20984       +/-   ##
=============================================
+ Coverage     36.84%   73.13%   +36.29%     
- Complexity    12195    32257    +20062     
=============================================
  Files          1698     1875      +177     
  Lines        129852   139443     +9591     
  Branches      14161    15333     +1172     
=============================================
+ Hits          47843   101983    +54140     
+ Misses        75680    29398    -46282     
- Partials       6329     8062     +1733     
Flag Coverage Δ
inttests 24.13% <100.00%> (+0.01%) ⬆️
systests 25.12% <100.00%> (+0.02%) ⬆️
unittests 72.42% <100.00%> (+40.36%) ⬆️

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

Files Changed Coverage Δ
...g/apache/pulsar/compaction/CompactedTopicImpl.java 63.90% <100.00%> (+1.50%) ⬆️

... and 1437 files with indirect coverage changes

@coderzc coderzc removed the release/blocker Indicate the PR or issue that should block the release until it gets resolved label Aug 12, 2023
@coderzc coderzc modified the milestones: 3.1.0, 3.2.0 Aug 12, 2023
@coderzc coderzc force-pushed the fix_compacted_topic branch from f11ba81 to 5245fa7 Compare August 14, 2023 03:26
CompletableFuture<CompactedTopicContext> previousContext = compactedTopicContext;
compactedTopicContext = openCompactedLedger(bk, compactedLedgerId);

compactionHorizon = (PositionImpl) p;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can not guarantee that the reading of compactionHorizon and compactedTopicContext safety even if this patch is merged. We should add some code-comment on the method getCompactedTopicContextFuture and getCompactedTopicContext like this:

/**
 * If you want to guarantee that `compactionHorizon` and `compactedTopicContext` match, you need to call this method in "synchronized(compartor){ ... }" lock block
 */

Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to give it a strong guarantee. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to give it a strong guarantee. :)

Yes, I agree. But a description is needed

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added some comments to explain this.

@coderzc coderzc force-pushed the fix_compacted_topic branch 3 times, most recently from 47ced32 to 633c1a9 Compare August 15, 2023 03:58
@coderzc coderzc force-pushed the fix_compacted_topic branch from 633c1a9 to 8dee1bb Compare August 16, 2023 05:57
@coderzc coderzc merged commit 0cb1c78 into apache:master Aug 16, 2023
coderzc added a commit that referenced this pull request Aug 16, 2023
…Horizon has been updated (#20984)

(cherry picked from commit 0cb1c78)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants