Commit Graph

7 Commits

Author SHA1 Message Date
Till Krüss eb8805e25e Keep the WATCH of a cluster transaction after a server error (#1764)
* Unwatch the keys when a server error escapes a transaction block

A transaction block that threw a server error, such as WRONGTYPE from a
command run before multi() in CAS mode, left its WATCH on the connection
because MultiExec ignored the exception. The next transaction on that
connection then failed with a spurious abort once a watched key had
changed. A server error now discards the transaction like any other
exception leaving the block, which sends UNWATCH before MULTI and
DISCARD after it.

* Keep the WATCH of a cluster transaction after a server error

A cluster transaction sent UNWATCH and released its node when a command
run before multi() in CAS mode got an error reply, such as WRONGTYPE
from GET or NOPERM from a second WATCH. A block that caught the error
and went on to multi() then ran MULTI and EXEC on a connection that
watched nothing, so a change to a watched key was silently overwritten.
Redis keeps the WATCH after an error outside MULTI, and so does a
non-cluster transaction, which fails EXEC on a conflicting change.

The node that already holds the transaction now keeps its WATCH and the
error is thrown. A -MOVED reply only updates the slots map: the queued
commands are rejected by that node, so the transaction cannot commit on
the new one without the WATCH. An error on the first command still
releases the node, as nothing is watched yet.

* Add the cluster WATCH fix to the changelog

* Give the CAS MOVED test the slot its WATCH key has

Cluster transactions now retry a MOVED reply only for the transaction's
own slot. The test's mocked strategy returned no slot, which a WATCH
key always has, so its queued MOVED was reported instead of retried.
2026-11-18 01:23:59 -07:00
Till Krüss a65a761f11 Report cluster transaction server errors instead of retrying them (#1763)
* Report cluster transaction server errors instead of retrying them

Every error reply to MULTI, to a queued command or to EXEC went through
abort() and made executeTransaction() return null, which
MultiExec::execute() reads as a WATCH conflict. A command Redis
rejected (CROSSSLOT, OOM, wrong arity, BUSY) therefore surfaced as "The
current transaction has been aborted by the server." without the
server's message, and with the retry option the block ran again against
an error that would repeat.

Only the errors a retry can get past still return null: MOVED for the
transaction's own slot, whose abort updates the slots map, TRYAGAIN,
CLUSTERDOWN, READONLY, and the "Transaction failed" error Relay uses to
report a WATCH conflict. Everything else is reported like on a single
node: a rejected queued command is returned to MultiExec, which throws
AbortedMultiExecException with the server's message, and an error from
MULTI or EXEC throws ServerException. Cleanup and slots map updates stay
as they were, and the transaction is reset, so it can be used again.

ASK is reported too. A transaction does not send ASKING, so every retry
reaches the same node and gets the same ASK until the migration ends.

LOADING, BUSY and MASTERDOWN are not retried either, as MultiExec
retries without waiting and single node transactions don't retry them.

* Add the cluster transaction error fix to the changelog

* Avoid a word the spell check rejects in the README

* Drop the Relay case from cluster transaction errors

RelayConnection now returns null when a watched key aborts EXEC, like
the stream connection, so a cluster transaction no longer sees Relay's
"Transaction failed" error and does not need to treat it as retryable.
2026-11-18 01:23:59 -07:00
Till Krüss 7bfe1357e8 Fail cluster transactions after a lost WATCH or a rejected command (#1759)
* Fail cluster transactions after a lost WATCH or a rejected command

A cluster transaction kept in use after losing its connection between
WATCH and MULTI committed on a new connection, without the WATCH. A
block that caught a cross-slot error committed the other commands.

Like with a single node, commands now fail until discard() or unwatch()
once the connection is lost, and EXEC fails with EXECABORT after a
rejected command.

* Add the cluster transaction fixes to the changelog

* Release a cluster transaction even when its cleanup fails

A connection lost while discard() or unwatch() sent UNWATCH marked the
transaction as lost again, after MultiExec had already reset it, so it
stayed unusable.

* Only fail a cluster transaction for commands rejected after MULTI

A cross-slot command before multi() in CAS mode runs on its own and is
never queued, but it still made EXEC fail with EXECABORT, so a block
that caught the error and went on to multi() could not commit, while
Redis and non-cluster transactions commit it.

* Report a lost cluster connection before a rejected command on EXEC

MultiExec now resets once EXEC fails with a server error. A cluster
transaction that lost its connection and also had a command rejected
failed EXEC with EXECABORT, so MultiExec reset and discard() could no
longer release the lost connection, failing every later command. EXEC
now reports the lost connection first, so the transaction keeps its
state until discard(), as it does on a single node.
2026-11-18 01:23:58 -07:00
Till Krüss 5a9a7665cb Fix cluster transaction cleanup and CAS behavior (#1735) 2026-10-07 10:02:58 -07:00
Till Krüss 581c5659bd update year in headers 2026-02-23 11:48:06 -08:00
vladvildanov bf526cc129 Codestyle fixes 2025-03-31 12:14:37 +03:00
Vladyslav Vildanov 73e6a03fd8 Added support for transactions in OSS Cluster (#1497)
* Added support for transactions in OSS Cluster

* Updated test cases

* Updated version restriction

* Updated server version restriction

* Added test skip for Relay

* Added test case for Relay

* Set transaction slot to null in case of failed transaction

* Restrict usage of transaction commands outside of transaction context

* Added handling for Relay responses

* Reverted changes

* Removed unsupported command

* Added dummy arguments

* Codestyle fixes

* Added additional test coverage

* Added CHANGELOG and README entries

* Added missing PR reference

* Missing word

* Fixed README
2025-03-07 10:31:02 +02:00