Repository navigation
Conversation
…riment scaffold Delayed messages stay in the data ledgers, and due delivery replays them by position, which is a random read per message once the backlog exceeds the caches. The body-copy design answers that with a copy of every delayed entry in a deliverAt-ordered store, so the due reads become sequential — at the price of writing every delayed entry twice. This is the write-side scaffold of that design, selectable per topic so both variants can be measured on one broker: - DelayedDeliveryTracker.addEntry(ledgerId, entryId, deliverAt, entryData): a default no-op that receives the serialized entry at the only point where the broker holds the buffer (the dispatcher's delayed-entry filter). Trackers that don't store copies pay nothing. - JournalingBucketTrackerFactory extends the bucket factory and routes by topic name: topics ending in -dj get a JournalingBucketDelayedDeliveryTracker, everything else keeps the regular bucket tracker untouched. - JournalingBucketDelayedDeliveryTracker extends the bucket tracker unchanged on the delivery side and additionally frames and appends every delayed entry into a BookKeeper journal ledger (arrival order, 50k entries per ledger, own client). Journal failures are counted and never affect delivery. - The bucket factory's fields and newTracker0 become protected so custom factories in subpackages can build their own trackers. Deliberate limitations of the scaffold: the journal is write-only (due delivery still replays from the data ledgers), and it is not durable across restarts (the ledgers are not recorded in cursor properties). Switching the delivery read to the journal and journal lifecycle management are the follow-ups, gated on the write-side measurements. Assisted-by: Claude Code
1638c77 to
662bd21
Compare
…ially The journaling tracker's due path now reads from the time-window journals instead of replaying positions from the data ledgers, so the dispatch round performs no random read for journaled entries: - JournalStorage routes copies by delivery time window (60s), one ledger per window, arrival order within it. The drain reads each window's ledger sequentially from a saved offset and holds at the first record that is not due yet, so the reads are always sequential and the disorder a consumer observes is bounded by the window width. - JournalingBucketDelayedDeliveryTracker.readDueAndReplay drives the dispatch round: the drain's records are served when the inherited index still tracks their position (removeIndexBit is the single pending-truth gate, so neither path can double-deliver) and the cursor has not acknowledged them, wrapped with their original positions. What the index still reports as due after the drain — failed or still-in-flight journal copies — is replayed from the data ledgers through the regular cursor path and merged into the same completion. A journal read failure falls the whole round back to the regular replay. - PersistentDispatcherMultipleConsumers dispatches journaling trackers through readDueAndReplay instead of getScheduledMessages plus asyncReplayEntries, keeping the round's scheduling and error recovery identical to the regular path. - removeIndexBit becomes protected so the journaling tracker can gate on the inherited index. Not durable across restarts: the journal ledgers and drain offsets are not recorded, so a restart falls back to the inherited delivery entirely. Assisted-by: Claude Code
Read side is in: due delivery now reads from the journals sequentiallyThe second commit (
Known limitation: not durable across restarts (drain offsets and journal ledgers are not recorded). A restart falls back entirely to the inherited delivery. Verification: 3 consecutive rounds of |
The dispatcher dispatched journaling trackers through an instanceof check on the concrete class. Extract the capability into a dedicated interface: - DueEntryReader: a delayed delivery tracker that reads the due entries — the serialized message bodies — itself, instead of reporting positions for the dispatcher to replay from the data ledgers. Named after what the callback receives (ManagedLedger Entry, not a decoded Message) and what the operation is (a sequential read). - readDueEntries(callback, ctx, maxMessages): the tracker captures its own cursor at construction from the public DelayedDeliveryContext, so the interface carries no dispatcher-owned dependencies. - The dispatcher checks instanceof DueEntryReader and no longer imports the journal package; the journaling tracker implements the interface with the method previously named readDueAndReplay. No behavior change: 3 rounds of the delayed delivery and dispatcher suites green. Assisted-by: Claude Code
… on clear/close The journal ledgers were never deleted — a disk leak at 4.3GB per 60s window per subscription. Three lifecycle fixes: - readDue deletes a window ledger when the window has expired (its end time is past the cutoff) and the drain is past its last entry: no future read can come from that ledger, regardless of ack state. The deletion is asynchronous and failure-tolerant (a retry happens after the next restart, which starts from offset 0 and re-drains everything anyway). - clear() overrides the inherited reset to also delete every journal ledger and reset the drain state, so a subscription reset does not leave stale copies behind. - close() deletes all journal ledgers before closing the BookKeeper client, so a broker shutdown does not leave orphans (the journal is not durable across restarts by design). Assisted-by: Claude Code
Assisted-by: Claude Code
Motivation
Delayed messages stay in the data ledgers and due delivery replays them by position — a random read per message once the backlog outgrows the caches (load test: read:consume = 1, ~14k random IOPS per bookie, consumption capped by the disk). The body-copy design fixes that with a copy of every delayed entry in a deliverAt-ordered store, so due reads become sequential, at the price of writing each delayed entry twice. Before building the whole thing, this PR delivers the write side of that trade as a per-topic selectable experiment, so both variants can run and be measured on one broker.
Modifications
DelayedDeliveryTracker.addEntry(ledgerId, entryId, deliverAt, entryData)— a default no-op that receives the serialized entry at the only point where the broker still holds the buffer (the dispatcher's delayed-entry filter,AbstractBaseDispatcher). Trackers that don't store copies pay nothing; the dispatcher forwards via a newtrackDelayedDeliveryoverload whose default delegates to the existing three-argument variant.JournalingBucketTrackerFactoryextends the bucket factory and routes by topic name: topics ending in-djget the journaling tracker, everything else keeps the regular bucket tracker untouched. One broker, both implementations, same traffic: produce tomytopicandmytopic-djand compare.JournalingBucketDelayedDeliveryTrackerextends the bucket tracker with the delivery side unchanged, and additionally frames and appends every delayed entry into a BookKeeper journal ledger (arrival order, 24-byte header: deliverAt | dataLedgerId | dataEntryId, 50k entries per ledger, rollover by count). Journal failures are counted and never affect delivery.newTracker0becomeprotectedso custom factories in subpackages can build their own trackers.Deliberate limitations (scaffold scope)
Testing
JournalingBucketTrackerTest: journal failure path is counted and delivery tracking is unaffected; framed header size contract.org.apache.pulsar.broker.delayed.*+ all*DispatcherMultipleConsumers*suites green (routing, dispatcher overload and the existing trackers are regression-covered).Select with:
Assisted-by: Claude Code