2
0

replication-psync.tcl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # Creates a master-slave pair and breaks the link continuously to force
  9. # partial resyncs attempts, all this while flooding the master with
  10. # write queries.
  11. #
  12. # You can specifiy backlog size, ttl, delay before reconnection, test duration
  13. # in seconds, and an additional condition to verify at the end.
  14. proc test_psync {descr duration backlog_size backlog_ttl delay cond} {
  15. start_server {tags {"repl"}} {
  16. start_server {} {
  17. set master [srv -1 client]
  18. set master_host [srv -1 host]
  19. set master_port [srv -1 port]
  20. set slave [srv 0 client]
  21. $master config set repl-backlog-size $backlog_size
  22. $master config set repl-backlog-ttl $backlog_ttl
  23. set load_handle0 [start_bg_complex_data $master_host $master_port 9 100000]
  24. set load_handle1 [start_bg_complex_data $master_host $master_port 11 100000]
  25. set load_handle2 [start_bg_complex_data $master_host $master_port 12 100000]
  26. test {First server should have role slave after SLAVEOF} {
  27. $slave slaveof $master_host $master_port
  28. wait_for_condition 50 100 {
  29. [s 0 role] eq {slave}
  30. } else {
  31. fail "Replication not started."
  32. }
  33. }
  34. test "Test replication partial resync: $descr" {
  35. # Now while the clients are writing data, break the maste-slave
  36. # link multiple times.
  37. for {set j 0} {$j < $duration*10} {incr j} {
  38. after 100
  39. # catch {puts "MASTER [$master dbsize] keys, SLAVE [$slave dbsize] keys"}
  40. if {($j % 20) == 0} {
  41. catch {
  42. if {$delay} {
  43. $slave multi
  44. $slave client kill $master_host:$master_port
  45. $slave debug sleep $delay
  46. $slave exec
  47. } else {
  48. $slave client kill $master_host:$master_port
  49. }
  50. }
  51. }
  52. }
  53. stop_bg_complex_data $load_handle0
  54. stop_bg_complex_data $load_handle1
  55. stop_bg_complex_data $load_handle2
  56. set retry 10
  57. while {$retry && ([$master debug digest] ne [$slave debug digest])}\
  58. {
  59. after 1000
  60. incr retry -1
  61. }
  62. assert {[$master dbsize] > 0}
  63. if {[$master debug digest] ne [$slave debug digest]} {
  64. set csv1 [csvdump r]
  65. set csv2 [csvdump {r -1}]
  66. set fd [open /tmp/repldump1.txt w]
  67. puts -nonewline $fd $csv1
  68. close $fd
  69. set fd [open /tmp/repldump2.txt w]
  70. puts -nonewline $fd $csv2
  71. close $fd
  72. puts "Master - Slave inconsistency"
  73. puts "Run diff -u against /tmp/repldump*.txt for more info"
  74. }
  75. assert_equal [r debug digest] [r -1 debug digest]
  76. eval $cond
  77. }
  78. }
  79. }
  80. }
  81. test_psync {ok psync} 6 1000000 3600 0 {
  82. assert {[s -1 sync_partial_ok] > 0}
  83. }
  84. test_psync {no backlog} 6 100 3600 0 {
  85. assert {[s -1 sync_partial_err] > 0}
  86. }
  87. test_psync {ok after delay} 3 100000000 3600 3 {
  88. assert {[s -1 sync_partial_ok] > 0}
  89. }
  90. test_psync {backlog expired} 3 100000000 1 3 {
  91. assert {[s -1 sync_partial_err] > 0}
  92. }