2
0

replication-4.tcl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. start_server {tags {"repl"}} {
  2. start_server {} {
  3. set master [srv -1 client]
  4. set master_host [srv -1 host]
  5. set master_port [srv -1 port]
  6. set slave [srv 0 client]
  7. set load_handle0 [start_bg_complex_data $master_host $master_port 9 100000]
  8. set load_handle1 [start_bg_complex_data $master_host $master_port 11 100000]
  9. set load_handle2 [start_bg_complex_data $master_host $master_port 12 100000]
  10. test {First server should have role slave after SLAVEOF} {
  11. $slave slaveof $master_host $master_port
  12. after 1000
  13. s 0 role
  14. } {slave}
  15. test {Test replication with parallel clients writing in differnet DBs} {
  16. after 5000
  17. stop_bg_complex_data $load_handle0
  18. stop_bg_complex_data $load_handle1
  19. stop_bg_complex_data $load_handle2
  20. set retry 10
  21. while {$retry && ([$master debug digest] ne [$slave debug digest])}\
  22. {
  23. after 1000
  24. incr retry -1
  25. }
  26. assert {[$master dbsize] > 0}
  27. if {[$master debug digest] ne [$slave debug digest]} {
  28. set csv1 [csvdump r]
  29. set csv2 [csvdump {r -1}]
  30. set fd [open /tmp/repldump1.txt w]
  31. puts -nonewline $fd $csv1
  32. close $fd
  33. set fd [open /tmp/repldump2.txt w]
  34. puts -nonewline $fd $csv2
  35. close $fd
  36. puts "Master - Replica inconsistency"
  37. puts "Run diff -u against /tmp/repldump*.txt for more info"
  38. }
  39. assert_equal [r debug digest] [r -1 debug digest]
  40. }
  41. }
  42. }
  43. start_server {tags {"repl"}} {
  44. start_server {} {
  45. set master [srv -1 client]
  46. set master_host [srv -1 host]
  47. set master_port [srv -1 port]
  48. set slave [srv 0 client]
  49. test {First server should have role slave after SLAVEOF} {
  50. $slave slaveof $master_host $master_port
  51. wait_for_condition 50 100 {
  52. [s 0 master_link_status] eq {up}
  53. } else {
  54. fail "Replication not started."
  55. }
  56. }
  57. test {With min-slaves-to-write (1,3): master should be writable} {
  58. $master config set min-slaves-max-lag 3
  59. $master config set min-slaves-to-write 1
  60. $master set foo bar
  61. } {OK}
  62. test {With min-slaves-to-write (2,3): master should not be writable} {
  63. $master config set min-slaves-max-lag 3
  64. $master config set min-slaves-to-write 2
  65. catch {$master set foo bar} e
  66. set e
  67. } {NOREPLICAS*}
  68. test {With min-slaves-to-write: master not writable with lagged slave} {
  69. $master config set min-slaves-max-lag 2
  70. $master config set min-slaves-to-write 1
  71. assert {[$master set foo bar] eq {OK}}
  72. $slave deferred 1
  73. $slave debug sleep 6
  74. after 4000
  75. catch {$master set foo bar} e
  76. set e
  77. } {NOREPLICAS*}
  78. }
  79. }
  80. start_server {tags {"repl"}} {
  81. start_server {} {
  82. set master [srv -1 client]
  83. set master_host [srv -1 host]
  84. set master_port [srv -1 port]
  85. set slave [srv 0 client]
  86. test {First server should have role slave after SLAVEOF} {
  87. $slave slaveof $master_host $master_port
  88. wait_for_condition 50 100 {
  89. [s 0 role] eq {slave}
  90. } else {
  91. fail "Replication not started."
  92. }
  93. }
  94. test {Replication: commands with many arguments (issue #1221)} {
  95. # We now issue large MSET commands, that may trigger a specific
  96. # class of bugs, see issue #1221.
  97. for {set j 0} {$j < 100} {incr j} {
  98. set cmd [list mset]
  99. for {set x 0} {$x < 1000} {incr x} {
  100. lappend cmd [randomKey] [randomValue]
  101. }
  102. $master {*}$cmd
  103. }
  104. set retry 10
  105. while {$retry && ([$master debug digest] ne [$slave debug digest])}\
  106. {
  107. after 1000
  108. incr retry -1
  109. }
  110. assert {[$master dbsize] > 0}
  111. }
  112. test {Replication of SPOP command -- alsoPropagate() API} {
  113. $master del myset
  114. set size [expr 1+[randomInt 100]]
  115. set content {}
  116. for {set j 0} {$j < $size} {incr j} {
  117. lappend content [randomValue]
  118. }
  119. $master sadd myset {*}$content
  120. set count [randomInt 100]
  121. set result [$master spop myset $count]
  122. wait_for_condition 50 100 {
  123. [$master debug digest] eq [$slave debug digest]
  124. } else {
  125. fail "SPOP replication inconsistency"
  126. }
  127. }
  128. }
  129. }