Skip to content

[refactor][broker] Name the segment state and consolidate in-flight bucket bookkeeping - #43

Open
nodece wants to merge 1 commit into
lazy-load-first-bucket-segmentfrom
refactor-bucket-tracker-structure
Open

nodece wants to merge 1 commit into
lazy-load-first-bucket-segmentfrom
refactor-bucket-tracker-structure

Conversation

@nodece

@nodece nodece commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Stacked on #42 (lazy segment loading). Pure structure, no behavior change: the delayed delivery suites (incl. the e2e BucketDelayedDeliveryTest) pass without a single test modification, and the JMH sanity numbers are unchanged.

What it does

The lazy-loading change left the tracker with five ad-hoc fields for asynchronous work (pendingLoads, pendingDrainedDeletes, pendingDeletes, uncleanedBuckets, trimFuture) and segment progress encoded as bare currentSegmentEntryId conventions. This PR extracts two cohesive, named collaborators and names the state:

  • SegmentLoadGate — the delivery gate for armed segment loads: arm / allSettled / awaitAllSettled. A dispatch round arms the loads of every due segment and delivers nothing until the batch settles, keeping a round's positions ordered.
  • SnapshotDeletionTracker — bookkeeping of asynchronous snapshot deletions: in-flight guard per bucket (no stacked deletes), failure retry set (a snapshot is never abandoned silently), and awaitAllSettled for clear().
  • ImmutableBucket.hasUnloadedSegments() / allSegmentsLoaded() — the segment-load state reads by intent instead of raw id comparisons.
  • recoverBucketSnapshot0 decomposed into registerRecoveredBuckets / collectObsoleteRecoveredBuckets / restoreRecoveredBuckets; recovery is not extracted into a class because it shares too much tracker state — a class split would just trade nesting for callbacks.

clear() now reads as "wait for trim/merge → wait for loads and deletes → reset" instead of assembling pending collections inline.

Testing

  • ./gradlew :pulsar-broker:test --tests "org.apache.pulsar.broker.delayed.*" --tests "org.apache.pulsar.broker.service.persistent.BucketDelayedDeliveryTest" — green, zero test modifications
  • checkstyle / spotless clean

Assisted-by: Claude Code

@nodece
nodece force-pushed the refactor-bucket-tracker-structure branch 2 times, most recently from d9da9f3 to 3989a9a Compare November 25, 2026 07:42
…ucket bookkeeping

Rebased onto the progressive-delivery base. The tracker carried five
ad-hoc fields for asynchronous work and segment progress encoded as
bare currentSegmentEntryId conventions; consolidate the state and name
it:

- PendingSnapshotDeletes: the snapshot deletions not done yet — in
  flight (guarded per bucket, so deletes never stack) or failed and
  waiting for a retry, so a snapshot is never abandoned silently.
  Replaces pendingDrainedDeletes, pendingDeletes and uncleanedBuckets.
- segmentLoadsSettled() / awaitSegmentLoadsSettled(): the armed segment
  loads read by intent instead of a raw future set with pruning at the
  call sites.
- ImmutableBucket.hasUnloadedSegments() / allSegmentsLoaded(): the
  segment-load state reads by intent instead of raw id comparisons.
- recoverBucketSnapshot0 decomposed into registerRecoveredBuckets,
  collectObsoleteRecoveredBuckets and restoreRecoveredBuckets.

clear() now reads as "wait for trim/merge → wait for loads and deletes
→ reset". No behavior change: the delayed delivery suites (incl. the
e2e bucket test) pass without a single test modification.

Assisted-by: Claude Code
@nodece
nodece force-pushed the refactor-bucket-tracker-structure branch from 3989a9a to d1a93bd Compare November 25, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant