1start_server {tags {"repl"}} { 2 start_server {} { 3 test {First server should have role slave after SLAVEOF} { 4 r -1 slaveof [srv 0 host] [srv 0 port] 5 wait_for_condition 50 100 { 6 [s -1 master_link_status] eq {up} 7 } else { 8 fail "Replication not started." 9 } 10 } 11 12 if {$::accurate} {set numops 50000} else {set numops 5000} 13 14 test {MASTER and SLAVE consistency with expire} { 15 createComplexDataset r $numops useexpire 16 after 4000 ;# Make sure everything expired before taking the digest 17 r keys * ;# Force DEL syntesizing to slave 18 after 1000 ;# Wait another second. Now everything should be fine. 19 if {[r debug digest] ne [r -1 debug digest]} { 20 set csv1 [csvdump r] 21 set csv2 [csvdump {r -1}] 22 set fd [open /tmp/repldump1.txt w] 23 puts -nonewline $fd $csv1 24 close $fd 25 set fd [open /tmp/repldump2.txt w] 26 puts -nonewline $fd $csv2 27 close $fd 28 puts "Master - Replica inconsistency" 29 puts "Run diff -u against /tmp/repldump*.txt for more info" 30 } 31 assert_equal [r debug digest] [r -1 debug digest] 32 } 33 34 test {Slave is able to evict keys created in writable slaves} { 35 r -1 select 5 36 assert {[r -1 dbsize] == 0} 37 r -1 config set slave-read-only no 38 r -1 set key1 1 ex 5 39 r -1 set key2 2 ex 5 40 r -1 set key3 3 ex 5 41 assert {[r -1 dbsize] == 3} 42 after 6000 43 r -1 dbsize 44 } {0} 45 } 46} 47 48start_server {tags {"repl"}} { 49 start_server {} { 50 test {First server should have role slave after SLAVEOF} { 51 r -1 slaveof [srv 0 host] [srv 0 port] 52 wait_for_condition 50 100 { 53 [s -1 master_link_status] eq {up} 54 } else { 55 fail "Replication not started." 56 } 57 } 58 59 set numops 20000 ;# Enough to trigger the Script Cache LRU eviction. 60 61 # While we are at it, enable AOF to test it will be consistent as well 62 # after the test. 63 r config set appendonly yes 64 65 test {MASTER and SLAVE consistency with EVALSHA replication} { 66 array set oldsha {} 67 for {set j 0} {$j < $numops} {incr j} { 68 set key "key:$j" 69 # Make sure to create scripts that have different SHA1s 70 set script "return redis.call('incr','$key')" 71 set sha1 [r eval "return redis.sha1hex(\"$script\")" 0] 72 set oldsha($j) $sha1 73 r eval $script 0 74 set res [r evalsha $sha1 0] 75 assert {$res == 2} 76 # Additionally call one of the old scripts as well, at random. 77 set res [r evalsha $oldsha([randomInt $j]) 0] 78 assert {$res > 2} 79 80 # Trigger an AOF rewrite while we are half-way, this also 81 # forces the flush of the script cache, and we will cover 82 # more code as a result. 83 if {$j == $numops / 2} { 84 catch {r bgrewriteaof} 85 } 86 } 87 88 wait_for_condition 50 100 { 89 [r dbsize] == $numops && 90 [r -1 dbsize] == $numops && 91 [r debug digest] eq [r -1 debug digest] 92 } else { 93 set csv1 [csvdump r] 94 set csv2 [csvdump {r -1}] 95 set fd [open /tmp/repldump1.txt w] 96 puts -nonewline $fd $csv1 97 close $fd 98 set fd [open /tmp/repldump2.txt w] 99 puts -nonewline $fd $csv2 100 close $fd 101 puts "Master - Replica inconsistency" 102 puts "Run diff -u against /tmp/repldump*.txt for more info" 103 } 104 105 set old_digest [r debug digest] 106 r config set appendonly no 107 r debug loadaof 108 set new_digest [r debug digest] 109 assert {$old_digest eq $new_digest} 110 } 111 112 test {SLAVE can reload "lua" AUX RDB fields of duplicated scripts} { 113 # Force a Slave full resynchronization 114 r debug change-repl-id 115 r -1 client kill type master 116 117 # Check that after a full resync the slave can still load 118 # correctly the RDB file: such file will contain "lua" AUX 119 # sections with scripts already in the memory of the master. 120 121 wait_for_condition 50 100 { 122 [s -1 master_link_status] eq {up} 123 } else { 124 fail "Replication not started." 125 } 126 127 wait_for_condition 50 100 { 128 [r debug digest] eq [r -1 debug digest] 129 } else { 130 fail "DEBUG DIGEST mismatch after full SYNC with many scripts" 131 } 132 } 133 } 134} 135