Set command side-effect category for WithRetry - #540
Merged
Conversation
StackExchange.Redis 3.1.0 added WithRetry, which replays failed operations according to a policy bounded by the command's declared side-effect category. Commands it does not recognise fall back to CommandRetryNever, and it knows nothing about module commands - so today *nothing* NRedisStack issues is eligible for retry. Categorize all 153 builder commands. SerializedCommand gains a CommandFlags category as the first constructor argument, masked on construction to the retry-category region (bits 13-17) plus the server-specific bit (18), so the parameter cannot smuggle in a replica preference or FireAndForget. The uncategorized constructors are [Obsolete] and CS0618 is an error inside the library, so a new command cannot be added without declaring what a replay of it would do. An internal EffectiveFlags property combines the category with the library-wide defaults (absorbing the DEBUG-only NoRedirect from Auxiliary). The library keeps its StackExchange.Redis 3.0.x floor: CommandCategories declares the values as casts rather than referencing the 3.1.0 named members, which are [Experimental] under SER007. On 3.0.x the bits fall outside that version's user-selectable mask and are silently discarded, reproducing current behaviour exactly; on 3.1.0+ they take effect. The test project overrides to 3.1.0 and asserts each rung against the named member, so an upstream renumbering fails loudly instead of silently re-categorizing everything. Notable calls: - BF.ADD/MADD/INSERT are WriteChecked: bloom adds are monotone, so a replay is a state no-op that only changes the returned 0/1. - CF.ADD/INSERT/DEL are WriteAccumulating: a cuckoo filter is a multiset, so a replay changes the counts. - FT.CURSOR READ is WriteAccumulating, not read-only - reading advances the cursor, so a replay skips a page rather than repeating one. It and FT.CURSOR DEL, BF/CF.SCANDUMP and cursored FT.AGGREGATE carry ServerSpecific, which strips failover while still permitting a same-server retry. - FT.CONFIG (GET as well as SET) is ServerAdmin|ServerSpecific, matching how SE.Redis treats plain CONFIG; a different member can be configured differently, so GET is not meaningfully safer. - The blocking core pops are WriteAccumulating: they are destructive reads, so a replay pops a further element and the first one is already lost. - TS.ADD/TS.MADD are uniformly WriteAccumulating for now; see the comment in TimeSeriesCommandsBuilder for why the overload taking TsAddParams cannot see which of three possible rungs applies.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e5ad774aa
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
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.
SE.Redis 3.1.0 adds "retry" support; this needs context on the operation being performed (see here), so: we add these.
Note that I have intentionally not added a 3.1.0 dependency yet; the flags work fine with or without that.
Note
Medium Risk
Wide behavioral change under failover/retry: mis-categorized commands could double-apply writes or skip safe retries; mitigated by exhaustive categorization and unit tests pinning argument-dependent cases.
Overview
Adds side-effect categories on every Redis Stack command so StackExchange.Redis 3.1+
WithRetrycan decide whether a lost reply may be replayed. Categories are carried onSerializedCommand(CommandCategory/EffectiveFlags) via a newCommandCategoriesladder that mirrorsCommandFlags.CommandRetry*using cast constants so the library still builds against SE.Redis 3.0.x (extra bits are ignored there).Dispatch now passes
command.EffectiveFlagsinstead of a single globalCommandFlagsvalue; uncategorized command paths useSerializedCommand.Uncategorized, and the oldSerializedCommandconstructors are[Obsolete]with CS0618 treated as an error in the main project so all builders must categorize.Per-module builders (Bloom, JSON, Search, TimeSeries, etc.) tag each command as read-only, conditional write, last-wins, accumulating, never-retry, server-specific, and so on. Notable argument-dependent rules include
JSON.SET(NX/XX →WriteChecked), RediSearch cursor / WITHCURSOR →Never, blocking list/stream pops →WriteAccumulating, andTS.ADDcategory fromTsAddParams.ResolveCategory(timestamp*,ON_DUPLICATE, etc.).ExecuteBroadcastgains overloads that accept an explicit category.Tests pin category bit alignment with SE.Redis 3.1.0 and cover the tricky cases in
CommandCategoryTests.Reviewed by Cursor Bugbot for commit cc8dbe9. Bugbot is set up for automated code reviews on this repo. Configure here.