2
0

replication-2.tcl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. start_server {tags {"repl"}} {
  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 slave"
  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 slave"
  35. }
  36. }
  37. test {No write if min-slaves-max-lag is > of the slave lag} {
  38. r -1 deferred 1
  39. r config set min-slaves-to-write 1
  40. r config set min-slaves-max-lag 2
  41. r -1 debug sleep 6
  42. assert {[r set foo 12345] eq {OK}}
  43. after 4000
  44. catch {r set foo 12345} err
  45. assert {[r -1 read] eq {OK}}
  46. r -1 deferred 0
  47. set err
  48. } {NOREPLICAS*}
  49. test {min-slaves-to-write is ignored by slaves} {
  50. r config set min-slaves-to-write 1
  51. r config set min-slaves-max-lag 10
  52. r -1 config set min-slaves-to-write 1
  53. r -1 config set min-slaves-max-lag 10
  54. r set foo aaabbb
  55. wait_for_condition 50 100 {
  56. [r -1 get foo] eq {aaabbb}
  57. } else {
  58. fail "Write did not reached slave"
  59. }
  60. }
  61. # Fix parameters for the next test to work
  62. r config set min-slaves-to-write 0
  63. r -1 config set min-slaves-to-write 0
  64. r flushall
  65. test {MASTER and SLAVE dataset should be identical after complex ops} {
  66. createComplexDataset r 10000
  67. after 500
  68. if {[r debug digest] ne [r -1 debug digest]} {
  69. set csv1 [csvdump r]
  70. set csv2 [csvdump {r -1}]
  71. set fd [open /tmp/repldump1.txt w]
  72. puts -nonewline $fd $csv1
  73. close $fd
  74. set fd [open /tmp/repldump2.txt w]
  75. puts -nonewline $fd $csv2
  76. close $fd
  77. puts "Master - Slave inconsistency"
  78. puts "Run diff -u against /tmp/repldump*.txt for more info"
  79. }
  80. assert_equal [r debug digest] [r -1 debug digest]
  81. }
  82. }
  83. }