Repository navigation
Share the Lettuce batch span among all commands of the batch - #845
Merged
Merged
Conversation
- Every command written in one write holds a share of its exit span (RedisWriteSpan), taken once by whoever finishes it, and the span finishes with the last share. A failure of any command makes the span an error, logged once; a later exception still counts unless it is ignored by the status check. The span no longer ends early when the last command is cancelled, and a cancellation while the batch is written can no longer leave it without a span or with two. - A delegate writer only sets the peer when a command of the collection already has a span. - The cluster writer does not trace a collection, as it writes the commands of each slot as a batch of their own, which gets its own span. - Mark the span of a reactive command as an error on an error reply, which completes it without an exception.
wankai123
approved these changes
Nov 1, 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.
Share the Lettuce batch span among all commands of the batch
Follow-up to #843, which left three limitations of the
Lettuce/BATCH_WRITEspan. #843 hung that span on the lastcommand of the batch that was not done yet, so:
INCRon a string key gotERR value is not an integer, while the batch span was a success.replies.
chosen command is cancelled before its span is set. Two spans: a delegate writer chooses another command after the
outer writer's choice is cancelled.
Fix
RedisWriteSpan):complete(),completeExceptionally(),cancel(), the writer's re-check of a command that is already done, orthe writer's exception handler.
one, so the span cannot finish while the batch is still being set up.
connection, timeouts) does not log one error per command. A later exception still makes the span an error, unless
it is one of the agent's ignored exceptions (
StatusCheckService).command of the collection already has a span, the delegate only sets the peer. This also covers the cluster ASK
write
[ASKING, cmd].ClusterDistributionChannelWritersplits a batch by slot and writes each slot's commands to itsnode as a batch of their own. So the cluster writer no longer traces a collection: each slot's batch gets its own
span with its node's peer, and keyless commands keep their single-command spans. This is the same span count as
before.
complete(), withthe error left in its output. Before this change, such a span stayed a success. The
complete()interceptor nowchecks
CommandOutput#hasError().AsyncCommandcompletes its inner commandexceptionally first.
The span still records only
cache.typeandcache.cmd=BATCH_WRITE. It carries no list of the batch's commands.Tests
lettuce-scenarioandlettuce-6.5.x-scenarioadd:[INCR on a string key, SET]. Its span must be an error, carrying one log of theRedisCommandExecutionException.INCRon the same key. Its span must be an error with the reply message.RedisChannelWriterInterceptorTestadds unit tests for the cases a scenario cannot reproduce. Each of the four batchtests below fails against
main's code:Ran locally for every version in the four Lettuce
support-version.listfiles (16 versions, Lettuce 5.0.5 to6.7.1), with the mock collector, the agent,
redis:3.2.9-alpineand the validator. All pass.Add a unit test to verify that the fix works.
Explain briefly why the bug exists and how to fix it.
Update the
CHANGESlog.