Repository navigation
fix(binding-mqtt-kafka): acknowledge qos1 publish only as far as kafka has acknowledged it - #3295
Merged
Merged
Conversation
…tain available Adds a paired mqtt and kafka script scenario for ten 1 KB QoS 1 publishes with retain available, with spec-level and runtime ITs. These pass against the current code; the window acknowledge defect in #3289 is not yet observable from the scripts. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
… with retain available" This reverts commit f31f64b.
…resets with retain available A produce stream reset while QoS 1 packets are not yet acknowledged by Kafka must fail those packets. With retain available and a produce stream that grows its maximum while holding its acknowledge, the proxy treats the packets as acknowledged, so no failure is reported (#3289). The runtime IT fails until the window acknowledge is derived from the unacknowledged bytes of both streams. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…a has acknowledged it With retain available the publish window acknowledge was derived from the smaller of the messages and retained stream maximums and the smaller of their credit budgets. A stream that holds its acknowledge and grows its maximum by its unacknowledged bytes keeps a constant budget, so the derived acknowledge reached the received sequence regardless of what Kafka had acknowledged and every QoS 1 publish was acknowledged on receipt. Derive the acknowledge from the larger unacknowledged byte count of the streams and the maximum from the smaller budget plus that count. A stream re-begun after a reset starts with the credit budget only, not the unacknowledged bytes of the stream it replaces. Fixes #3289 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…er member The cache server produce fan remembered the last acknowledged partition offset it had flushed on the fan, not on each member. A fan has one member per cache client fan, one per engine worker, so once the first member was flushed for an acknowledged offset every other member was skipped for that acknowledgement and never learned that its own entries were acknowledged. The entries stayed unacknowledged, so a producer waiting on them, for example a QoS 1 publisher holding its in-flight limit, stalled until a later acknowledgement happened to reach the member first. Track the last flushed acknowledged offset per member. No IT covers this: it needs two members on one server fan, which only arise across engine workers. Verified on a real broker with 6 stack runs of a throttled ingest followed by a fresh publisher: it stalled in 5 of 6 runs before and in 0 of 6 after. Refs #3289 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
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.
Description
QoS 1 PUBLISH packets were acknowledged (PUBACK reason 0) as soon as Zilla received them, not when Kafka had acknowledged the produce. Under a slow broker, clients were told messages were accepted while they sat in a growing backlog, and an acknowledged backlog is lost if the process stops.
Two defects, fixed in two commits.
1.
binding-mqtt-kafka: window acknowledge ignored the produce acknowledgeWith retain available,
doMqttWindowderived the MQTT-side acknowledge from the smaller of the messages and retained stream maximums and the smaller of their credit budgets. The cache client holds the messages stream's acknowledge at its oldest unacknowledged byte and grows its maximum by the unacknowledged bytes, so that stream's budget stays constant. The retained stream acknowledges each flush at once. The derived acknowledge therefore reached the received sequence regardless of Kafka, and the MQTT server sent each PUBACK on receipt.The acknowledge is now derived from the larger unacknowledged byte count of the streams, and the maximum from the smaller budget plus that count. Without retain this equals the previous result. Pattern mirrored:
KafkaMergedFactory.doMergedInitialWindow(maximum unacknowledged, minimum budget, maximum = budget + unacknowledged). A stream re-begun after a reset starts with the credit budget only, not the unacknowledged bytes of the stream it replaces.2.
binding-kafka: produce acknowledgement flushed to only one cache server memberOnce real acknowledgements gate PUBACKs, a second defect becomes visible. The cache server produce fan remembered the last acknowledged offset it had flushed on the fan, not per member. A fan has one member per cache client fan (one per engine worker), so after the first member was flushed for an acknowledged offset every other member was skipped for it and never learned its entries were acknowledged. A publisher waiting on those entries, for example a QoS 1 client at its in-flight limit, stalled. The last flushed offset is now tracked per member.
Evidence (real broker,
examples/mqtt.kafka.proxy, Kafka limited to 1 CPU)Tests
MqttKafkaPublishProxyIT.shouldPublishQos1RetainAvailableServerSentResetInFlightwith paired mqtt and kafka scripts and spec-levelMqttIT/KafkaITmethods: a produce reset while QoS 1 packets are unacknowledged must fail those packets with reason 0x83. It failed before the fix and passes after../mvnw clean verify -pl runtime/binding-mqtt-kafka(168 ITs) andruntime/binding-kafka(229 unit tests, 469 ITs) pass with checks on.Not addressed
mqtt-deviceswas in its own batch, with-F 1and with-F 1000alike. Not changed here.IndexOutOfBoundsExceptionin segment compaction, and a SIGSEGV after a broker pause). I have not retested them with these fixes.Fixes #3289
Generated by Claude Code