mirror of
https://github.com/hanzoai/kv.git
synced 2026-11-09 16:05:35 +00:00
Provide an RDB snapshot that the replica can handle, for resilience during rolling upgrades. This permits an older replica to do a full sync from a newer primary. The primary takes the replica's announced version into account when generating the snapshot. In particular, it allows latest Valkey to send snapshots as RDB 11 to replicas running Valkey 7.2 and 8.x. The implementation is structurally similar to how filtered snapshots with REPLCONF RDB-FILTER-ONLY works (commitse1e12c1f1c,2b4727e58b) and to the feature negotiation that replicas initiate using REPLCONF CAPA. If any new features that the replica can't handle (such as hash-field expiration and atomic slot migration) are in use, the full sync is aborted and the replica connection is closed. This mechanism will allow us to do RDB changes more often. In the recent years, we have been avoiding RDB changes. With this mechanism, there is no need to avoid introducing RDB changes such as new encodings and new compression algorithms (#1962). In my experience, providing a way to undo an upgrade makes users less worried and actually more willing to upgrade. This is true not least when Valkey is a part of a larger system which is upgraded as a whole. Valkey may be just one microservice of many within a larger system; not uncommon in on-prem deployments. If anything goes wrong (even if it's not Valkey itself) the user wants a way to roll back the whole system to the last working state. --------- Signed-off-by: Viktor Söderqvist <[email protected]>
91 lines
3.8 KiB
Tcl
91 lines
3.8 KiB
Tcl
# Test replication from an older version primary.
|
|
#
|
|
# Use minimal.conf to make sure we don't use any configs not supported on the old version.
|
|
start_server {tags {"repl needs:other-server external:skip compatible-redis"} start-other-server 1 config "minimal.conf"} {
|
|
set hello [r hello]
|
|
set primary_name_and_version "[dict get $hello server] [dict get $hello version]"
|
|
r set foo bar
|
|
|
|
start_server {} {
|
|
test "Start replication from $primary_name_and_version" {
|
|
r replicaof [srv -1 host] [srv -1 port]
|
|
wait_for_sync r 500 100
|
|
# The key has been transferred.
|
|
assert_equal bar [r get foo]
|
|
assert_equal up [s master_link_status]
|
|
}
|
|
|
|
test "Replicate a SET command from $primary_name_and_version" {
|
|
r -1 set baz quux
|
|
wait_for_ofs_sync [srv 0 client] [srv -1 client]
|
|
set reply [r get baz]
|
|
assert_equal $reply quux
|
|
}
|
|
}
|
|
}
|
|
|
|
# Test replication from the current version to an older version replica.
|
|
start_server {tags {"repl needs:other-server external:skip"}} {
|
|
set primary [srv 0 client]
|
|
set primary_host [srv 0 host]
|
|
set primary_port [srv 0 port]
|
|
$primary config set repl-diskless-sync yes
|
|
$primary config set repl-diskless-sync-delay 1
|
|
|
|
# As a side-effect, this first start_server block initializes old_replica_version which
|
|
# is used in the tests below.
|
|
start_server {start-other-server 1 config "minimal.conf"} {
|
|
set hello [r hello]
|
|
set old_replica_version [dict get $hello version]
|
|
# set replica_name_and_version "[dict get $hello server] $replica_version"
|
|
set old_replica [srv 0 client]
|
|
start_server {} {
|
|
set new_replica [srv 0 client]
|
|
test {Keys can be sync'ed by old and new replicas} {
|
|
$primary set foo bar
|
|
$old_replica replicaof $primary_host $primary_port
|
|
$new_replica replicaof $primary_host $primary_port
|
|
wait_for_sync $old_replica 500 100
|
|
wait_for_sync $new_replica 500 100
|
|
assert_equal bar [$old_replica get foo]
|
|
assert_equal bar [$new_replica get foo]
|
|
}
|
|
}
|
|
}
|
|
|
|
test "Old pre-HFE replica can't sync but doesn't prevent new replica from sync" {
|
|
if {[version_greater_or_equal $old_replica_version 9.0.0]} {
|
|
skip "Replica $old_replica_version does support HFE"
|
|
}
|
|
r flushall
|
|
r hsetex hfe ex 1000 fields 1 field1 value1
|
|
start_server {start-other-server 1 config "minimal.conf"} {
|
|
set old_replica [srv 0 client]
|
|
start_server {} {
|
|
set new_replica [srv 0 client]
|
|
$old_replica replicaof $primary_host $primary_port
|
|
$new_replica replicaof $primary_host $primary_port
|
|
wait_for_sync $new_replica 500 100
|
|
wait_for_log_messages -2 [list {*Can't store key 'hfe'*}] 0 50 100
|
|
assert_equal value1 [$new_replica hget hfe field1]
|
|
assert_match {*master_link_status:up*} [$new_replica info replication]
|
|
assert_match {*master_link_status:down*} [$old_replica info replication]
|
|
}
|
|
}
|
|
}
|
|
|
|
test "Replica with HFE support can full sync" {
|
|
if {![version_greater_or_equal $old_replica_version 9.0.0]} {
|
|
skip "Replica $old_replica_version doesn't support HFE"
|
|
}
|
|
r flushall
|
|
r hsetex hfe ex 1000 fields 1 field1 value1
|
|
start_server {start-other-server 1 config "minimal.conf"} {
|
|
set old_replica [srv 0 client]
|
|
$old_replica replicaof $primary_host $primary_port
|
|
wait_for_sync $old_replica 500 100
|
|
assert_equal value1 [$old_replica hget hfe field1]
|
|
}
|
|
}
|
|
}
|