Skip to content

Commit

Permalink
Test: AOF rewrite during write load.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jul 10, 2014
1 parent 067e365 commit e01195e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
9 changes: 0 additions & 9 deletions tests/integration/replication.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ start_server {tags {"repl"}} {
}
}

proc start_write_load {host port seconds} {
set tclsh [info nameofexecutable]
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds &
}

proc stop_write_load {handle} {
catch {exec /bin/kill -9 $handle}
}

start_server {tags {"repl"}} {
set master [srv 0 client]
set master_host [srv 0 host]
Expand Down
12 changes: 12 additions & 0 deletions tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,15 @@ proc colorstr {color str} {
return $str
}
}

# Execute a background process writing random data for the specified number
# of seconds to the specified Redis instance.
proc start_write_load {host port seconds} {
set tclsh [info nameofexecutable]
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds &
}

# Stop a process generating write load executed with start_write_load.
proc stop_write_load {handle} {
catch {exec /bin/kill -9 $handle}
}
52 changes: 52 additions & 0 deletions tests/unit/aofrw.tcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
start_server {tags {"aofrw"}} {
# Enable the AOF
r config set appendonly yes
r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
waitForBgrewriteaof r

test {AOF rewrite during write load} {
# Start a write load for 10 seconds
set master [srv 0 client]
set master_host [srv 0 host]
set master_port [srv 0 port]
set load_handle0 [start_write_load $master_host $master_port 10]
set load_handle1 [start_write_load $master_host $master_port 10]
set load_handle2 [start_write_load $master_host $master_port 10]
set load_handle3 [start_write_load $master_host $master_port 10]
set load_handle4 [start_write_load $master_host $master_port 10]

# Make sure the instance is really receiving data
wait_for_condition 50 100 {
[r dbsize] > 0
} else {
fail "No write load detected."
}

# After 3 seconds, start a rewrite, while the write load is still
# active.
after 3000
r bgrewriteaof
waitForBgrewriteaof r

# Let it run a bit more so that we'll append some data to the new
# AOF.
after 1000

# Stop the processes generating the load if they are still active
stop_write_load $load_handle0
stop_write_load $load_handle1
stop_write_load $load_handle2
stop_write_load $load_handle3
stop_write_load $load_handle4

# Get the data set digest
set d1 [r debug digest]

# Load the AOF
r debug loadaof
set d2 [r debug digest]

# Make sure they are the same
assert {$d1 eq $d2}
}
}

start_server {tags {"aofrw"}} {
test {Turning off AOF kills the background writing child if any} {
r config set appendonly yes
waitForBgrewriteaof r
Expand Down

0 comments on commit e01195e

Please sign in to comment.