You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "coderzc (via GitHub)" <gi...@apache.org> on 2023/08/12 10:56:51 UTC

[GitHub] [pulsar] coderzc opened a new pull request, #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

coderzc opened a new pull request, #20984:
URL: https://github.com/apache/pulsar/pull/20984

   ### Motivation
   
   In #20697, we remove the lock of get compactedTopicContext, 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
   
   - [x] 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:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *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
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: <!-- ENTER URL HERE -->
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc merged pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc merged PR #20984:
URL: https://github.com/apache/pulsar/pull/20984


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1292935241


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -69,16 +69,14 @@ public CompactedTopicImpl(BookKeeper bk) {
 
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
-        synchronized (this) {

Review Comment:
   Ok.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1293099208


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -70,14 +70,14 @@ public CompactedTopicImpl(BookKeeper bk) {
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
         synchronized (this) {
-            compactionHorizon = (PositionImpl) p;
-
             CompletableFuture<CompactedTopicContext> previousContext = compactedTopicContext;
             compactedTopicContext = openCompactedLedger(bk, compactedLedgerId);
 
+            compactionHorizon = (PositionImpl) p;

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc closed pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc closed pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated
URL: https://github.com/apache/pulsar/pull/20984


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codecov-commenter commented on pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#issuecomment-1675960469

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/20984?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#20984](https://app.codecov.io/gh/apache/pulsar/pull/20984?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (f42520b) into [master](https://app.codecov.io/gh/apache/pulsar/commit/98628845aa94b416b0c3711b5a15819ade549c57?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (9862884) will **increase** coverage by `39.60%`.
   > Report is 3 commits behind head on master.
   > The diff coverage is `100.00%`.
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/20984/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/pulsar/pull/20984?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@              Coverage Diff              @@
   ##             master   #20984       +/-   ##
   =============================================
   + Coverage     33.53%   73.13%   +39.60%     
   - Complexity    12174    32249    +20075     
   =============================================
     Files          1621     1875      +254     
     Lines        126919   139406    +12487     
     Branches      13851    15329     +1478     
   =============================================
   + Hits          42561   101960    +59399     
   + Misses        78745    29383    -49362     
   - Partials       5613     8063     +2450     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | inttests | `24.13% <100.00%> (-0.14%)` | :arrow_down: |
   | systests | `25.11% <100.00%> (?)` | |
   | unittests | `72.44% <100.00%> (+40.39%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Files Changed](https://app.codecov.io/gh/apache/pulsar/pull/20984?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...g/apache/pulsar/compaction/CompactedTopicImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/20984?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vQ29tcGFjdGVkVG9waWNJbXBsLmphdmE=) | `63.63% <100.00%> (+4.23%)` | :arrow_up: |
   
   ... and [1523 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/20984/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1292934520


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -69,16 +69,14 @@ public CompactedTopicImpl(BookKeeper bk) {
 
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
-        synchronized (this) {

Review Comment:
   We can leave this lock here because JVM is smart enough to distinguish if we need it. or we can issue another PR to remove this lock to get a clear context. :) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1293085970


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -70,14 +70,14 @@ public CompactedTopicImpl(BookKeeper bk) {
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
         synchronized (this) {
-            compactionHorizon = (PositionImpl) p;
-
             CompletableFuture<CompactedTopicContext> previousContext = compactedTopicContext;
             compactedTopicContext = openCompactedLedger(bk, compactedLedgerId);
 
+            compactionHorizon = (PositionImpl) p;

Review Comment:
   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
    */
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1293295877


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -70,14 +70,14 @@ public CompactedTopicImpl(BookKeeper bk) {
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
         synchronized (this) {
-            compactionHorizon = (PositionImpl) p;
-
             CompletableFuture<CompactedTopicContext> previousContext = compactedTopicContext;
             compactedTopicContext = openCompactedLedger(bk, compactedLedgerId);
 
+            compactionHorizon = (PositionImpl) p;

Review Comment:
   I have added some comments to explain this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on a diff in pull request #20984: [fix][broker] Fix get outdated compactedTopicContext after compactionHorizon has been updated

Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #20984:
URL: https://github.com/apache/pulsar/pull/20984#discussion_r1293104588


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java:
##########
@@ -70,14 +70,14 @@ public CompactedTopicImpl(BookKeeper bk) {
     @Override
     public CompletableFuture<CompactedTopicContext> newCompactedLedger(Position p, long compactedLedgerId) {
         synchronized (this) {
-            compactionHorizon = (PositionImpl) p;
-
             CompletableFuture<CompactedTopicContext> previousContext = compactedTopicContext;
             compactedTopicContext = openCompactedLedger(bk, compactedLedgerId);
 
+            compactionHorizon = (PositionImpl) p;

Review Comment:
   > I think we don't need to give it a strong guarantee. :)
   
   Yes, I agree. But a description is needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org