-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Enable multi-command parsing for replicated clients #3597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
enjoy-binbin
merged 5 commits into
valkey-io:unstable
from
enjoy-binbin:replicaed_pipeline
Jun 13, 2026
+250
−9
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19f37ad
Enable multi-command parsing for replicated clients
enjoy-binbin a6364de
code review
enjoy-binbin db3dace
code review: use input_bytes
enjoy-binbin 7909b4d
Merge remote-tracking branch 'upstream/unstable' into replicaed_pipeline
enjoy-binbin 6b2da72
Handle createSlotImportJob
enjoy-binbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| # Tests for multi-command parsing on the replication stream. | ||
| # Verifies that pipelined commands replicated to a replica are parsed in | ||
| # batches into c->cmd_queue while keeping per-command qb_applied tracking | ||
| # (advanced by parsedCommand.input_bytes), so the replication offset stays | ||
| # exact and chained replication converges. | ||
|
|
||
| # Assert primary and replica converge: same digest, dbsize, reploff. | ||
| proc assert_primary_replica_consistent {primary replica} { | ||
| wait_for_ofs_sync $primary $replica | ||
| assert_equal [$primary debug digest] [$replica debug digest] | ||
| assert_equal [$primary dbsize] [$replica dbsize] | ||
|
enjoy-binbin marked this conversation as resolved.
|
||
| } | ||
|
|
||
| # Pipeline correctness on a single primary/replica pair. | ||
| start_server {tags {"repl external:skip"}} { | ||
| start_server {} { | ||
| set primary [srv -1 client] | ||
| set primary_host [srv -1 host] | ||
| set primary_port [srv -1 port] | ||
| set replica [srv 0 client] | ||
|
|
||
| $replica replicaof $primary_host $primary_port | ||
| wait_for_sync $replica | ||
| wait_for_ofs_sync $primary $replica | ||
|
|
||
| test {Multi-command parsing: large SET pipeline keeps reploff exact} { | ||
| set rd [valkey_deferring_client -1] | ||
| for {set i 0} {$i < 500} {incr i} { | ||
| $rd set key1 value1 | ||
| $rd set key2 value2 | ||
| } | ||
| for {set i 0} {$i < 1000} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Multi-command parsing: MULTI/EXEC across pipelined batch} { | ||
| set rd [valkey_deferring_client -1] | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd multi | ||
| $rd set key1 value1 | ||
| $rd set key2 value2 | ||
| $rd set key3 value3 | ||
| $rd exec | ||
| } | ||
| for {set i 0} {$i < 1000} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Multi-command parsing: PROTO_MBULK_BIG_ARG in pipeline} { | ||
| set rd [valkey_deferring_client -1] | ||
| set big_string [string repeat X 100000] | ||
| for {set i 0} {$i < 50} {incr i} { | ||
| $rd set key1 $big_string | ||
| $rd set key2 $big_string | ||
| } | ||
| for {set i 0} {$i < 100} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Multi-command parsing: pipeline survives PSYNC reconnect} { | ||
| set rd [valkey_deferring_client -1] | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set kx$i vx$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| # Force replica to drop the primary connection. | ||
| $replica client kill type primary | ||
| wait_for_sync $replica | ||
|
|
||
| # Push another batch of pipelined writes after the reconnect. | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set ky$i vy$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| assert_primary_replica_consistent $primary $replica | ||
| $rd close | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Chained replication (subreplica -> replica -> primary). | ||
| # Verifies the replica forwards the exact byte stream to its own replicas. | ||
| start_server {tags {"repl external:skip"}} { | ||
| start_server {} { | ||
| start_server {} { | ||
| set primary [srv -2 client] | ||
| set primary_host [srv -2 host] | ||
| set primary_port [srv -2 port] | ||
| set replica [srv -1 client] | ||
| set replica_host [srv -1 host] | ||
| set replica_port [srv -1 port] | ||
| set subreplica [srv 0 client] | ||
|
|
||
| $replica replicaof $primary_host $primary_port | ||
| $subreplica replicaof $replica_host $replica_port | ||
| wait_for_sync $replica | ||
| wait_for_sync $subreplica | ||
| wait_for_ofs_sync $primary $replica | ||
| wait_for_ofs_sync $replica $subreplica | ||
|
|
||
| test {Chained replication: pipelined SETs converge on all 3 nodes} { | ||
| set rd [valkey_deferring_client -2] | ||
| for {set i 0} {$i < 500} {incr i} { | ||
| $rd set key1 value1 | ||
| $rd set key2 value2 | ||
| } | ||
| for {set i 0} {$i < 1000} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| assert_primary_replica_consistent $replica $subreplica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Chained replication: MULTI/EXEC propagates correctly} { | ||
| set rd [valkey_deferring_client -2] | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd multi | ||
| $rd set key1 value1 | ||
| $rd set key2 value2 | ||
| $rd set key3 value3 | ||
| $rd exec | ||
| } | ||
| for {set i 0} {$i < 1000} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| assert_primary_replica_consistent $replica $subreplica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Chained replication: PROTO_MBULK_BIG_ARG in pipeline} { | ||
| set rd [valkey_deferring_client -2] | ||
| set big_string [string repeat X 100000] | ||
| for {set i 0} {$i < 50} {incr i} { | ||
| $rd set key1 $big_string | ||
| $rd set key2 $big_string | ||
| } | ||
| for {set i 0} {$i < 100} {incr i} { | ||
| $rd read | ||
| } | ||
| assert_primary_replica_consistent $primary $replica | ||
| assert_primary_replica_consistent $replica $subreplica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Chained replication: pipeline survives PSYNC reconnect} { | ||
| set rd [valkey_deferring_client -2] | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set kx$i vx$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| # Force replica to drop the primary connection. | ||
| $replica client kill type primary | ||
| wait_for_sync $replica | ||
|
|
||
| # Push another batch of pipelined writes after the reconnect. | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set ky$i vy$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| assert_primary_replica_consistent $primary $replica | ||
| assert_primary_replica_consistent $replica $subreplica | ||
| $rd close | ||
| } | ||
|
|
||
| test {Chained replication: pipeline survives subreplica<-replica reconnect} { | ||
| set rd [valkey_deferring_client -2] | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set kp$i vp$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| # Force replica to drop the primary connection. | ||
| $subreplica client kill type primary | ||
|
enjoy-binbin marked this conversation as resolved.
|
||
| wait_for_sync $subreplica | ||
|
|
||
| # Push another batch of pipelined writes after the reconnect. | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd set kq$i vq$i | ||
| } | ||
| for {set i 0} {$i < 200} {incr i} { | ||
| $rd read | ||
| } | ||
|
|
||
| assert_primary_replica_consistent $primary $replica | ||
| assert_primary_replica_consistent $replica $subreplica | ||
| $rd close | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.