replication-2.tcl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. test {If min-slaves-to-write is honored, write is accepted} {
  12. r config set min-slaves-to-write 1
  13. r config set min-slaves-max-lag 10
  14. r set foo 12345
  15. wait_for_condition 50 100 {
  16. [r -1 get foo] eq {12345}
  17. } else {
  18. fail "Write did not reached replica"
  19. }
  20. }
  21. test {No write if min-slaves-to-write is < attached slaves} {
  22. r config set min-slaves-to-write 2
  23. r config set min-slaves-max-lag 10
  24. catch {r set foo 12345} err
  25. set err
  26. } {NOREPLICAS*}
  27. test {If min-slaves-to-write is honored, write is accepted (again)} {
  28. r config set min-slaves-to-write 1
  29. r config set min-slaves-max-lag 10
  30. r set foo 12345
  31. wait_for_condition 50 100 {
  32. [r -1 get foo] eq {12345}
  33. } else {
  34. fail "Write did not reached replica"
  35. }
  36. }
  37. test {No write if min-slaves-max-lag is > of the slave lag} {
  38. r config set min-slaves-to-write 1
  39. r config set min-slaves-max-lag 2
  40. exec kill -SIGSTOP [srv -1 pid]
  41. assert {[r set foo 12345] eq {OK}}
  42. wait_for_condition 100 100 {
  43. [catch {r set foo 12345}] != 0
  44. } else {
  45. fail "Master didn't become readonly"
  46. }
  47. catch {r set foo 12345} err
  48. assert_match {NOREPLICAS*} $err
  49. }
  50. exec kill -SIGCONT [srv -1 pid]
  51. test {min-slaves-to-write is ignored by slaves} {
  52. r config set min-slaves-to-write 1
  53. r config set min-slaves-max-lag 10
  54. r -1 config set min-slaves-to-write 1
  55. r -1 config set min-slaves-max-lag 10
  56. r set foo aaabbb
  57. wait_for_condition 50 100 {
  58. [r -1 get foo] eq {aaabbb}
  59. } else {
  60. fail "Write did not reached replica"
  61. }
  62. }
  63. # Fix parameters for the next test to work
  64. r config set min-slaves-to-write 0
  65. r -1 config set min-slaves-to-write 0
  66. r flushall
  67. test {MASTER and SLAVE dataset should be identical after complex ops} {
  68. createComplexDataset r 10000
  69. after 500
  70. if {[r debug digest] ne [r -1 debug digest]} {
  71. set csv1 [csvdump r]
  72. set csv2 [csvdump {r -1}]
  73. set fd [open /tmp/repldump1.txt w]
  74. puts -nonewline $fd $csv1
  75. close $fd
  76. set fd [open /tmp/repldump2.txt w]
  77. puts -nonewline $fd $csv2
  78. close $fd
  79. puts "Master - Replica inconsistency"
  80. puts "Run diff -u against /tmp/repldump*.txt for more info"
  81. }
  82. assert_equal [r debug digest] [r -1 debug digest]
  83. }
  84. }
  85. }