GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [improve][pip] PIP-491: Prevent Delivery Stalls by Making the Client Return Exactly the Permits Used by the Broker by void-ptr974 · Pull Request #26336 · apache/pulsar Conversation
|
| unit, so its unit remains in the command budget. Any message object already created for that skipped index is | ||
| released. | ||
|
|
||
| At normal completion or failure, the command path immediately returns all remaining units. If deserialization fails |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The budget rule double-returns on four paths that already return permits themselves.
remaining = P plus "the command path immediately returns all remaining units" is stated unconditionally over native command processing. But four sites inside ConsumerImpl.messageReceived already call increaseAvailablePermits and then return early — all of them before the batch branch (:1566) and before the MessagePayloadProcessor branch (:1499), so they are squarely on the native path this section governs:
| Site | Today | Under the budget rule as written |
|---|---|---|
ConsumerImpl.java:1474 |
duplicate non-batched → increaseAvailablePermits(cnx, numMessages); return; |
nothing transferred, so the command path also returns P=1 → 2 returned for P=1 |
ConsumerImpl.java:1558 |
non-batched past maxRedeliverCount → increaseAvailablePermits(cnx); return; |
same double return |
ConsumerImpl.java:1578 |
non-final chunk → increaseAvailablePermits(cnx), then processMessageChunk returns null → :1512-1513 return; |
double return per chunk |
ConsumerImpl.java:2090 |
crypto DISCARD → discardMessage(..., batchSize), then :1481-1483 return; |
returns B, then the command path returns P; for a complete batch P == B, so the whole batch is returned twice |
That is the over-grant the PIP names as a harm at :80. Chunk assembly and encrypted payloads are deferred at :182, but they are native non-batch messages that flow through this exact path, so the deferral does not cover them.
Could this section state explicitly whether those existing increaseAvailablePermits calls are deleted as part of the change or exempted from the budget? As written an implementer reading only the PIP produces silently weakened backpressure.
Two adjacent cases worth a sentence while you are here:
ConsumerImpl.java:1536-1543 (discard prior to startMessageId) returns no permit today — a real existing leak the budget would silently fix. Worth naming as an intended side effect so it lands with a test.handleCryptoFailure FAIL (:2092-2105) deliberately returns nothing and holds the message for redelivery. The budget rule changes that; say so on purpose or exempt it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Agreed, and thank you for identifying the four concrete paths. I addressed them through one client-ownership rule: a direct return must atomically consume the command-owned units, so later terminal cleanup returns zero. The specialized payload section now explicitly transfers authority to the existing chunk, crypto-failure, and custom-processor paths and forbids the generic budget from draining afterward. It also names the pre-startMessageId return as an intended leak fix and preserves the no-return behavior for crypto FAIL.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks — this is resolved, and the way you split it (one atomic terminal transition for the generic budget, explicit ownership transfer for the specialized paths) is better than the enumeration I was asking for.
Mapping my four sites onto the current text so the record is explicit:
:421 "Consume and return the P = 1 budget once":424 "Leave the unit command-owned"DISCARD → :485-486 "its existing permit cardinality remains authoritative and the generic budget must not also drain"startMessageId → :407 names it as an intended correction, and :615-616 carries the testFAIL → :486-487 keeps the no-return behavior on purpose:404-406 is the sentence that does the work: it makes an existing increaseAvailablePermits call either budget-consuming or wrong, which is what I wanted an implementer to be unable to miss.
Two small things I'd still like your view on, then I'm happy:
The document never quite says that the existing increaseAvailablePermits call sites are rewritten rather than left alongside the budget. It is derivable from :404-406, but one sentence would remove the derivation step for whoever implements this.
"its existing permit cardinality remains authoritative" at :485 is exact for chunks, but for crypto DISCARD the existing cardinality is B, not P — discardMessage(messageId, cnx, DecryptionError, batchSize) returns batchSize. On a partial-batch redelivery where P < B that over-returns B - P, which is the harm :86 names. :178-179 does put that path out of scope, so this is not a contradiction — but since :485 now specifies the behavior rather than merely deferring it, I think it is worth saying plainly that the deferred paths may return more or less than P and that this is accepted for now. Otherwise "authoritative" reads as "exact".
Leaving this thread open for those two; nothing here changes the design.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Assisted-by: OpenAI Codex
There was an error while loading. Please reload this page.
|
Thanks for the detailed review and for grounding the comments in the current implementation. I treated the feedback as four connected gaps rather than isolated wording changes. First, the broker now has one finalization boundary: P becomes authoritative only after admission, and the same finalized per-entry values and sum feed command serialization, consumer accounting, every applicable dispatcher aggregate, and the avgMessagesPerEntry sample. Only emitted entries and their finalized P values participate; pre-admission candidates, rejected entries, and other intermediate counts are excluded. The existing EMA behavior otherwise remains unchanged. Second, the Java side now has one ownership model: the command budget initially owns P, each accepted native message transfers one unit to its existing lifecycle, and one terminal transition returns only the units still command-owned. Specialized payload processing and dead-letter handling have explicit ownership-transfer rules, while permit ownership remains separate from MessageImpl lifetime. Third, I narrowed the failure scope. The decompression description now matches the current processing order, while new broker write-failure handling has been removed because the proposal did not establish a concrete gap beyond existing transport cleanup. Finally, the compatibility tradeoffs are explicit. The PIP keeps optional-field fallback without a new capability flag, documents the ambiguity this preserves, and links the related Flow-removal work without combining its scope with this proposal. Together, these changes preserve one end-to-end invariant: every emitted command has one finalized debit P, every covered broker counter uses that same value, and the in-scope Java lifecycle either returns exactly that debt to the source incarnation or discards it when that incarnation no longer exists. I replied to each inline thread and left them open for your confirmation. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the very substantial revision — this is a much stronger document than the one I read. All eight points I raised are handled in the text, not just in the replies, and two of them (removing root cause 4, and the six-dispatcher aggregate table) took real work to get right.
What I checked, and what I now believe:
:336-343 matches every post-send aggregate debit in the tree today. I confirmed the six sites: PersistentDispatcherMultipleConsumers (two loops), PersistentDispatcherMultipleConsumersClassic (two loops), PersistentStickyKeyDispatcherMultipleConsumers:348, PersistentStickyKeyDispatcherMultipleConsumersClassic:401, NonPersistentDispatcherMultipleConsumers:210, and NonPersistentStickyKeyDispatcherMultipleConsumers:185. :345 ("normal, replay, and chunk-specific loops") covers the doubled sites. Nothing else under pulsar-broker/src/main debits an aggregate on send.Consumer.sendMessages reading behind root cause 2 holds: the debit is MESSAGE_PERMITS_UPDATER.addAndGet(this, ackedCount - totalMessages) where totalMessages is the pre-admission parameter and ackedCount spans rejected entries too, so it over-debits by a rejected entry's P exactly as :153 says.:184 plus :327-329 close it cleanly.Two new points come from reading this revision, both about text the last round did not contain. Neither is a design objection — the first is a scope widening I think was unintentional, the second is a section-placement question. Details inline.
The empty mailing-list links at :685-686 are expected at this stage; worth filling before the vote thread starts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| `P` to equal the deliverable `ack_set` cardinality, with every set bit in `[0, B)`. A non-empty all-zero `ack_set`, an | ||
| out-of-range set bit, or native expansion beyond `P` is malformed. Validation occurs before accepting a native | ||
| message whenever the required metadata is available. A malformed command returns no Flow credit and closes the | ||
| source connection so the associated broker-side debt is discarded. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
[DESIGN] the disconnect trigger widened from "invalid explicit value" to "malformed command", which now contradicts the Alternatives bullet and can fire against an old broker
In the version I reviewed, this rule read:
An invalid explicit value is a protocol error: the client sends no Flow credit and closes the source connection…
It now reads:
A malformed command returns no Flow credit and closes the source connection so the associated broker-side debt is discarded.
and the set of malformed conditions defined just above it (:375-377) grew to include several that do not involve the explicit field at all:
B is not positive;ack_set;P.Those are derived from the payload and from ack_set, both of which an old broker supplies. :377 says "Validation occurs before accepting a native message whenever the required metadata is available" — with no explicit-field precondition — so on an old-broker connection the client resolves P through step 2 or 3 of the ladder at :364-369 and can still reach the disconnect. "Native expansion beyond P" is the sharpest case: when P came from ack_set cardinality, exceeding it means the decoded payload disagreed with the broker's ack set, which is ordinary payload corruption.
That collides with the Alternatives bullet at :581-583, which is unchanged:
Always disconnect on ambiguous payload failure: discards the debt but disrupts every producer and consumer on a multiplexed connection. Disconnect remains appropriate for an invalid explicit value, not normal data corruption or old-protocol ambiguity.
The blast radius that bullet describes is real: ClientCnx is pooled, so closing it takes down unrelated producers and consumers, and ConsumerImpl closes the channel in only two places today — both in the subscribe path, never from messageReceived. Compare the zero-queue rule you wrote at :478, which closes the consumer; that matches ZeroQueueConsumerImpl.rejectBatchMessageByClosingConsumer, which calls closeAsync() on the consumer rather than on the channel.
I don't think you meant to widen it. Two ways to land it, either is fine:
P only, and route the metadata/ack_set inconsistencies to a bounded outcome (discard the command, return P, close the consumer) — this keeps :581-583 true as written; or:581-583 so the two sections agree, saying explicitly that old-broker payload inconsistency can now close a shared connection.Worth settling before the vote, since it is the one place where this PIP changes client behavior against brokers that have not been upgraded.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ``` | ||
|
|
||
| When no entry is emitted, the average is not updated. This statistic therefore describes final deliverable logical | ||
| messages per emitted entry, and the existing `ConsumerStats.avgMessagesPerEntry` field exposes that corrected value. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
[MINOR] the avgMessagesPerEntry change is observable in stats and in dispatcher read sizing, but appears only here and not in Public-facing Changes
This answers what I asked in the earlier thread — thank you; the zero-emitted-entries rule at :358 also closes the +Infinity edge I mentioned.
Two things I would still pin down, because "exposes that corrected value" understates the reach:
It is observable. ConsumerStatsImpl.avgMessagesPerEntry is a public stats field, surfaced through pulsar-admin topics stats and StreamingStats. Today the numerator is the pre-admission totalMessages (summed B); under this PIP it becomes summed P. For a partial-batch redelivery those differ, so an operator watching that number sees it move after upgrade. The Public-facing Changes section at :490-520 currently covers only the protocol field, and :188 puts new metrics out of scope — which is not the same thing as a changed value on an existing one. A voter reading only that section would not learn about this.
Its consumers are wider than preciseDispatcherFlowControl. The subsection heading and :613 both frame this around that setting, but getAvgMessagesPerEntry() also drives PersistentStickyKeyDispatcherMultipleConsumers:730-744, which converts maxUnackedMessages headroom into an entry estimate whenever maxUnackedMessages > 0, independent of preciseDispatcherFlowControl. Since summed P ≤ summed B, the average can only fall, so both ceil(availablePermits / avg) and estimatedRemainingPermits rise: this changes Key_Shared read sizing under redelivery-heavy load. That is arguably the correct direction, but it is a dispatch-behavior change and deserves to be named rather than inferred.
A sentence in Public-facing Changes plus a test-matrix line for the read-sizing consequence would cover both.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the write-up, and for treating the comments as connected gaps rather than line edits — that produced a better document than answering them one at a time would have. I've confirmed each thread inline. Six are resolved; I left the budget thread open for two small follow-ups, and opened one new comment on the On the verification side, I re-walked the two claims that carry the most weight for a voter. The dispatcher table at Worth filling in the mailing-list links at |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@lhotari Apologies for the delayed follow-up, and thanks for the careful review. I revisited the three open points together and kept the revision centered on exact permit accounting for the in-scope standard Java native path. I removed the finalized- I narrowed the connection-level error to an explicit I also clarified the ownership boundary. Existing direct permit-return sites in the in-scope path must be rewritten or removed so they cannot coexist with the terminal drain. After a specialized path takes ownership, the generic budget returns nothing; the specialized path may currently return less than, equal to, or greater than Finally, I aligned the central ownership invariant, the necessary in-scope lifecycle boundaries, and the test matrix, and added the mailing-list discussion link. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| output-cardinality semantics are not redefined by this PIP. The Flow-removal race is tracked by | ||
| [issue #26288](https://github.com/apache/pulsar/issues/26288) and | ||
| [PR #26289](https://github.com/apache/pulsar/pull/26289). That work touches some of the same counters but enforces a | ||
| Flow-side consumer-removal invariant; implementations must account for merge order without combining its scope with |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just a small update: since #26289 has already been merged into master, the original wording about merge order is now stale.
PIP‑491’s implementation will build on top of the pendingDispatcherFlowPermits accounting instead of racing with #26289. Since both changes touch messagePermits and dispatcher aggregate permits, could this paragraph be updated to state that the Flow‑side removal invariant from #26289 is the baseline that the finalized‑P send debit must preserve?
I don’t believe we need to pull the Flow race itself into this PIP’s scope, but one integration test that includes a pending Flow update together with a send/removal would help ensure the two accounting rules remain compatible.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Appendix B now identifies merged #26289 as the baseline and states the pending-Flow accounting invariant that the finalized send debit must preserve. I also added one combined Flow/send/removal requirement to the implementation test matrix, including negative removal balances. The Flow-side design remains unchanged.
Updated in 7c71574abef.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| does the broker record `P` in the per-send result, before handing entries to the asynchronous command sender: | ||
|
|
||
| ```text | ||
| entry is not sent => no command and no debit |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A late eligibility check still appears to occur after finalization.
In PulsarCommandSenderImpl.sendMessagesToConsumer(), the condition batchSize > 1 && !cnx.isBatchMessageCompatibleVersion() can still be met, causing the connection to close and the entry to be released with a continue, without emitting a CommandMessage. This scenario is reachable when an older consumer subscribes before the topic has published its first batch, as the subscribe-side check only rejects if hasBatchMessagePublished is already true.
In such a case, Consumer.sendMessages() has already finalized and debited at point P. While existing connection teardown should eventually discard that debt—preserving long-term accounting—it does strengthen the guarantee entry not sent => no command and no debit beyond what the current send pipeline can ensure.
Could we either move this compatibility check before finalization, or narrow this rule to entries rejected by final admission, and explicitly treat late sender aborts as teardown cases?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Agreed; I took your second option. The broker finalization section now limits the zero-debit rule to admission rejection and explicitly treats the downstream batch-compatibility abort as an existing teardown case. I aligned the related admission wording; no check is moved and no new write-failure handling is proposed.
Updated in 7c71574abef.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Assisted-by: Codex
|
Two related points from reworking #21767, which fixes races when the Java client clears its incoming queue:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.