[improve][broker] Refactor bucket delayed-delivery class structure#26214
Draft
nodece wants to merge 3 commits into
Draft
[improve][broker] Refactor bucket delayed-delivery class structure#26214nodece wants to merge 3 commits into
nodece wants to merge 3 commits into
Conversation
nodece
force-pushed
the
refactor-bucket-delayed-delivery-clarity
branch
from
July 20, 2026 10:27
ddae503 to
68f3cad
Compare
nodece
marked this pull request as draft
July 21, 2026 03:35
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
The bucket delayed-delivery implementation has accumulated unnecessary complexity over time.
The current
Bucketbase class mixes mutable bucket state, immutable snapshot state, shared dependencies, and persistence helpers, making the lifecycle and ownership of these fields unclear.In addition, the mutable bucket's delayed index bitmap was serving two different purposes:
This coupling makes the state management harder to reason about and can lead to unnecessary memory growth.
The existing use of boxed
Longkeys in delayed indexes also introduces additional memory overhead, which becomes significant for large delayed message workloads.This change simplifies bucket ownership boundaries, separates mutable and immutable state, and reduces memory overhead for large delayed indexes.
Modifications
Removed the
Bucketabstract base class.MutableBucketandImmutableBucketare now independent classes with clearly separated responsibilities.Added
BucketContextrecord to hold shared dependencies:dispatcherNamecursorsequencerbucketSnapshotStorageThe tracker creates a single context instance and shares it across buckets.
Refactored
MutableBucket:Bucket.priorityQueueand mutable ledger range.delayedIndexBitMapfield.Refactored
ImmutableBucket:delayedIndexBitMapsnapshotSegmentsbucketIdsnapshotCreateFutureBucketintoImmutableBucket.startLedgerIdandendLedgerIdfinal to match their lifecycle.Added tracker-level
inflightIndexinBucketDelayedDeliveryTracker:lastMutableBucket.delayedIndexBitMap.containsMessageandremoveIndexBitnow checkinflightIndexfirst and fall back to immutable bucket indexes.afterCreateImmutableBucketremoves migrated positions frominflightIndexto avoid stale entries.Replaced boxed
Map<Long, LongBitmap>with primitive-keyed fastutil maps:Long2ObjectOpenHashMapTracker.inflightIndexImmutableBucket.delayedIndexBitMapMutableBucket.sealBucketAndAsyncPersistentTracker.asyncMergeBucketSnapshotThis avoids
Longboxing overhead and saves approximately 24 bytes per entry, which is significant for delayed indexes that can grow beyond 100K entries.