You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cluster: EXEC during slot migration: partial ASK replies, no-writes scripts refused, stale fast-path check #339
writes() disagrees with pause::holds / may_replicate (src/cluster/routing.rs ~243). writes() counts every EVAL/EVALSHA/FCALL as a write. holds() lets a no-writes script through, as Redis does. So in the lua/full variant, MULTI; EVAL <no-writes script>; EXEC is refused with TRYAGAIN on every retry for the whole handoff. Fix: reuse may_replicate.
Stale fast-path check (src/server.rs ~1436, src/server_uring.rs ~1626). The old || crate::pause::handoff() in the SET-only transaction fast path is now unreachable for real racers. When it does fire, it answers a WATCH-abort null even to an unwatched transaction. Remove it, or make it answer TRYAGAIN.
Option (design): instead of refusing, an EXEC that meets a handoff could drop its gates, wait the handoff out and route its queue again, as single writes do. That is closer to Redis/Valkey atomic slot migration. It's only worth doing if clients have trouble with TRYAGAIN on EXEC.
The CHANGELOG line "refused with TRYAGAIN if it writes" should be updated along with (2).
Tests are missing for: a read-only EXEC during a handoff not being refused, and a transaction with a no-writes script.
Two concrete cases for item 1 (queued commands are routed again, one at a time, inside EXEC), run on a two-master cluster while slot 405 was moving. Both leave a transaction half applied; nothing acknowledged is lost.
Importing node, {t}a and {t}b both already arrived: ASKING; MULTI; DEL {t}b; RENAME {t}a {t}b; EXEC → both QUEUED, then EXEC replies [1, TRYAGAIN Multiple keys request during rehashing of slot]. The DEL ran (ASKING; GET {t}b → nil), the RENAME did not. Redis routes the whole queue once at EXEC and runs both. Reachable since ASKING before MULTI covers the transaction up to its EXEC #746, which keeps ASKING for the transaction.
Migrating source, {t}a present: MULTI; DEL {t}a; SET {t}a v; EXEC → [1, ASK 405 <dest>]. The DEL ran, the SET got ASK. This one was there before.
The cause in both: the commands run inside EXEC are routed with the keys as they are at that moment, so an earlier command in the transaction changes how a later one routes. The fix is to route the queue once, before any of it runs, and not again per command.
@murtazayusuf since you pointed me to this in #770 can I take item 1?
My plan is to route the whole queue once when EXEC starts, using the keys as they are before anything runs. If any command would get MOVED, ASK or TRYAGAIN, the whole EXEC is refused, as Redis does. Otherwise the queued commands run without being routed again, so an earlier command can't change how a later one routes. ASKING keeps its current meaning for the queue, from #746.
I'd add both of your cases as cluster tests: DEL + RENAME on the importing node, and DEL + SET on the migrating source. Both should then run whole, or be refused whole, never half applied.
Yes, please take item 1, @magic-peach, and that is the right plan: route the whole queue once when EXEC starts, with the keys as they are before anything runs; refuse the whole EXEC if any command would be redirected; then run the queue without routing again. Notes so the PR goes straight through:
What a refused EXEC answers. Match Redis: the transaction is discarded and the reply is the redirection itself for the whole EXEC (-MOVED / -ASK / -TRYAGAIN), not an array with errors inside, and -CROSSSLOT stays as route_queue gives it today. Check a real Redis 8 cluster for the exact replies in your two cases and one where only the second command would be redirected, and put them in the PR.
Keys the queue itself creates or deletes. Routing "as before anything runs" is what Redis does, so DEL {t}b; RENAME {t}a {t}b on the importing node is judged on {t}a and {t}b as they are at EXEC. Say in the PR what happens when the first command creates a key the second needs in a migrating slot: Redis's answer, and ours.
WATCH, and EXEC held by a pause (exec_held_in_gate, redispatched): the queue must be routed again on the retry, not reuse a decision from before the pause, since slots can move while it is held.
The fast path.EXEC of plain SETs goes through exec_fast_apply_sets in both loops (src/server.rs, src/server_uring.rs) and already never routes per command; keep it that way, and outside cluster mode nothing may be added to EXEC at all (it is all behind cluster.enabled today). If you touch run_command, the per-command path for ordinary commands must stay as it is.
Tests on both I/O models (the io_models() helper from ASKING before MULTI covers the transaction up to its EXEC #746 is in tests/cluster.rs now), the two cases from my comment above running whole or refused whole, and one for the paused-EXEC retry if you can make it deterministic.
On #850: one thing at a time, and that one needs a diagnosis from our side first (it may be how the script is classified rather than something to implement), so I'd rather not hand it over yet. I'll write what we find there.
@magic-peach yes, and take item 3 with it in the same PR; they are both small and touch the same path.
Item 2: check after EXEC routes its queue once, as one command, and does not route its commands again (#339) #866 where writes() is still consulted for a queued EXEC (src/cluster/routing.rs); make it agree with pause::holds by reusing may_replicate, so MULTI; EVAL <no-writes script>; EXEC and FCALL_RO/EVAL_RO in a queue are not refused during a handoff, while a queue with any command that may replicate still is. Flags are per script (the shebang no-writes flag, and function flags), so the answer has to come from the loaded script, not the command name; a script that is not loaded yet (EVALSHA miss) counts as a write.
Item 3: the || crate::pause::handoff() in the SET-only transaction fast path (both loops). Prefer removing it if you can show nothing reaches it; if something can, it must answer TRYAGAIN for the whole EXEC, never the WATCH-abort null for a transaction that watched nothing.
Tests (cluster, lua build for the script ones): a read-only EXEC during a handoff is not refused; a queue with a no-writes script is not refused; the same queue plus one write is refused with TRYAGAIN as a whole; and the fast-path case. Update the CHANGELOG line "refused with TRYAGAIN if it writes" to say what decides it.
Items 1 to 3 are done: #866 (EXEC routes its queue once and is refused as a whole), and the script-flag and fast-path changes with their tests in #954. Item 4 (waiting a handoff out instead of answering TRYAGAIN) was only worth doing if clients had trouble with TRYAGAIN on EXEC; nobody has reported any, so I'm closing this. If that changes it gets its own issue. Thanks @magic-peach.
Activity
Cluster: EXEC during a handoff is refused only if it may write (#339)
Merge pull request #406 from ShryukGrandhi/fix/issue-339-cluster-exec…
murtazayusuf commentedon Nov 16, 2026
Two concrete cases for item 1 (queued commands are routed again, one at a time, inside
EXEC), run on a two-master cluster while slot 405 was moving. Both leave a transaction half applied; nothing acknowledged is lost.{t}aand{t}bboth already arrived:ASKING; MULTI; DEL {t}b; RENAME {t}a {t}b; EXEC→ bothQUEUED, thenEXECreplies[1, TRYAGAIN Multiple keys request during rehashing of slot]. TheDELran (ASKING; GET {t}b→ nil), theRENAMEdid not. Redis routes the whole queue once atEXECand runs both. Reachable since ASKING before MULTI covers the transaction up to its EXEC #746, which keepsASKINGfor the transaction.{t}apresent:MULTI; DEL {t}a; SET {t}a v; EXEC→[1, ASK 405 <dest>]. TheDELran, theSETgotASK. This one was there before.The cause in both: the commands run inside
EXECare routed with the keys as they are at that moment, so an earlier command in the transaction changes how a later one routes. The fix is to route the queue once, before any of it runs, and not again per command.magic-peach commentedon Nov 17, 2026
@murtazayusuf since you pointed me to this in #770 can I take item 1?
My plan is to route the whole queue once when EXEC starts, using the keys as they are before anything runs. If any command would get MOVED, ASK or TRYAGAIN, the whole EXEC is refused, as Redis does. Otherwise the queued commands run without being routed again, so an earlier command can't change how a later one routes. ASKING keeps its current meaning for the queue, from #746.
I'd add both of your cases as cluster tests: DEL + RENAME on the importing node, and DEL + SET on the migrating source. Both should then run whole, or be refused whole, never half applied.
murtazayusuf commentedon Nov 17, 2026
Yes, please take item 1, @magic-peach, and that is the right plan: route the whole queue once when
EXECstarts, with the keys as they are before anything runs; refuse the wholeEXECif any command would be redirected; then run the queue without routing again. Notes so the PR goes straight through:EXECanswers. Match Redis: the transaction is discarded and the reply is the redirection itself for the wholeEXEC(-MOVED/-ASK/-TRYAGAIN), not an array with errors inside, and-CROSSSLOTstays asroute_queuegives it today. Check a real Redis 8 cluster for the exact replies in your two cases and one where only the second command would be redirected, and put them in the PR.DEL {t}b; RENAME {t}a {t}bon the importing node is judged on{t}aand{t}bas they are atEXEC. Say in the PR what happens when the first command creates a key the second needs in a migrating slot: Redis's answer, and ours.WATCH, andEXECheld by a pause (exec_held_in_gate, redispatched): the queue must be routed again on the retry, not reuse a decision from before the pause, since slots can move while it is held.EXECof plainSETs goes throughexec_fast_apply_setsin both loops (src/server.rs,src/server_uring.rs) and already never routes per command; keep it that way, and outside cluster mode nothing may be added toEXECat all (it is all behindcluster.enabledtoday). If you touchrun_command, the per-command path for ordinary commands must stay as it is.io_models()helper from ASKING before MULTI covers the transaction up to its EXEC #746 is intests/cluster.rsnow), the two cases from my comment above running whole or refused whole, and one for the paused-EXECretry if you can make it deterministic.On #850: one thing at a time, and that one needs a diagnosis from our side first (it may be how the script is classified rather than something to implement), so I'd rather not hand it over yet. I'll write what we find there.
EXEC routes its queue once, as one command, and does not route its co…
Merge pull request #866 from magic-peach/fix/exec-route-queue-once
magic-peach commentedon Nov 19, 2026
@murtazayusuf can I take item 2?
murtazayusuf commentedon Nov 19, 2026
@magic-peach yes, and take item 3 with it in the same PR; they are both small and touch the same path.
writes()is still consulted for a queuedEXEC(src/cluster/routing.rs); make it agree withpause::holdsby reusingmay_replicate, soMULTI; EVAL <no-writes script>; EXECandFCALL_RO/EVAL_ROin a queue are not refused during a handoff, while a queue with any command that may replicate still is. Flags are per script (the shebangno-writesflag, and function flags), so the answer has to come from the loaded script, not the command name; a script that is not loaded yet (EVALSHAmiss) counts as a write.|| crate::pause::handoff()in the SET-only transaction fast path (both loops). Prefer removing it if you can show nothing reaches it; if something can, it must answerTRYAGAINfor the wholeEXEC, never the WATCH-abort null for a transaction that watched nothing.EXECduring a handoff is not refused; a queue with ano-writesscript is not refused; the same queue plus one write is refused withTRYAGAINas a whole; and the fast-path case. Update the CHANGELOG line "refused with TRYAGAIN if it writes" to say what decides it.src/commands/handler.rsandsrc/tag_locks.rs. Yours should not need to touch those files; if it does, say so on the PR and I'll sequence the merges.Cluster tests: the watched-SET handoff test holds EXEC after the impo…
Cluster: tests for EXEC during a handoff, judged by script flags (#339)
Merge pull request #954 from magic-peach/fix/exec-no-writes-scripts
murtazayusuf commentedon Nov 19, 2026
Items 1 to 3 are done: #866 (
EXECroutes its queue once and is refused as a whole), and the script-flag and fast-path changes with their tests in #954. Item 4 (waiting a handoff out instead of answeringTRYAGAIN) was only worth doing if clients had trouble withTRYAGAINonEXEC; nobody has reported any, so I'm closing this. If that changes it gets its own issue. Thanks @magic-peach.