Repository navigation
ring: count each key once when it reaches quorum in DoBatch - #7975
Merged
Merged
Conversation
batchTracker.record decremented rpcsPending on every success at or past a key's quorum. With RF 3 a fully replicated key counted twice, so in rare cases DoBatch returned success before every key reached quorum, and an error from a key that failed on all its replicas was not returned. Count a key only on the success that reaches its quorum, as dskit does (grafana/dskit#430). Successes past quorum still skip the remaining-instances check. Require at least one success per key, so a replication set with MaxErrors >= len(Instances) cannot leave the key uncounted. Signed-off-by: Alan Protasio <alanprot@gmail.com>
Scripted tests fix the order in which DoBatch records each instance's outcome: fully replicated keys next to keys that miss quorum (4xx and 5xx, several orders), keys at exactly quorum, error family selection, a replica filtered out, MaxErrors 0 and MaxErrors >= len(Instances), failed RPCs counting for every key in them, and outcomes recorded after the context is canceled. TestDoBatch_EveryCompletionOrder checks every result and completion order over small layouts. Randomized tests, one over a real ring, check concurrent completion against the quorum of each key, and that DoBatch never answers success before every key has quorum among the RPCs that have returned. Signed-off-by: Alan Protasio <alanprot@gmail.com>
Push fails when a series is rejected by all its ingesters while the other series replicate fully. mockIngester can now reject chosen series the way a real ingester does: store the others and fail the whole RPC with 400. Tests pin how such a failure counts against every series in the RPC. Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
danielblando
approved these changes
Nov 27, 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.
What this PR does:
batchTracker.recorddecrementsrpcsPendingon every success at or past a key's quorum, not only on the success that reaches it. With RF 3, a fully replicated key is counted twice. In rare cases, this letsDoBatchreturn success before every key has reached quorum, so an error from a key that failed on all its replicas is not returned.Example with two keys and RF 3 (quorum 2). Key A succeeds on all 3 replicas, and key B fails on all 3:
DoBatchreturnsnilThis only happens when the failures are recorded after the successes. If B's failure is recorded first, the error is returned as expected.
This change counts each key once, on the success that reaches its quorum, using the same shape as grafana/dskit#430, which fixed this in dskit's copy of
DoBatch. Successes past quorum still skip the "not enough remaining instances" check.minSuccessis also clamped to at least 1, so a replication set withMaxErrors >= len(Instances)still completes on the first success. No in-tree replication strategy produces such a set.Since
DoBatchnow waits until every key reaches quorum, a push takes as long as its slowest series needs to reach quorum, and returns that series' error if it misses quorum.Tests:
pkg/ring: scripted completion orders (4xx/5xx, keys at exactly quorum, error-family rules,MaxErrors = 0, a replica filtered out,MaxErrors >= len(Instances)), every result and completion order over small layouts, and concurrent runs over a real ring that also checkDoBatchnever answers success before every key has quorum.pkg/distributor:Pushfails when one series is rejected by all its ingesters, including when the ingesters store the rest of the RPC and fail it with 400.Notes for reviewers
Push, andDoBatchcounts that failure against every series in it. If two ingesters each reject a different series, a series sent to both counts as failed on 2 of 3 although all three stored it, and the push returns 400. Before this change it returned 200 or 400 depending on response order; now it is always 400.TestDistributor_Push_RejectionsOnTwoIngestersFailASeriesStoredOnAllpins this. Per-series attribution is out of scope.BenchmarkBatch*(no latency) is unchanged.-distributor.use-stream-push,PushStreamConnectionsends tostreamPushChanwithout checking the context, so an RPC can outlive-distributor.remote-timeout. A push now waits for quorum on every series, so two stuck replicas of one series hold it open. Not changed here.Addrare counted as two replicas; zero keys, or an empty replication set, wait until the context deadline; the first key to fail decides the error family of the whole request.Which issue(s) this PR fixes:
None filed.
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags