* Do not follow -ASK on the first command of a cluster transaction
A cluster transaction is held on the node the slots map associates
with its slot, but its first command went through the cluster like any
other one. While a slot was being migrated, an -ASK reply to WATCH (or
to the first command in CAS mode) was followed to the node importing
the slot, and only then was the connection pinned from the slots map,
which -ASK does not update. WATCH was left on the importing node while
MULTI, the queued commands and EXEC ran on the source node with nothing
watched, so the transaction committed even though the watched key had
changed. When the transaction failed after that WATCH, the cleanup was
sent to the source node and the WATCH on the importing node was never
released, so its dirty flag aborted a later, unrelated transaction sent
over the pooled connection.
The first command is now sent through
RedisCluster::executeCommandOnSlotOwner(), which retries and follows
-MOVED and -READONLY like executeCommand() but returns -ASK replies.
The transaction then fails with a ServerException carrying the -ASK
reply, as later CAS commands already did, without touching the
importing node. Retrying once the migration has finished reaches the
new owner. An -ASK reply to a queued command still aborts the
transaction, as before.
The README no longer claims that the first command is redirected like
any other command, and describes how an -ASK reply fails a transaction.
* Add the cluster ASK fix to the changelog
* Return null when a watched key aborts a Relay EXEC
When a watched key aborts EXEC, Redis replies with a null array but
Relay throws "Transaction failed", and RelayConnection returns that as
an error response. The strategy mapped it to null in a catch for a
ServerException, which RelayConnection never throws, so a transaction
aborted by WATCH failed with a ServerException instead of
AbortedMultiExecException and the retry option was ignored.
RelayConnection now returns null for that failure of EXEC, as the
stream connection does for the null array, so every strategy handles it
the same way. The dead catch in NonClusterConnectionStrategy is removed,
and so is the exclusion that kept a Relay connection open when EXEC
fails with an error other than EXECABORT, since a WATCH abort no longer
reaches it. A Relay connection whose EXEC was rejected while MULTI
stays open is now closed like any other.
Client::exec() on a Relay connection returns null after a WATCH abort,
as it does on other connections.
* Add the Relay WATCH abort fix to the changelog
Relay::select() throws a TypeError for anything but an integer, where
other connections get an error response from the server. Wrap the call
and return the same error response, so the existing test runs against
Relay and no longer needs a Relay-only counterpart.
Relay warns before sending SELECT for out-of-range databases, so that
test keeps its Relay-specific counterpart.
Disconnect interrupted pipeline connections before they can be reused,
discard remaining commands, and reset running state after PHP errors.
Preserve the original failure when connection cleanup also fails.
Clear the cached connection resource when Relay is closed so the next
command reconnects and replays connection initialization. This fixes
client reuse after an interrupted pipeline disconnects the connection.
queryClusterNodeForSlotMap() overrides Retry's default catchable exception
list with [ConnectionException::class]. StreamInitException extends
PredisException directly, so a CLUSTER SLOTS refresh that cannot open a
connection to the node it was redirected to is neither retried nor allowed
to fall back to another node: the fail callback that evicts the unreachable
node never runs, and the exception escapes uncaught.
* feature: Added support for READONLY responses from AWS Elastic Cache
* chore: improve -READONLY handler comment and add changelog entry (#1656)
* tests: add unit test demonstrating ServerException behavior with READONLY error
* Initial work on retries
* Added retry class and test coverage
* Added support for standalone and cluster
* Make TimeoutException instance of CommunicationException
* Added pipeline, trasnaction, replication support
* Fixed broken test
* Marked test as relay-incompatible
* Marked test as relay-incompatible
* Fixed analysis errors, added missing tests
* Codestyle fixes
* Fixed test
* Update README.md
* Update README.md
* Update README.md
* Updated README.md
* Refactor retry on read and write
* Added check for timeout value
* Updated README.md
* Fixed README.md
* Codestyle changes
* Added missing coverage
* Added missing test coverage
* Removed comments
* Added retry support for Relay connection (#1620)
* Added integration test case with mocked retry
* Changed client initialisation in tests
* Marked test as relay-incompatible
---------
Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
* Retry SentinelReplication::retryCommandOnFailure on all classes with Throwable interface
* Retry SentinelReplication::retryCommandOnFailure on all classes with Throwable interface
* Fix coding style
* fix(sentinel-replication): Treat LOADING error responses as ConnectionException to allow retry mechanism to discard the current replica and switch to the next available one.
* fix(sentinel-replication): add changelog entries for LOADING response handling
* Update CHANGELOG.md
* Update CHANGELOG.md
---------
Co-authored-by: Mustafa AKBEL <mustafa.akbel@pusula.net.tr>
Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>