2
0

aofrw.tcl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. start_server {tags {"aofrw"}} {
  2. test {Turning off AOF kills the background writing child if any} {
  3. r config set appendonly yes
  4. waitForBgrewriteaof r
  5. r multi
  6. r bgrewriteaof
  7. r config set appendonly no
  8. r exec
  9. wait_for_condition 50 100 {
  10. [string match {*Killing*AOF*child*} [exec tail -n5 < [srv 0 stdout]]]
  11. } else {
  12. fail "Can't find 'Killing AOF child' into recent logs"
  13. }
  14. }
  15. foreach d {string int} {
  16. foreach e {ziplist linkedlist} {
  17. test "AOF rewrite of list with $e encoding, $d data" {
  18. r flushall
  19. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  20. for {set j 0} {$j < $len} {incr j} {
  21. if {$d eq {string}} {
  22. set data [randstring 0 16 alpha]
  23. } else {
  24. set data [randomInt 4000000000]
  25. }
  26. r lpush key $data
  27. }
  28. assert_equal [r object encoding key] $e
  29. set d1 [r debug digest]
  30. r bgrewriteaof
  31. waitForBgrewriteaof r
  32. r debug loadaof
  33. set d2 [r debug digest]
  34. if {$d1 ne $d2} {
  35. error "assertion:$d1 is not equal to $d2"
  36. }
  37. }
  38. }
  39. }
  40. foreach d {string int} {
  41. foreach e {intset hashtable} {
  42. test "AOF rewrite of set with $e encoding, $d data" {
  43. r flushall
  44. if {$e eq {intset}} {set len 10} else {set len 1000}
  45. for {set j 0} {$j < $len} {incr j} {
  46. if {$d eq {string}} {
  47. set data [randstring 0 16 alpha]
  48. } else {
  49. set data [randomInt 4000000000]
  50. }
  51. r sadd key $data
  52. }
  53. if {$d ne {string}} {
  54. assert_equal [r object encoding key] $e
  55. }
  56. set d1 [r debug digest]
  57. r bgrewriteaof
  58. waitForBgrewriteaof r
  59. r debug loadaof
  60. set d2 [r debug digest]
  61. if {$d1 ne $d2} {
  62. error "assertion:$d1 is not equal to $d2"
  63. }
  64. }
  65. }
  66. }
  67. foreach d {string int} {
  68. foreach e {ziplist hashtable} {
  69. test "AOF rewrite of hash with $e encoding, $d data" {
  70. r flushall
  71. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  72. for {set j 0} {$j < $len} {incr j} {
  73. if {$d eq {string}} {
  74. set data [randstring 0 16 alpha]
  75. } else {
  76. set data [randomInt 4000000000]
  77. }
  78. r hset key $data $data
  79. }
  80. assert_equal [r object encoding key] $e
  81. set d1 [r debug digest]
  82. r bgrewriteaof
  83. waitForBgrewriteaof r
  84. r debug loadaof
  85. set d2 [r debug digest]
  86. if {$d1 ne $d2} {
  87. error "assertion:$d1 is not equal to $d2"
  88. }
  89. }
  90. }
  91. }
  92. foreach d {string int} {
  93. foreach e {ziplist skiplist} {
  94. test "AOF rewrite of zset with $e encoding, $d data" {
  95. r flushall
  96. if {$e eq {ziplist}} {set len 10} else {set len 1000}
  97. for {set j 0} {$j < $len} {incr j} {
  98. if {$d eq {string}} {
  99. set data [randstring 0 16 alpha]
  100. } else {
  101. set data [randomInt 4000000000]
  102. }
  103. r zadd key [expr rand()] $data
  104. }
  105. assert_equal [r object encoding key] $e
  106. set d1 [r debug digest]
  107. r bgrewriteaof
  108. waitForBgrewriteaof r
  109. r debug loadaof
  110. set d2 [r debug digest]
  111. if {$d1 ne $d2} {
  112. error "assertion:$d1 is not equal to $d2"
  113. }
  114. }
  115. }
  116. }
  117. test {BGREWRITEAOF is delayed if BGSAVE is in progress} {
  118. r multi
  119. r bgsave
  120. r bgrewriteaof
  121. r info persistence
  122. set res [r exec]
  123. assert_match {*scheduled*} [lindex $res 1]
  124. assert_match {*aof_rewrite_scheduled:1*} [lindex $res 2]
  125. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  126. after 100
  127. }
  128. }
  129. test {BGREWRITEAOF is refused if already in progress} {
  130. catch {
  131. r multi
  132. r bgrewriteaof
  133. r bgrewriteaof
  134. r exec
  135. } e
  136. assert_match {*ERR*already*} $e
  137. while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
  138. after 100
  139. }
  140. }
  141. }