2
0

replication-4.tcl 4.5 KB

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