Repository navigation
Send a transaction to the primary when it has primary-only work and the caller prefers a replica - #3381
Open
ShmueLior wants to merge 1 commit into
Open
Send a transaction to the primary when it has primary-only work and the caller prefers a replica#3381ShmueLior wants to merge 1 commit into
ShmueLior wants to merge 1 commit into
Conversation
…he caller prefers a replica LockExtend and LockRelease fall back to a WATCH/MULTI/EXEC transaction on servers without SET IFEQ / DELEX (before 8.4). The transaction was routed with the caller's flags, so PreferReplica sent it to a replica, which then rejected the queued EXPIRE/DEL and dropped the connection. The transaction now applies the same rule as Message.SetPrimaryOnly: if any queued operation is primary-only, PreferMaster/PreferReplica become DemandMaster. DemandReplica is left alone.
This branch has not been deployed
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.
Follow up to #3291.
On servers before 8.4 there's no SET IFEQ / DELEX, so LockExtend and LockRelease fall back to a WATCH/MULTI/EXEC transaction, executed with the caller's flags. EXEC isn't primary-only, so with PreferReplica the transaction went to a replica. The queued EXPIRE / DEL was then rejected with
Command cannot be issued to a replica: EXPIRE ..., and since that throws inside the write, the replica connection was torn down too. #3291 fixed the IFEQ / DELEX path but not this one.TransactionMessagenow does whatMessage.SetPrimaryOnlydoes for a single command: if any queued operation is primary-only, PreferMaster / PreferReplica become DemandMaster. A transaction with only reads still follows the caller's flags, and DemandReplica is left alone so it fails the same way it does today. This also fixes user transactions that contain a write and are executed with PreferReplica.Why not just pass DemandMaster from LockExtend / LockRelease: that only fixes the two helpers, and it's about the same size.
Tests (TransactionTests, against the primary/replica pair, RESP2 and RESP3):
PrimaryOnlyWorkWithPreferReplicaRunsOnThePrimary: condition + EXPIRE, and condition + SET, executed with PreferReplica (sync and async), checks EXEC ran on the primary. Fails on main on any server version.ReadOnlyWorkWithPreferReplicaStillRunsOnTheReplica: condition + GET with PreferReplica still runs EXEC on the replica.KeyTests.PrimaryOnlyCommandsWithPreferReplicaRunOnThePrimarynow passes on Redis 8.0.2 too (it failed on main there). Ran the full suite on net8.0 and net10.0 against 8.0.2 (primary/replica + cluster), no new failures compared to main. Also checked LockExtend / LockRelease with PreferReplica on a local 8.0.2 cluster. Didn't run net481.Checklist