"Fossies" - the Fresh Open Source Software Archive

Member "redis-6.2.5/tests/unit/aofrw.tcl" (21 Jul 2021, 7089 Bytes) of package /linux/misc/redis-6.2.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "aofrw.tcl": 6.2.4_vs_6.2.5.

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