summaryrefslogtreecommitdiffstats
path: root/tests/cluster/tests/17-diskless-load-swapdb.tcl
blob: 7a56ec783b167ab07fa762c352f65a767be9e895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Check that replica keys and keys to slots map are right after failing to diskless load using SWAPDB.

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 "Main db not affected 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 set appendonly no
    $replica config set save ""
    $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
    wait_for_ofs_sync $master $replica
    assert_equal {1} [$replica get $slot0_key]
    assert_equal $slot0_key [$replica CLUSTER GETKEYSINSLOT 0 1]

    # Save an RDB and kill the replica
    $replica save
    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 till after db started loading in background
    wait_for_condition 500 10 {
        [s $replica_id async_loading] eq 1
    } else {
        fail "Fail to full sync"
    }

    # Kill master, abort full sync
    kill_instance redis $master_id

    # Start full sync, wait till the replica detects the disconnection
    wait_for_condition 500 10 {
        [s $replica_id async_loading] eq 0
    } else {
        fail "Fail to full sync"
    }

    # 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]
}