2
0

replication-3.tcl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 - Slave 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. }
  32. }
  33. start_server {tags {"repl"}} {
  34. start_server {} {
  35. test {First server should have role slave after SLAVEOF} {
  36. r -1 slaveof [srv 0 host] [srv 0 port]
  37. wait_for_condition 50 100 {
  38. [s -1 master_link_status] eq {up}
  39. } else {
  40. fail "Replication not started."
  41. }
  42. }
  43. set numops 20000 ;# Enough to trigger the Script Cache LRU eviction.
  44. # While we are at it, enable AOF to test it will be consistent as well
  45. # after the test.
  46. r config set appendonly yes
  47. test {MASTER and SLAVE consistency with EVALSHA replication} {
  48. array set oldsha {}
  49. for {set j 0} {$j < $numops} {incr j} {
  50. set key "key:$j"
  51. # Make sure to create scripts that have different SHA1s
  52. set script "return redis.call('incr','$key')"
  53. set sha1 [r eval "return redis.sha1hex(\"$script\")" 0]
  54. set oldsha($j) $sha1
  55. r eval $script 0
  56. set res [r evalsha $sha1 0]
  57. assert {$res == 2}
  58. # Additionally call one of the old scripts as well, at random.
  59. set res [r evalsha $oldsha([randomInt $j]) 0]
  60. assert {$res > 2}
  61. # Trigger an AOF rewrite while we are half-way, this also
  62. # forces the flush of the script cache, and we will cover
  63. # more code as a result.
  64. if {$j == $numops / 2} {
  65. catch {r bgrewriteaof}
  66. }
  67. }
  68. wait_for_condition 50 100 {
  69. [r dbsize] == $numops &&
  70. [r -1 dbsize] == $numops &&
  71. [r debug digest] eq [r -1 debug digest]
  72. } else {
  73. set csv1 [csvdump r]
  74. set csv2 [csvdump {r -1}]
  75. set fd [open /tmp/repldump1.txt w]
  76. puts -nonewline $fd $csv1
  77. close $fd
  78. set fd [open /tmp/repldump2.txt w]
  79. puts -nonewline $fd $csv2
  80. close $fd
  81. puts "Master - Slave inconsistency"
  82. puts "Run diff -u against /tmp/repldump*.txt for more info"
  83. }
  84. set old_digest [r debug digest]
  85. r config set appendonly no
  86. r debug loadaof
  87. set new_digest [r debug digest]
  88. assert {$old_digest eq $new_digest}
  89. }
  90. }
  91. }