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] Compare batch index when accumulating acks and updating batchDeletedIndexes #18042

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

lordcheng10
Copy link
Contributor

@lordcheng10 lordcheng10 commented Oct 13, 2022

Motivation

When accumulating acks, update the batch index in batchDeletedIndexes without checking whether it is greater than the batch index of the previous ack:

if (config.isDeletionAtBatchIndexLevelEnabled() && batchDeletedIndexes != null) {
if (newPosition.ackSet != null) {
batchDeletedIndexes.put(newPosition, BitSetRecyclable.create().resetWords(newPosition.ackSet));
newPosition = ledger.getPreviousPosition(newPosition);

This may cause the index of ack in the batch to fall back.

Should be modified to:

                lock.writeLock().lock();
                try {
                    BitSetRecyclable givenBitSet = BitSetRecyclable.create().resetWords(newPosition.ackSet);
                    batchDeletedIndexes.compute(newPosition,
                            (k, v) -> v == null || givenBitSet.nextSetBit(0) > v.nextSetBit(0)
                                    ? givenBitSet : v);
               } finally {
                    lock.writeLock().unlock();
                }

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: lordcheng10#28

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 13, 2022
@lordcheng10 lordcheng10 changed the title [fix][broker] When accumulating acks, update the batch index in batchDeletedIndexes and check whether it is greater than the batch index of the previous ack [fix][broker] Check the index size when accumulating acks and updating batchDeletedIndexes Oct 13, 2022
@lordcheng10 lordcheng10 changed the title [fix][broker] Check the index size when accumulating acks and updating batchDeletedIndexes [fix][broker] Compare batch index when accumulating acks and updating batchDeletedIndexes Oct 13, 2022
@lordcheng10 lordcheng10 changed the title [fix][broker] Compare batch index when accumulating acks and updating batchDeletedIndexes [improve][broker] Reduce unnecessary persistence of markdelete Oct 14, 2022
@lordcheng10 lordcheng10 changed the title [improve][broker] Reduce unnecessary persistence of markdelete [fix][broker] Compare batch index when accumulating acks and updating batchDeletedIndexes Oct 14, 2022
@lordcheng10
Copy link
Contributor Author

@lordcheng10 lordcheng10 force-pushed the batch_index_update_check branch from 99e38d8 to 3567d01 Compare October 16, 2022 04:04
@@ -105,6 +105,35 @@ private void recalculateWordsInUse() {
wordsInUse = i+1; // The new logical size
}

public int compareTo(BitSetRecyclable bitSetRecyclable) {
long[] words1 = toLongArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we avoid this memory copy in toLongArray, just use words and wordsInUse instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. @Jason918
PTAL,thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove compareTo method,use nextSetBit instead of compareTo! @Jason918 PTAL,thanks!

@lordcheng10 lordcheng10 requested a review from Jason918 October 16, 2022 08:38
@codelipenghui codelipenghui added this to the 2.12.0 milestone Oct 17, 2022
@codelipenghui codelipenghui added type/bug The PR fixed a bug or issue reported a bug area/broker labels Oct 17, 2022
batchDeletedIndexes.put(newPosition, BitSetRecyclable.create().resetWords(newPosition.ackSet));
lock.writeLock().lock();
try {
setBatchDeletedIndexes(newPosition);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we just change to

BitSetRecyclable givenBitSet = BitSetRecyclable.create().resetWords(newPosition.ackSet);
batchDeletedIndexes.compute(newPosition,
        (k, v) -> v == null || givenBitSet.nextClearBit(0) > v.nextClearBit(0) ?
                givenBitSet : v);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK ,I will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, PTAL,thanks! @codelipenghui

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nextClearBit is not suitable, because 0 means acked.
So use nextSetBit instead.

@lordcheng10 lordcheng10 force-pushed the batch_index_update_check branch from ff72a2c to 6f89d69 Compare October 17, 2022 05:45
@lordcheng10 lordcheng10 requested review from codelipenghui and removed request for Jason918 October 17, 2022 05:46
@lordcheng10
Copy link
Contributor Author

@Jason918 @codelipenghui PTAL,thanks!

Copy link
Contributor

@aloyszhang aloyszhang left a comment

Choose a reason for hiding this comment

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

LGTM

@lordcheng10 lordcheng10 force-pushed the batch_index_update_check branch from 227941e to 7d6a3fd Compare October 18, 2022 07:55
@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2022

Codecov Report

Merging #18042 (3393572) into master (6c65ca0) will increase coverage by 11.94%.
The diff coverage is 59.90%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #18042       +/-   ##
=============================================
+ Coverage     34.91%   46.85%   +11.94%     
- Complexity     5707    17892    +12185     
=============================================
  Files           607     1574      +967     
  Lines         53396   128353    +74957     
  Branches       5712    14123     +8411     
=============================================
+ Hits          18644    60144    +41500     
- Misses        32119    62010    +29891     
- Partials       2633     6199     +3566     
Flag Coverage Δ
unittests 46.85% <59.90%> (+11.94%) ⬆️

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

Impacted Files Coverage Δ
...org/apache/pulsar/broker/ServiceConfiguration.java 52.07% <ø> (ø)
.../service/SystemTopicBasedTopicPoliciesService.java 62.97% <0.00%> (+11.38%) ⬆️
.../pulsar/broker/stats/BrokerOperabilityMetrics.java 100.00% <ø> (+7.35%) ⬆️
...va/org/apache/pulsar/client/impl/ConsumerBase.java 21.95% <0.00%> (ø)
...ache/pulsar/functions/utils/io/ConnectorUtils.java 0.00% <0.00%> (ø)
...nator/impl/MLTransactionMetadataStoreProvider.java 0.00% <0.00%> (ø)
.../org/apache/pulsar/broker/admin/v2/Namespaces.java 55.32% <50.00%> (+47.30%) ⬆️
...he/pulsar/functions/worker/rest/api/SinksImpl.java 36.82% <50.00%> (ø)
...apache/pulsar/proxy/server/DirectProxyHandler.java 63.63% <50.00%> (ø)
...ulsar/functions/worker/rest/api/ComponentImpl.java 25.26% <57.14%> (ø)
... and 1163 more

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

Copy link
Contributor

@Jason918 Jason918 left a comment

Choose a reason for hiding this comment

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

LGTM

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

@Technoboy- PTAL,thanks!

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

lordcheng10 commented Oct 20, 2022

@AnonHxy @Technoboy- PTAL,thanks!

… and check whether it is greater than the batch index of the previous ack
@lordcheng10 lordcheng10 force-pushed the batch_index_update_check branch from 3393572 to 6ad5478 Compare October 20, 2022 11:39
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

CI all passed: lordcheng10#28

@lordcheng10
Copy link
Contributor Author

@AnonHxy PTAL,thanks!

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

7 similar comments
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@aloyszhang aloyszhang merged commit fa328a4 into apache:master Oct 21, 2022
@Technoboy- Technoboy- modified the milestones: 2.12.0, 2.11.0 Oct 31, 2022
Technoboy- pushed a commit that referenced this pull request Oct 31, 2022
… and check whether it is greater than the batch index of the previous ack (#18042)

Co-authored-by: leolinchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants