2
0

replication-3.tcl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. start_server {tags {"repl external:skip"}} {
  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 {Master can replicate command longer than client-query-buffer-limit on replica} {
  32. # Configure the master to have a bigger query buffer limit
  33. r config set client-query-buffer-limit 2000000
  34. r -1 config set client-query-buffer-limit 1048576
  35. # Write a very large command onto the master
  36. r set key [string repeat "x" 1100000]
  37. wait_for_condition 300 100 {
  38. [r -1 get key] eq [string repeat "x" 1100000]
  39. } else {
  40. fail "Unable to replicate command longer than client-query-buffer-limit"
  41. }
  42. }
  43. test {Slave is able to evict keys created in writable slaves} {
  44. r -1 select 5
  45. assert {[r -1 dbsize] == 0}
  46. r -1 config set slave-read-only no
  47. r -1 set key1 1 ex 5
  48. r -1 set key2 2 ex 5
  49. r -1 set key3 3 ex 5
  50. assert {[r -1 dbsize] == 3}
  51. after 6000
  52. r -1 dbsize
  53. } {0}
  54. }
  55. }
  56. start_server {tags {"repl external:skip"}} {
  57. start_server {} {
  58. test {First server should have role slave after SLAVEOF} {
  59. r -1 slaveof [srv 0 host] [srv 0 port]
  60. wait_for_condition 50 100 {
  61. [s -1 master_link_status] eq {up}
  62. } else {
  63. fail "Replication not started."
  64. }
  65. }
  66. set numops 20000 ;# Enough to trigger the Script Cache LRU eviction.
  67. # While we are at it, enable AOF to test it will be consistent as well
  68. # after the test.
  69. r config set appendonly yes
  70. test {MASTER and SLAVE consistency with EVALSHA replication} {
  71. array set oldsha {}
  72. for {set j 0} {$j < $numops} {incr j} {
  73. set key "key:$j"
  74. # Make sure to create scripts that have different SHA1s
  75. set script "return redis.call('incr','$key')"
  76. set sha1 [r eval "return redis.sha1hex(\"$script\")" 0]
  77. set oldsha($j) $sha1
  78. r eval $script 0
  79. set res [r evalsha $sha1 0]
  80. assert {$res == 2}
  81. # Additionally call one of the old scripts as well, at random.
  82. set res [r evalsha $oldsha([randomInt $j]) 0]
  83. assert {$res > 2}
  84. # Trigger an AOF rewrite while we are half-way, this also
  85. # forces the flush of the script cache, and we will cover
  86. # more code as a result.
  87. if {$j == $numops / 2} {
  88. catch {r bgrewriteaof}
  89. }
  90. }
  91. wait_for_condition 50 100 {
  92. [r dbsize] == $numops &&
  93. [r -1 dbsize] == $numops &&
  94. [r debug digest] eq [r -1 debug digest]
  95. } else {
  96. set csv1 [csvdump r]
  97. set csv2 [csvdump {r -1}]
  98. set fd [open /tmp/repldump1.txt w]
  99. puts -nonewline $fd $csv1
  100. close $fd
  101. set fd [open /tmp/repldump2.txt w]
  102. puts -nonewline $fd $csv2
  103. close $fd
  104. puts "Master - Replica inconsistency"
  105. puts "Run diff -u against /tmp/repldump*.txt for more info"
  106. }
  107. set old_digest [r debug digest]
  108. r config set appendonly no
  109. r debug loadaof
  110. set new_digest [r debug digest]
  111. assert {$old_digest eq $new_digest}
  112. }
  113. test {SLAVE can reload "lua" AUX RDB fields of duplicated scripts} {
  114. # Force a Slave full resynchronization
  115. r debug change-repl-id
  116. r -1 client kill type master
  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. wait_for_condition 1000 100 {
  121. [s -1 master_link_status] eq {up}
  122. } else {
  123. fail "Replication not started."
  124. }
  125. wait_for_condition 50 100 {
  126. [r debug digest] eq [r -1 debug digest]
  127. } else {
  128. fail "DEBUG DIGEST mismatch after full SYNC with many scripts"
  129. }
  130. }
  131. }
  132. }