aofrw.tcl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. start_server {tags {"aofrw"}} {
  2. # Enable the AOF
  3. r config set appendonly yes
  4. r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
  5. waitForBgrewriteaof r
  6. foreach rdbpre {yes no} {
  7. r config set aof-use-rdb-preamble $rdbpre
  8. test "AOF rewrite during write load: RDB preamble=$rdbpre" {
  9. # Start a write load for 10 seconds
  10. set master [srv 0 client]
  11. set master_host [srv 0 host]
  12. set master_port [srv 0 port]
  13. set load_handle0 [start_write_load $master_host $master_port 10]
  14. set load_handle1 [start_write_load $master_host $master_port 10]
  15. set load_handle2 [start_write_load $master_host $master_port 10]
  16. set load_handle3 [start_write_load $master_host $master_port 10]
  17. set load_handle4 [start_write_load $master_host $master_port 10]
  18. # Make sure the instance is really receiving data
  19. wait_for_condition 50 100 {
  20. [r dbsize] > 0
  21. } else {
  22. fail "No write load detected."
  23. }
  24. # After 3 seconds, start a rewrite, while the write load is still
  25. # active.
  26. after 3000
  27. r bgrewriteaof
  28. waitForBgrewriteaof r
  29. # Let it run a bit more so that we'll append some data to the new
  30. # AOF.
  31. after 1000
  32. # Stop the processes generating the load if they are still active
  33. stop_write_load $load_handle0
  34. stop_write_load $load_handle1
  35. stop_write_load $load_handle2
  36. stop_write_load $load_handle3
  37. stop_write_load $load_handle4
  38. # Make sure that we remain the only connected client.
  39. # This step is needed to make sure there are no pending writes
  40. # that will be processed between the two "debug digest" calls.
  41. wait_for_condition 50 100 {
  42. [llength [split [string trim [r client list]] "\n"]] == 1
  43. } else {
  44. puts [r client list]
  45. fail "Clients generating loads are not disconnecting"
  46. }
  47. # Get the data set digest
  48. set d1 [r debug digest]
  49. # Load the AOF
  50. r debug loadaof
  51. set d2 [r debug digest]
  52. # Make sure they are the same
  53. assert {$d1 eq $d2}
  54. }
  55. }
  56. }
  57. start_server {tags {"aofrw"}} {
  58. test {Turning off AOF kills the background writing child if any} {
  59. r config set appendonly yes
  60. waitForBgrewriteaof r
  61. r multi
  62. r bgrewriteaof
  63. r config set appendonly no
  64. r exec
  65. wait_for_condition 50 100 {
  66. [string match {*Killing*AOF*child*} [exec tail -5 < [srv 0 stdout]]]
  67. } else {
  68. fail "Can't find 'Killing AOF child' into recent logs"
  69. }
  70. }
  71. foreach d {string int} {
  72. foreach e {quicklist} {
  73. test "AOF rewrite of list with $e encoding, $d data" {
  74. r flushall
  75. set len 1000
  76. for {set j 0} {$j < $len} {incr j} {
  77. if {$d eq {string}} {
  78. set data [randstring 0 16 alpha]
  79. } else {
  80. set data [randomInt 4000000000]
  81. }
  82. r lpush key $data
  83. }
  84. assert_equal [r object encoding key] $e
  85. set d1 [r debug digest]
  86. r bgrewriteaof
  87. waitForBgrewriteaof r
  88. r debug loadaof
  89. set d2 [r debug digest]
  90. if {$d1 ne $d2} {
  91. error "assertion:$d1 is not equal to $d2"
  92. }
  93. }
  94. }
  95. }
  96. foreach d {string int} {
  97. foreach e {intset hashtable} {
  98. test "AOF rewrite of set with $e encoding, $d data" {
  99. r flushall
  100. if {$e eq {intset}} {set len 10} else {set len 1000}
  101. for {set j 0} {$j < $len} {incr j} {
  102. if {$d eq {string}} {
  103. set data [randstring 0 16 alpha]
  104. } else {
  105. set data [randomInt 4000000000]
  106. }
  107. r sadd key $data
  108. }
  109. if {$d ne {string}} {
  110. assert_equal [r object encoding key] $e
  111. }
  112. set d1 [r debug digest]
  113. r bgrewriteaof
  114. waitForBgrewriteaof r
  115. r debug loadaof
  116. set d2 [r debug digest]
  117. if {$d1 ne $d2} {
  118. error "assertion:$d1 is not equal to $d2"
  119. }
  120. }
  121. }
  122. }
  123. foreach d {string int} {
  124. foreach e {ziplist hashtable} {
  125. test "AOF rewrite of hash with $e encoding, $d data" {
  126. r flushall
  127. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  128. for {set j 0} {$j < $len} {incr j} {
  129. if {$d eq {string}} {
  130. set data [randstring 0 16 alpha]
  131. } else {
  132. set data [randomInt 4000000000]
  133. }
  134. r hset key $data $data
  135. }
  136. assert_equal [r object encoding key] $e
  137. set d1 [r debug digest]
  138. r bgrewriteaof
  139. waitForBgrewriteaof r
  140. r debug loadaof
  141. set d2 [r debug digest]
  142. if {$d1 ne $d2} {
  143. error "assertion:$d1 is not equal to $d2"
  144. }
  145. }
  146. }
  147. }
  148. foreach d {string int} {
  149. foreach e {ziplist skiplist} {
  150. test "AOF rewrite of zset with $e encoding, $d data" {
  151. r flushall
  152. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  153. for {set j 0} {$j < $len} {incr j} {
  154. if {$d eq {string}} {
  155. set data [randstring 0 16 alpha]
  156. } else {
  157. set data [randomInt 4000000000]
  158. }
  159. r zadd key [expr rand()] $data
  160. }
  161. assert_equal [r object encoding key] $e
  162. set d1 [r debug digest]
  163. r bgrewriteaof
  164. waitForBgrewriteaof r
  165. r debug loadaof
  166. set d2 [r debug digest]
  167. if {$d1 ne $d2} {
  168. error "assertion:$d1 is not equal to $d2"
  169. }
  170. }
  171. }
  172. }
  173. test {BGREWRITEAOF is delayed if BGSAVE is in progress} {
  174. r multi
  175. r bgsave
  176. r bgrewriteaof
  177. r info persistence
  178. set res [r exec]
  179. assert_match {*scheduled*} [lindex $res 1]
  180. assert_match {*aof_rewrite_scheduled:1*} [lindex $res 2]
  181. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  182. after 100
  183. }
  184. }
  185. test {BGREWRITEAOF is refused if already in progress} {
  186. catch {
  187. r multi
  188. r bgrewriteaof
  189. r bgrewriteaof
  190. r exec
  191. } e
  192. assert_match {*ERR*already*} $e
  193. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  194. after 100
  195. }
  196. }
  197. }