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 possible mark delete NPE when batch index ack is enabled #23833

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BewareMyPower
Copy link
Contributor

Motivation

MLPendingAckStoreTest#testMainProcess will fail by NPE if batch index ACK is enabled. The NPE happens when the position argument does not has a non-null ackSet.

Modifications

  • Add an ackBatchPosition method to handle Optional objects correctly with elegant and clear code.
  • Make BitSetRecycable#recycle() call safe to be called multiple times so that it can be called in ConcurrentSkipListMap's callback, which is not guaranteed to be called only once.
  • Mark batchDeletedIndexes as @Nullable and check if it's not null instead of getConfig().isDeletionAtBatchIndexLevelEnabled() to eliminate all NPE warnings.

Verifying this change

Enable batch index ACK in MLPendingAckStoreTest and guarantee this test passes.

Documentation

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

Matching PR in forked repository

PR in forked repository:

@BewareMyPower BewareMyPower self-assigned this Jan 9, 2025
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jan 9, 2025
@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug area/broker labels Jan 9, 2025
@lhotari lhotari added this to the 4.1.0 milestone Jan 9, 2025
@@ -1211,6 +1211,9 @@ public void recycle() {
if (recyclerHandle != null) {
this.clear();
recyclerHandle.recycle(this);
// Reset with null so that recycle() can be called many times but only the 1st time takes effect.
Copy link
Member

Choose a reason for hiding this comment

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

If we set the recycleHandler = null here, looks like it will downgrade to shortlive objects

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. What's the issue here?

Copy link
Member

Choose a reason for hiding this comment

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

I am just wandering that since it can be downgrade to shortlive objects, why not just new BitSetRecyclable() here directly, so we don't need to call recycle and don't need to set recycleHandle=null

Copy link
Member

Choose a reason for hiding this comment

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

By this way, we can keep the semantic align, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I will use BitSet instead. Using a recyclable object is very error-prone in non-trivial cases. In this specific case, it's used as the value of a map and we must guarantee recycle() is called when the value is removed.

The benefit of recycler is a pre-mature optimization IMO.

Copy link
Member

Choose a reason for hiding this comment

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

+1, use bitset here directly will not lead to performance regression, and makes it more clearly. The key point is BitSet#words field, since we just wrap the given ackSet by BitSet, it is OK to use BitSet instead.

@BewareMyPower BewareMyPower marked this pull request as draft January 10, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-not-needed Your PR changes do not impact docs ready-to-test release/3.0.9 release/3.3.4 release/4.0.2 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.

3 participants