replication-2.tcl 3.0 KB

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