replication-3.tcl 4.9 KB

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