aofrw.tcl 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. start_server {tags {"aofrw external:skip"}} {
  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 no more commands processed, before taking debug digest
  39. wait_load_handlers_disconnected
  40. # Get the data set digest
  41. set d1 [r debug digest]
  42. # Load the AOF
  43. r debug loadaof
  44. set d2 [r debug digest]
  45. # Make sure they are the same
  46. assert {$d1 eq $d2}
  47. }
  48. }
  49. }
  50. start_server {tags {"aofrw external:skip"} overrides {aof-use-rdb-preamble no}} {
  51. test {Turning off AOF kills the background writing child if any} {
  52. r config set appendonly yes
  53. waitForBgrewriteaof r
  54. r multi
  55. r bgrewriteaof
  56. r config set appendonly no
  57. r exec
  58. wait_for_condition 50 100 {
  59. [string match {*Killing*AOF*child*} [exec tail -5 < [srv 0 stdout]]]
  60. } else {
  61. fail "Can't find 'Killing AOF child' into recent logs"
  62. }
  63. }
  64. foreach d {string int} {
  65. foreach e {quicklist} {
  66. test "AOF rewrite of list with $e encoding, $d data" {
  67. r flushall
  68. set len 1000
  69. for {set j 0} {$j < $len} {incr j} {
  70. if {$d eq {string}} {
  71. set data [randstring 0 16 alpha]
  72. } else {
  73. set data [randomInt 4000000000]
  74. }
  75. r lpush key $data
  76. }
  77. assert_equal [r object encoding key] $e
  78. set d1 [r debug digest]
  79. r bgrewriteaof
  80. waitForBgrewriteaof r
  81. r debug loadaof
  82. set d2 [r debug digest]
  83. if {$d1 ne $d2} {
  84. error "assertion:$d1 is not equal to $d2"
  85. }
  86. }
  87. }
  88. }
  89. foreach d {string int} {
  90. foreach e {intset hashtable} {
  91. test "AOF rewrite of set with $e encoding, $d data" {
  92. r flushall
  93. if {$e eq {intset}} {set len 10} else {set len 1000}
  94. for {set j 0} {$j < $len} {incr j} {
  95. if {$d eq {string}} {
  96. set data [randstring 0 16 alpha]
  97. } else {
  98. set data [randomInt 4000000000]
  99. }
  100. r sadd key $data
  101. }
  102. if {$d ne {string}} {
  103. assert_equal [r object encoding key] $e
  104. }
  105. set d1 [r debug digest]
  106. r bgrewriteaof
  107. waitForBgrewriteaof r
  108. r debug loadaof
  109. set d2 [r debug digest]
  110. if {$d1 ne $d2} {
  111. error "assertion:$d1 is not equal to $d2"
  112. }
  113. }
  114. }
  115. }
  116. foreach d {string int} {
  117. foreach e {listpack hashtable} {
  118. test "AOF rewrite of hash with $e encoding, $d data" {
  119. r flushall
  120. if {$e eq {listpack}} {set len 10} else {set len 1000}
  121. for {set j 0} {$j < $len} {incr j} {
  122. if {$d eq {string}} {
  123. set data [randstring 0 16 alpha]
  124. } else {
  125. set data [randomInt 4000000000]
  126. }
  127. r hset key $data $data
  128. }
  129. assert_equal [r object encoding key] $e
  130. set d1 [r debug digest]
  131. r bgrewriteaof
  132. waitForBgrewriteaof r
  133. r debug loadaof
  134. set d2 [r debug digest]
  135. if {$d1 ne $d2} {
  136. error "assertion:$d1 is not equal to $d2"
  137. }
  138. }
  139. }
  140. }
  141. foreach d {string int} {
  142. foreach e {ziplist skiplist} {
  143. test "AOF rewrite of zset with $e encoding, $d data" {
  144. r flushall
  145. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  146. for {set j 0} {$j < $len} {incr j} {
  147. if {$d eq {string}} {
  148. set data [randstring 0 16 alpha]
  149. } else {
  150. set data [randomInt 4000000000]
  151. }
  152. r zadd key [expr rand()] $data
  153. }
  154. assert_equal [r object encoding key] $e
  155. set d1 [r debug digest]
  156. r bgrewriteaof
  157. waitForBgrewriteaof r
  158. r debug loadaof
  159. set d2 [r debug digest]
  160. if {$d1 ne $d2} {
  161. error "assertion:$d1 is not equal to $d2"
  162. }
  163. }
  164. }
  165. }
  166. test {BGREWRITEAOF is delayed if BGSAVE is in progress} {
  167. r multi
  168. r bgsave
  169. r bgrewriteaof
  170. r info persistence
  171. set res [r exec]
  172. assert_match {*scheduled*} [lindex $res 1]
  173. assert_match {*aof_rewrite_scheduled:1*} [lindex $res 2]
  174. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  175. after 100
  176. }
  177. }
  178. test {BGREWRITEAOF is refused if already in progress} {
  179. catch {
  180. r multi
  181. r bgrewriteaof
  182. r bgrewriteaof
  183. r exec
  184. } e
  185. assert_match {*ERR*already*} $e
  186. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  187. after 100
  188. }
  189. }
  190. }