2
0

replication-psync.tcl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # Creates a master-slave pair and breaks the link continuously to force
  2. # partial resyncs attempts, all this while flooding the master with
  3. # write queries.
  4. #
  5. # You can specify backlog size, ttl, delay before reconnection, test duration
  6. # in seconds, and an additional condition to verify at the end.
  7. #
  8. # If reconnect is > 0, the test actually try to break the connection and
  9. # reconnect with the master, otherwise just the initial synchronization is
  10. # checked for consistency.
  11. proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reconnect} {
  12. start_server {tags {"repl"}} {
  13. start_server {} {
  14. set master [srv -1 client]
  15. set master_host [srv -1 host]
  16. set master_port [srv -1 port]
  17. set slave [srv 0 client]
  18. $master config set repl-backlog-size $backlog_size
  19. $master config set repl-backlog-ttl $backlog_ttl
  20. $master config set repl-diskless-sync $mdl
  21. $master config set repl-diskless-sync-delay 1
  22. $slave config set repl-diskless-load $sdl
  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 {Slave should be able to synchronize with the master} {
  27. $slave slaveof $master_host $master_port
  28. wait_for_condition 50 100 {
  29. [lindex [r role] 0] eq {slave} &&
  30. [lindex [r role] 3] eq {connected}
  31. } else {
  32. fail "Replication not started."
  33. }
  34. }
  35. # Check that the background clients are actually writing.
  36. test {Detect write load to master} {
  37. wait_for_condition 50 1000 {
  38. [$master dbsize] > 100
  39. } else {
  40. fail "Can't detect write load from background clients."
  41. }
  42. }
  43. test "Test replication partial resync: $descr (diskless: $mdl, $sdl, reconnect: $reconnect)" {
  44. # Now while the clients are writing data, break the maste-slave
  45. # link multiple times.
  46. if ($reconnect) {
  47. for {set j 0} {$j < $duration*10} {incr j} {
  48. after 100
  49. # catch {puts "MASTER [$master dbsize] keys, REPLICA [$slave dbsize] keys"}
  50. if {($j % 20) == 0} {
  51. catch {
  52. if {$delay} {
  53. $slave multi
  54. $slave client kill $master_host:$master_port
  55. $slave debug sleep $delay
  56. $slave exec
  57. } else {
  58. $slave client kill $master_host:$master_port
  59. }
  60. }
  61. }
  62. }
  63. }
  64. stop_bg_complex_data $load_handle0
  65. stop_bg_complex_data $load_handle1
  66. stop_bg_complex_data $load_handle2
  67. # Wait for the slave to reach the "online"
  68. # state from the POV of the master.
  69. set retry 5000
  70. while {$retry} {
  71. set info [$master info]
  72. if {[string match {*slave0:*state=online*} $info]} {
  73. break
  74. } else {
  75. incr retry -1
  76. after 100
  77. }
  78. }
  79. if {$retry == 0} {
  80. error "assertion:Slave not correctly synchronized"
  81. }
  82. # Wait that slave acknowledge it is online so
  83. # we are sure that DBSIZE and DEBUG DIGEST will not
  84. # fail because of timing issues. (-LOADING error)
  85. wait_for_condition 5000 100 {
  86. [lindex [$slave role] 3] eq {connected}
  87. } else {
  88. fail "Slave still not connected after some time"
  89. }
  90. wait_for_condition 100 100 {
  91. [$master debug digest] == [$slave debug digest]
  92. } else {
  93. set csv1 [csvdump r]
  94. set csv2 [csvdump {r -1}]
  95. set fd [open /tmp/repldump1.txt w]
  96. puts -nonewline $fd $csv1
  97. close $fd
  98. set fd [open /tmp/repldump2.txt w]
  99. puts -nonewline $fd $csv2
  100. close $fd
  101. fail "Master - Replica inconsistency, Run diff -u against /tmp/repldump*.txt for more info"
  102. }
  103. assert {[$master dbsize] > 0}
  104. eval $cond
  105. }
  106. }
  107. }
  108. }
  109. tags {"external:skip"} {
  110. foreach mdl {no yes} {
  111. foreach sdl {disabled swapdb} {
  112. test_psync {no reconnection, just sync} 6 1000000 3600 0 {
  113. } $mdl $sdl 0
  114. test_psync {ok psync} 6 100000000 3600 0 {
  115. assert {[s -1 sync_partial_ok] > 0}
  116. } $mdl $sdl 1
  117. test_psync {no backlog} 6 100 3600 0.5 {
  118. assert {[s -1 sync_partial_err] > 0}
  119. } $mdl $sdl 1
  120. test_psync {ok after delay} 3 100000000 3600 3 {
  121. assert {[s -1 sync_partial_ok] > 0}
  122. } $mdl $sdl 1
  123. test_psync {backlog expired} 3 100000000 1 3 {
  124. assert {[s -1 sync_partial_err] > 0}
  125. } $mdl $sdl 1
  126. }
  127. }
  128. }