[client] Retry stale out-of-order responses without resetting writer - #4125
Open
litiliu wants to merge 1 commit into
Open
[client] Retry stale out-of-order responses without resetting writer#4125litiliu wants to merge 1 commit into
litiliu wants to merge 1 commit into
Conversation
…idempotent writer An idempotent writer could be fatally reset by a stale OutOfOrderSequence response, killing all in-flight writes across every bucket. Failure scenario addressed: with max-inflight > 1 and acks=all, PutKv/ProduceLog responses are returned in completion order (a bucket's error result rides along with its request, whose response is gated by the slowest replicating bucket in that request). A batch (seqN) can transiently fail (e.g. NotLeaderOrFollower during a leader/partition transition) so its successor (seqN+1) hits an empty or behind writer state and is rejected with OutOfOrderSequence. seqN is then retried and acknowledged, advancing lastAckedBatchSequence, before seqN+1's already-generated out-of-order response is delivered. At that point the batch looks like the next expected sequence, so canRetry treated it as an unrecoverable regression and reset the writer id, which then dropped other in-flight batches with UnknownWriterId. Fix: snapshot each batch's lastAckedBatchSequence at send time (WriteBatch.lastAckedSequenceAtSend, set in Sender before dispatch, refreshed on every send attempt). In IdempotenceManager.canRetry, retry an OutOfOrderSequence when the acked sequence has advanced since the batch was sent (current lastAcked > lastAckedSequenceAtSend): that advancement means a predecessor was acknowledged while the batch was in flight, so the response is a superseded (stale) one that a reordering surfaced late, and a retry will observe the advanced state and succeed. A genuine regression shows no such progress and still resets. Adds SenderTest cases for the stale (retry, no reset) and genuine (reset) out-of-order paths, and one asserting the send-time snapshot is refreshed on retry so a repeated out-of-order response with no new ack still resets.
litiliu
marked this pull request as ready for review
August 28, 2026 02:16
litiliu
marked this pull request as draft
August 28, 2026 02:48
litiliu
marked this pull request as ready for review
August 28, 2026 06:44
leekeiabstraction
approved these changes
Aug 29, 2026
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.
Purpose
Linked issue: close #4121
Prevent an idempotent writer from being reset when an out-of-order response reflects an older server state and the acknowledged sequence has advanced while the batch was in flight.
Brief change log
SenderTest.Tests
./mvnw -pl fluss-client -DskipITs -Dtest=SenderTest testAPI and Format
No public API or storage format changes.
Documentation
No user-facing documentation changes.