futriix-old/tests/cluster/tests/17-diskless-load-swapdb.tcl
Wang Yuan f5d6057cbb Backup keys to slots map and restore when fail to sync if diskless-load type is swapdb in cluster mode (#8108)
When replica diskless-load type is swapdb in cluster mode, we didn't backup
keys to slots map, so we will lose keys to slots map if fail to sync.
Now we backup keys to slots map at first, and restore it properly when fail.

This commit includes a refactory/cleanup of the backups mechanism (moving it to db.c and re-structuring it a bit).

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 10712afaf3e7f2ea859622fa5b27c96ee8f478c5)
2021-01-12 16:25:37 +02:00

77 lines
2.1 KiB
Tcl

# Check replica can restore database buckup correctly if fail to diskless load.
source "../tests/includes/init-tests.tcl"
test "Create a primary with a replica" {
create_cluster 1 1
}
test "Cluster should start ok" {
assert_cluster_state ok
}
test "Cluster is writable" {
cluster_write_test 0
}
test "Right to restore backups when fail to diskless load " {
set master [Rn 0]
set replica [Rn 1]
set master_id 0
set replica_id 1
$replica READONLY
$replica config set repl-diskless-load swapdb
$replica config rewrite
$master config set repl-backlog-size 1024
$master config set repl-diskless-sync yes
$master config set repl-diskless-sync-delay 0
$master config set rdb-key-save-delay 10000
$master config set rdbcompression no
$master config set appendonly no
$master config set save ""
# Write a key that belongs to slot 0
set slot0_key "06S"
$master set $slot0_key 1
after 100
assert_equal {1} [$replica get $slot0_key]
assert_equal $slot0_key [$replica CLUSTER GETKEYSINSLOT 0 1]
# Kill the replica
kill_instance redis $replica_id
# Delete the key from master
$master del $slot0_key
# Replica must full sync with master when start because replication
# backlog size is very small, and dumping rdb will cost several seconds.
set num 10000
set value [string repeat A 1024]
set rd [redis_deferring_client redis $master_id]
for {set j 0} {$j < $num} {incr j} {
$rd set $j $value
}
for {set j 0} {$j < $num} {incr j} {
$rd read
}
# Start the replica again
restart_instance redis $replica_id
$replica READONLY
# Start full sync
wait_for_condition 500 10 {
[string match "*sync*" [$replica role]]
} else {
fail "Fail to full sync"
}
after 100
# Kill master, abort full sync
kill_instance redis $master_id
# Replica keys and keys to slots map still both are right
assert_equal {1} [$replica get $slot0_key]
assert_equal $slot0_key [$replica CLUSTER GETKEYSINSLOT 0 1]
}