1
0

replication-4.tcl 4.9 KB

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