[fix][broker] Fix snapshot creation race causing delayed delivery bucket trim failures - #26260
Open
void-ptr974 wants to merge 1 commit into
Open
[fix][broker] Fix snapshot creation race causing delayed delivery bucket trim failures#26260void-ptr974 wants to merge 1 commit into
void-ptr974 wants to merge 1 commit into
Conversation
void-ptr974
marked this pull request as ready for review
August 1, 2026 14:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
BucketDelayedDeliveryTrackerpublishes a newly sealed immutable bucket before its asynchronous snapshot creation completes. If the sameaddMessagecall causes the bucket count to exceeddelayedDeliveryMaxNumBuckets, trim can immediately select a bucket whose snapshot ID is not available yet. This makes the current trim pass fail and delays cleanup until a later trim is triggered.Modifications
Consider a tracker with a maximum of 5 buckets and a first active ledger ID of 50:
addMessagecall that creates the sixth bucket starts trim because the limit has been exceeded.getAndUpdateBucketId()callsLong.parseLong(null)and throwsNumberFormatException. The trim chain stops at that failure andtrimFuturecompletes exceptionally. It is not permanently pending, but the failed deletion is left for a later trim attempt.The wait is asynchronous and does not block the dispatcher thread.
Verifying this change
Added deterministic tests that hold snapshot creation in flight and verify that:
Verified with:
./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.delayed.bucket.BucketDelayedDeliveryTrackerTest./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.delayed.bucket.BucketDelayedDeliveryTrackerThreadSafetyTest./gradlew quickCheckDoes this pull request potentially affect one of the following parts: