mirror of
https://github.com/Snapchat/KeyDB.git
synced 2026-11-25 23:49:40 -05:00
commit
fe8efa916b
298 files changed
+30298
-10182
No files matched your search
@@ -296,4 +296,15 @@ tags {"aof"} {
|
||||
assert_equal 3 [$client scard testkey]
|
||||
}
|
||||
}
|
||||
|
||||
start_server {overrides {appendonly {yes} appendfilename {appendonly.aof}}} {
|
||||
test {GETEX should not append to AOF} {
|
||||
set aof [file join [lindex [r config get dir] 1] appendonly.aof]
|
||||
r set foo bar
|
||||
set before [file size $aof]
|
||||
r getex foo
|
||||
set after [file size $aof]
|
||||
assert_equal $before $after
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
# tests of corrupt ziplist payload with valid CRC
|
||||
|
||||
tags {"dump" "corruption"} {
|
||||
|
||||
proc generate_collections {suffix elements} {
|
||||
set rd [redis_deferring_client]
|
||||
for {set j 0} {$j < $elements} {incr j} {
|
||||
# add both string values and integers
|
||||
if {$j % 2 == 0} {set val $j} else {set val "_$j"}
|
||||
$rd hset hash$suffix $j $val
|
||||
$rd lpush list$suffix $val
|
||||
$rd zadd zset$suffix $j $val
|
||||
$rd sadd set$suffix $val
|
||||
$rd xadd stream$suffix * item 1 value $val
|
||||
}
|
||||
for {set j 0} {$j < $elements * 5} {incr j} {
|
||||
$rd read ; # Discard replies
|
||||
}
|
||||
$rd close
|
||||
}
|
||||
|
||||
# generate keys with various types and encodings
|
||||
proc generate_types {} {
|
||||
r config set list-max-ziplist-size 5
|
||||
r config set hash-max-ziplist-entries 5
|
||||
r config set zset-max-ziplist-entries 5
|
||||
r config set stream-node-max-entries 5
|
||||
|
||||
# create small (ziplist / listpack encoded) objects with 3 items
|
||||
generate_collections "" 3
|
||||
|
||||
# add some metadata to the stream
|
||||
r xgroup create stream mygroup 0
|
||||
set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >]
|
||||
r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0]
|
||||
r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0]
|
||||
|
||||
# create other non-collection types
|
||||
r incr int
|
||||
r set string str
|
||||
|
||||
# create bigger objects with 10 items (more than a single ziplist / listpack)
|
||||
generate_collections big 10
|
||||
|
||||
# make sure our big stream also has a listpack record that has different
|
||||
# field names than the master recored
|
||||
r xadd streambig * item 1 value 1
|
||||
r xadd streambig * item 1 unique value
|
||||
}
|
||||
|
||||
proc corrupt_payload {payload} {
|
||||
set len [string length $payload]
|
||||
set count 1 ;# usually corrupt only one byte
|
||||
if {rand() > 0.9} { set count 2 }
|
||||
while { $count > 0 } {
|
||||
set idx [expr {int(rand() * $len)}]
|
||||
set ch [binary format c [expr {int(rand()*255)}]]
|
||||
set payload [string replace $payload $idx $idx $ch]
|
||||
incr count -1
|
||||
}
|
||||
return $payload
|
||||
}
|
||||
|
||||
# fuzzy tester for corrupt RESTORE payloads
|
||||
# valgrind will make sure there were no leaks in the rdb loader error handling code
|
||||
foreach sanitize_dump {no yes} {
|
||||
if {$::accurate} {
|
||||
set min_duration [expr {60 * 10}] ;# run at least 10 minutes
|
||||
set min_cycles 1000 ;# run at least 1k cycles (max 16 minutes)
|
||||
} else {
|
||||
set min_duration 10 ; # run at least 10 seconds
|
||||
set min_cycles 10 ; # run at least 10 cycles
|
||||
}
|
||||
|
||||
# Don't execute this on FreeBSD due to a yet-undiscovered memory issue
|
||||
# which causes tclsh to bloat.
|
||||
if {[exec uname] == "FreeBSD"} {
|
||||
set min_cycles 1
|
||||
set min_duration 1
|
||||
}
|
||||
|
||||
test "Fuzzer corrupt restore payloads - sanitize_dump: $sanitize_dump" {
|
||||
if {$min_duration * 2 > $::timeout} {
|
||||
fail "insufficient timeout"
|
||||
}
|
||||
# start a server, fill with data and save an RDB file once (avoid re-save)
|
||||
start_server [list overrides [list "save" "" use-exit-on-panic yes crash-memcheck-enabled no loglevel verbose] ] {
|
||||
set stdout [srv 0 stdout]
|
||||
r config set sanitize-dump-payload $sanitize_dump
|
||||
r debug set-skip-checksum-validation 1
|
||||
set start_time [clock seconds]
|
||||
generate_types
|
||||
r save
|
||||
set cycle 0
|
||||
set stat_terminated_in_restore 0
|
||||
set stat_terminated_in_traffic 0
|
||||
set stat_terminated_by_signal 0
|
||||
set stat_successful_restore 0
|
||||
set stat_rejected_restore 0
|
||||
set stat_traffic_commands_sent 0
|
||||
# repeatedly DUMP a random key, corrupt it and try RESTORE into a new key
|
||||
while true {
|
||||
set k [r randomkey]
|
||||
set dump [r dump $k]
|
||||
set dump [corrupt_payload $dump]
|
||||
set printable_dump [string2printable $dump]
|
||||
set restore_failed false
|
||||
set report_and_restart false
|
||||
set sent {}
|
||||
# RESTORE can fail, but hopefully not terminate
|
||||
if { [catch { r restore "_$k" 0 $dump REPLACE } err] } {
|
||||
set restore_failed true
|
||||
# skip if return failed with an error response.
|
||||
if {[string match "ERR*" $err]} {
|
||||
incr stat_rejected_restore
|
||||
} else {
|
||||
set report_and_restart true
|
||||
incr stat_terminated_in_restore
|
||||
write_log_line 0 "corrupt payload: $printable_dump"
|
||||
if {$sanitize_dump == 1} {
|
||||
puts "Server crashed in RESTORE with payload: $printable_dump"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r ping ;# an attempt to check if the server didn't terminate (this will throw an error that will terminate the tests)
|
||||
}
|
||||
|
||||
set print_commands false
|
||||
if {!$restore_failed} {
|
||||
# if RESTORE didn't fail or terminate, run some random traffic on the new key
|
||||
incr stat_successful_restore
|
||||
if { [ catch {
|
||||
set sent [generate_fuzzy_traffic_on_key "_$k" 1] ;# traffic for 1 second
|
||||
incr stat_traffic_commands_sent [llength $sent]
|
||||
r del "_$k" ;# in case the server terminated, here's where we'll detect it.
|
||||
} err ] } {
|
||||
# if the server terminated update stats and restart it
|
||||
set report_and_restart true
|
||||
incr stat_terminated_in_traffic
|
||||
set by_signal [count_log_message 0 "crashed by signal"]
|
||||
incr stat_terminated_by_signal $by_signal
|
||||
|
||||
if {$by_signal != 0 || $sanitize_dump == 1 } {
|
||||
puts "Server crashed (by signal: $by_signal), with payload: $printable_dump"
|
||||
set print_commands true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# check valgrind report for invalid reads after each RESTORE
|
||||
# payload so that we have a report that is easier to reproduce
|
||||
set valgrind_errors [find_valgrind_errors [srv 0 stderr] false]
|
||||
if {$valgrind_errors != ""} {
|
||||
puts "valgrind found an issue for payload: $printable_dump"
|
||||
set report_and_restart true
|
||||
set print_commands true
|
||||
}
|
||||
|
||||
if {$report_and_restart} {
|
||||
if {$print_commands} {
|
||||
puts "violating commands:"
|
||||
foreach cmd $sent {
|
||||
foreach arg $cmd {
|
||||
puts -nonewline "[string2printable $arg] "
|
||||
}
|
||||
puts ""
|
||||
}
|
||||
}
|
||||
|
||||
# restart the server and re-apply debug configuration
|
||||
write_log_line 0 "corrupt payload: $printable_dump"
|
||||
restart_server 0 true true
|
||||
r config set sanitize-dump-payload $sanitize_dump
|
||||
r debug set-skip-checksum-validation 1
|
||||
}
|
||||
|
||||
incr cycle
|
||||
if { ([clock seconds]-$start_time) >= $min_duration && $cycle >= $min_cycles} {
|
||||
break
|
||||
}
|
||||
}
|
||||
if {$::verbose} {
|
||||
puts "Done $cycle cycles in [expr {[clock seconds]-$start_time}] seconds."
|
||||
puts "RESTORE: successful: $stat_successful_restore, rejected: $stat_rejected_restore"
|
||||
puts "Total commands sent in traffic: $stat_traffic_commands_sent, crashes during traffic: $stat_terminated_in_traffic ($stat_terminated_by_signal by signal)."
|
||||
}
|
||||
}
|
||||
# if we run sanitization we never expect the server to crash at runtime
|
||||
if { $sanitize_dump == 1} {
|
||||
assert_equal $stat_terminated_in_restore 0
|
||||
assert_equal $stat_terminated_in_traffic 0
|
||||
}
|
||||
# make sure all terminations where due to assertion and not a SIGSEGV
|
||||
assert_equal $stat_terminated_by_signal 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} ;# tags
|
||||
|
||||
@@ -0,0 +1,522 @@
|
||||
# tests of corrupt ziplist payload with valid CRC
|
||||
# * setting crash-memcheck-enabled to no to avoid issues with valgrind
|
||||
# * setting use-exit-on-panic to yes so that valgrind can search for leaks
|
||||
# * settng debug set-skip-checksum-validation to 1 on some tests for which we
|
||||
# didn't bother to fake a valid checksum
|
||||
# * some tests set sanitize-dump-payload to no and some to yet, depending on
|
||||
# what we want to test
|
||||
|
||||
tags {"dump" "corruption"} {
|
||||
|
||||
set corrupt_payload_7445 "\x0E\x01\x1D\x1D\x00\x00\x00\x16\x00\x00\x00\x03\x00\x00\x04\x43\x43\x43\x43\x06\x04\x42\x42\x42\x42\x06\x3F\x41\x41\x41\x41\xFF\x09\x00\x88\xA5\xCA\xA8\xC5\x41\xF4\x35"
|
||||
|
||||
test {corrupt payload: #7445 - with sanitize} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
catch {
|
||||
r restore key 0 $corrupt_payload_7445
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: #7445 - without sanitize - 1} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 $corrupt_payload_7445
|
||||
catch {r lindex key 2}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: #7445 - without sanitize - 2} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 $corrupt_payload_7445
|
||||
catch {r lset key 2 "BEEF"}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: hash with valid zip list header, invalid entry len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0D\x1B\x1B\x00\x00\x00\x16\x00\x00\x00\x04\x00\x00\x02\x61\x00\x04\x02\x62\x00\x04\x14\x63\x00\x04\x02\x64\x00\xFF\x09\x00\xD9\x10\x54\x92\x15\xF5\x5F\x52"
|
||||
r config set hash-max-ziplist-entries 1
|
||||
catch {r hset key b b}
|
||||
verify_log_message 0 "*zipEntrySafe*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: invalid zlbytes header} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
catch {
|
||||
r restore key 0 "\x0D\x1B\x25\x00\x00\x00\x16\x00\x00\x00\x04\x00\x00\x02\x61\x00\x04\x02\x62\x00\x04\x02\x63\x00\x04\x02\x64\x00\xFF\x09\x00\xB7\xF7\x6E\x9F\x43\x43\x14\xC6"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: valid zipped hash header, dup records} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0D\x1B\x1B\x00\x00\x00\x16\x00\x00\x00\x04\x00\x00\x02\x61\x00\x04\x02\x62\x00\x04\x02\x61\x00\x04\x02\x64\x00\xFF\x09\x00\xA1\x98\x36\x78\xCC\x8E\x93\x2E"
|
||||
r config set hash-max-ziplist-entries 1
|
||||
# cause an assertion when converting to hash table
|
||||
catch {r hset key b b}
|
||||
verify_log_message 0 "*ziplist with dup elements dump*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: quicklist big ziplist prev len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0E\x01\x13\x13\x00\x00\x00\x0E\x00\x00\x00\x02\x00\x00\x02\x61\x00\x0E\x02\x62\x00\xFF\x09\x00\x49\x97\x30\xB2\x0D\xA1\xED\xAA"
|
||||
catch {r lindex key -2}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: quicklist small ziplist prev len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
catch {
|
||||
r restore key 0 "\x0E\x01\x13\x13\x00\x00\x00\x0E\x00\x00\x00\x02\x00\x00\x02\x61\x00\x02\x02\x62\x00\xFF\x09\x00\xC7\x71\x03\x97\x07\x75\xB0\x63"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: quicklist ziplist wrong count} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0E\x01\x13\x13\x00\x00\x00\x0E\x00\x00\x00\x03\x00\x00\x02\x61\x00\x04\x02\x62\x00\xFF\x09\x00\x4D\xE2\x0A\x2F\x08\x25\xDF\x91"
|
||||
# we'll be able to push, but iterating on the list will assert
|
||||
r lpush key header
|
||||
r rpush key footer
|
||||
catch { [r lrange key -1 -1] }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: #3080 - quicklist} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
catch {
|
||||
r RESTORE key 0 "\x0E\x01\x80\x00\x00\x00\x10\x41\x41\x41\x41\x41\x41\x41\x41\x02\x00\x00\x80\x41\x41\x41\x41\x07\x00\x03\xC7\x1D\xEF\x54\x68\xCC\xF3"
|
||||
r DUMP key ;# DUMP was used in the original issue, but now even with shallow sanitization restore safely fails, so this is dead code
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: #3080 - ziplist} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
# shallow sanitization is enough for restore to safely reject the payload with wrong size
|
||||
r config set sanitize-dump-payload no
|
||||
catch {
|
||||
r RESTORE key 0 "\x0A\x80\x00\x00\x00\x10\x41\x41\x41\x41\x41\x41\x41\x41\x02\x00\x00\x80\x41\x41\x41\x41\x07\x00\x39\x5B\x49\xE0\xC1\xC6\xDD\x76"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: load corrupted rdb with no CRC - #3505} {
|
||||
set server_path [tmpdir "server.rdb-corruption-test"]
|
||||
exec cp tests/assets/corrupt_ziplist.rdb $server_path
|
||||
set srv [start_server [list overrides [list "dir" $server_path "dbfilename" "corrupt_ziplist.rdb" loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no sanitize-dump-payload no]]]
|
||||
|
||||
# wait for termination
|
||||
wait_for_condition 100 50 {
|
||||
! [is_alive $srv]
|
||||
} else {
|
||||
fail "rdb loading didn't fail"
|
||||
}
|
||||
|
||||
set stdout [dict get $srv stdout]
|
||||
assert_equal [count_message_lines $stdout "Terminating server after rdb file reading failure."] 1
|
||||
assert_lessthan 1 [count_message_lines $stdout "integrity check failed"]
|
||||
kill_server $srv ;# let valgrind look for issues
|
||||
}
|
||||
|
||||
test {corrupt payload: listpack invalid size header} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
catch {
|
||||
r restore key 0 "\x0F\x01\x10\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x40\x55\x5F\x00\x00\x00\x0F\x00\x01\x01\x00\x01\x02\x01\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x00\x01\x00\x01\x00\x01\x00\x01\x02\x02\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x61\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x88\x62\x00\x00\x00\x00\x00\x00\x00\x09\x08\x01\xFF\x0A\x01\x00\x00\x09\x00\x45\x91\x0A\x87\x2F\xA5\xF9\x2E"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*Stream listpack integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: listpack too long entry len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0F\x01\x10\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x40\x55\x55\x00\x00\x00\x0F\x00\x01\x01\x00\x01\x02\x01\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x00\x01\x00\x01\x00\x01\x00\x01\x02\x02\x89\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x61\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x88\x62\x00\x00\x00\x00\x00\x00\x00\x09\x08\x01\xFF\x0A\x01\x00\x00\x09\x00\x40\x63\xC9\x37\x03\xA2\xE5\x68"
|
||||
catch {
|
||||
r xinfo stream key full
|
||||
} err
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: listpack very long entry len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r restore key 0 "\x0F\x01\x10\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x40\x55\x55\x00\x00\x00\x0F\x00\x01\x01\x00\x01\x02\x01\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x00\x01\x00\x01\x00\x01\x00\x01\x02\x02\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x61\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x9C\x62\x00\x00\x00\x00\x00\x00\x00\x09\x08\x01\xFF\x0A\x01\x00\x00\x09\x00\x63\x6F\x42\x8E\x7C\xB5\xA2\x9D"
|
||||
catch {
|
||||
r xinfo stream key full
|
||||
} err
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: listpack too long entry prev len} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
catch {
|
||||
r restore key 0 "\x0F\x01\x10\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x40\x55\x55\x00\x00\x00\x0F\x00\x01\x01\x00\x15\x02\x01\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x00\x01\x00\x01\x00\x01\x00\x01\x02\x02\x88\x31\x00\x00\x00\x00\x00\x00\x00\x09\x88\x61\x00\x00\x00\x00\x00\x00\x00\x09\x88\x32\x00\x00\x00\x00\x00\x00\x00\x09\x88\x62\x00\x00\x00\x00\x00\x00\x00\x09\x08\x01\xFF\x0A\x01\x00\x00\x09\x00\x06\xFB\x44\x24\x0A\x8E\x75\xEA"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*Stream listpack integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: hash ziplist with duplicate records} {
|
||||
# when we do perform full sanitization, we expect duplicate records to fail the restore
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _hash 0 "\x0D\x3D\x3D\x00\x00\x00\x3A\x00\x00\x00\x14\x13\x00\xF5\x02\xF5\x02\xF2\x02\x53\x5F\x31\x04\xF3\x02\xF3\x02\xF7\x02\xF7\x02\xF8\x02\x02\x5F\x37\x04\xF1\x02\xF1\x02\xF6\x02\x02\x5F\x35\x04\xF4\x02\x02\x5F\x33\x04\xFA\x02\x02\x5F\x39\x04\xF9\x02\xF9\xFF\x09\x00\xB5\x48\xDE\x62\x31\xD0\xE5\x63" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: hash ziplist uneven record count} {
|
||||
# when we do perform full sanitization, we expect duplicate records to fail the restore
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _hash 0 "\r\x1b\x1b\x00\x00\x00\x16\x00\x00\x00\x04\x00\x00\x02a\x00\x04\x02b\x00\x04\x02a\x00\x04\x02d\x00\xff\t\x00\xa1\x98\x36x\xcc\x8e\x93\x2e" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: hash dupliacte records} {
|
||||
# when we do perform full sanitization, we expect duplicate records to fail the restore
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _hash 0 "\x04\x02\x01a\x01b\x01a\x01d\t\x00\xc6\x9c\xab\xbc\bk\x0c\x06" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - NPD in streamIteratorGetID} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {
|
||||
r RESTORE key 0 "\x0F\x01\x10\x00\x00\x01\x73\xBD\x68\x48\x71\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x05\x01\x02\x01\x00\x01\x01\x01\x01\x01\x82\x5F\x31\x03\x05\x01\x02\x01\x00\x01\x02\x01\x01\x01\x02\x01\x48\x01\xFF\x03\x81\x00\x00\x01\x73\xBD\x68\x48\x71\x02\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x73\xBD\x68\x48\x71\x00\x01\x00\x00\x01\x73\xBD\x68\x48\x71\x00\x00\x00\x00\x00\x00\x00\x00\x72\x48\x68\xBD\x73\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\x72\x48\x68\xBD\x73\x01\x00\x00\x01\x00\x00\x01\x73\xBD\x68\x48\x71\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x80\xCD\xB0\xD5\x1A\xCE\xFF\x10"
|
||||
r XREVRANGE key 725 233
|
||||
}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - listpack NPD on invalid stream} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {
|
||||
r RESTORE _stream 0 "\x0F\x01\x10\x00\x00\x01\x73\xDC\xB6\x6B\xF1\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x05\x01\x02\x01\x1F\x01\x00\x01\x01\x01\x6D\x5F\x31\x03\x05\x01\x02\x01\x29\x01\x00\x01\x01\x01\x02\x01\x05\x01\xFF\x03\x81\x00\x00\x01\x73\xDC\xB6\x6C\x1A\x00\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x73\xDC\xB6\x6B\xF1\x00\x01\x00\x00\x01\x73\xDC\xB6\x6B\xF1\x00\x00\x00\x00\x00\x00\x00\x00\x4B\x6C\xB6\xDC\x73\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\x3D\x6C\xB6\xDC\x73\x01\x00\x00\x01\x00\x00\x01\x73\xDC\xB6\x6B\xF1\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\xC7\x7D\x1C\xD7\x04\xFF\xE6\x9D"
|
||||
r XREAD STREAMS _stream 519389898758
|
||||
}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - NPD in quicklistIndex} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {
|
||||
r RESTORE key 0 "\x0E\x01\x13\x13\x00\x00\x00\x10\x00\x00\x00\x03\x12\x00\xF3\x02\x02\x5F\x31\x04\xF1\xFF\x09\x00\xC9\x4B\x31\xFE\x61\xC0\x96\xFE"
|
||||
r LSET key 290 290
|
||||
}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - invalid read in ziplistFind} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {
|
||||
r RESTORE key 0 "\x0D\x19\x19\x00\x00\x00\x16\x00\x00\x00\x06\x00\x00\xF1\x02\xF1\x02\xF2\x02\x02\x5F\x31\x04\x99\x02\xF3\xFF\x09\x00\xC5\xB8\x10\xC0\x8A\xF9\x16\xDF"
|
||||
r HEXISTS key -688319650333
|
||||
}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test {corrupt payload: fuzzer findings - invalid ziplist encoding} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {
|
||||
r RESTORE _listbig 0 "\x0E\x02\x1B\x1B\x00\x00\x00\x16\x00\x00\x00\x05\x00\x00\x02\x5F\x39\x04\xF9\x02\x86\x5F\x37\x04\xF7\x02\x02\x5F\x35\xFF\x19\x19\x00\x00\x00\x16\x00\x00\x00\x05\x00\x00\xF5\x02\x02\x5F\x33\x04\xF3\x02\x02\x5F\x31\x04\xF1\xFF\x09\x00\x0C\xFC\x99\x2C\x23\x45\x15\x60"
|
||||
} err
|
||||
assert_match "*Bad data format*" $err
|
||||
verify_log_message 0 "*integrity check failed*" 0
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - hash crash} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _hash 0 "\x0D\x19\x19\x00\x00\x00\x16\x00\x00\x00\x06\x00\x00\xF1\x02\xF1\x02\xF2\x02\x02\x5F\x31\x04\xF3\x02\xF3\xFF\x09\x00\x38\xB8\x10\xC0\x8A\xF9\x16\xDF"
|
||||
r HSET _hash 394891450 1635910264
|
||||
r HMGET _hash 887312884855
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - uneven entry count in hash} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _hashbig 0 "\x0D\x3D\x3D\x00\x00\x00\x38\x00\x00\x00\x14\x00\x00\xF2\x02\x02\x5F\x31\x04\x1C\x02\xF7\x02\xF1\x02\xF1\x02\xF5\x02\xF5\x02\xF4\x02\x02\x5F\x33\x04\xF6\x02\x02\x5F\x35\x04\xF8\x02\x02\x5F\x37\x04\xF9\x02\xF9\x02\xF3\x02\xF3\x02\xFA\x02\x02\x5F\x39\xFF\x09\x00\x73\xB7\x68\xC8\x97\x24\x8E\x88"
|
||||
catch { r HSCAN _hashbig -250 }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - invalid read in lzf_decompress} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _setbig 0 "\x02\x03\x02\x5F\x31\xC0\x02\xC3\x00\x09\x00\xE6\xDC\x76\x44\xFF\xEB\x3D\xFE" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - leak in rdbloading due to dup entry in set} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _setbig 0 "\x02\x0A\x02\x5F\x39\xC0\x06\x02\x5F\x31\xC0\x00\xC0\x04\x02\x5F\x35\xC0\x02\xC0\x08\x02\x5F\x31\x02\x5F\x33\x09\x00\x7A\x5A\xFB\x90\x3A\xE9\x3C\xBE" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - empty intset div by zero} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _setbig 0 "\x02\xC0\xC0\x06\x02\x5F\x39\xC0\x02\x02\x5F\x33\xC0\x00\x02\x5F\x31\xC0\x04\xC0\x08\x02\x5F\x37\x02\x5F\x35\x09\x00\xC5\xD4\x6D\xBA\xAD\x14\xB7\xE7"
|
||||
catch {r SRANDMEMBER _setbig }
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind ziplist - crash report prints freed memory} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _zsetbig 0 "\x0C\x3D\x3D\x00\x00\x00\x3A\x00\x00\x00\x14\x00\x00\xF1\x02\xF1\x02\x02\x5F\x31\x04\xF2\x02\xF3\x02\xF3\x02\x02\x5F\x33\x04\xF4\x02\xEE\x02\xF5\x02\x02\x5F\x35\x04\xF6\x02\xF7\x02\xF7\x02\x02\x5F\x37\x04\xF8\x02\xF9\x02\xF9\x02\x02\x5F\x39\x04\xFA\xFF\x09\x00\xAE\xF9\x77\x2A\x47\x24\x33\xF6"
|
||||
catch { r ZREMRANGEBYSCORE _zsetbig -1050966020 724 }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind ziplist prevlen reaches outside the ziplist} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _listbig 0 "\x0E\x02\x1B\x1B\x00\x00\x00\x16\x00\x00\x00\x05\x00\x00\x02\x5F\x39\x04\xF9\x02\x02\x5F\x37\x04\xF7\x02\x02\x5F\x35\xFF\x19\x19\x00\x00\x00\x16\x00\x00\x00\x05\x00\x00\xF5\x02\x02\x5F\x33\x04\xF3\x95\x02\x5F\x31\x04\xF1\xFF\x09\x00\x0C\xFC\x99\x2C\x23\x45\x15\x60"
|
||||
catch { r RPOP _listbig }
|
||||
catch { r RPOP _listbig }
|
||||
catch { r RPUSH _listbig 949682325 }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind - bad rdbLoadDoubleValue} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _list 0 "\x03\x01\x11\x11\x00\x00\x00\x0A\x00\x00\x00\x01\x00\x00\xD0\x07\x1A\xE9\x02\xFF\x09\x00\x1A\x06\x07\x32\x41\x28\x3A\x46" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind ziplist prev too big} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _list 0 "\x0E\x01\x13\x13\x00\x00\x00\x10\x00\x00\x00\x03\x00\x00\xF3\x02\x02\x5F\x31\xC1\xF1\xFF\x09\x00\xC9\x4B\x31\xFE\x61\xC0\x96\xFE"
|
||||
catch { r RPUSHX _list -45 }
|
||||
catch { r LREM _list -748 -840}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - lzf decompression fails, avoid valgrind invalid read} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {r RESTORE _stream 0 "\x0F\x02\x10\x00\x00\x01\x73\xDD\xAA\x2A\xB9\x00\x00\x00\x00\x00\x00\x00\x00\xC3\x40\x4B\x40\x5C\x18\x5C\x00\x00\x00\x24\x00\x05\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x40\x10\x00\x00\x20\x01\x00\x01\x20\x03\x00\x05\x20\x1C\x40\x07\x05\x01\x01\x82\x5F\x31\x03\x80\x0D\x40\x00\x00\x02\x60\x19\x40\x27\x40\x19\x00\x33\x60\x19\x40\x29\x02\x01\x01\x04\x20\x19\x00\xFF\x10\x00\x00\x01\x73\xDD\xAA\x2A\xBC\x00\x00\x00\x00\x00\x00\x00\x00\xC3\x40\x4D\x40\x5E\x18\x5E\x00\x00\x00\x24\x00\x05\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x40\x10\x00\x00\x20\x01\x06\x01\x01\x82\x5F\x35\x03\x05\x20\x1E\x17\x0B\x03\x01\x01\x06\x01\x40\x0B\x00\x01\x60\x0D\x02\x82\x5F\x37\x60\x19\x80\x00\x00\x08\x60\x19\x80\x27\x02\x82\x5F\x39\x20\x19\x00\xFF\x0A\x81\x00\x00\x01\x73\xDD\xAA\x2A\xBE\x00\x00\x09\x00\x21\x85\x77\x43\x71\x7B\x17\x88"} err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - stream bad lp_count} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _stream 0 "\x0F\x01\x10\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x56\x01\x02\x01\x22\x01\x00\x01\x01\x01\x82\x5F\x31\x03\x05\x01\x02\x01\x2C\x01\x00\x01\x01\x01\x02\x01\x05\x01\xFF\x03\x81\x00\x00\x01\x73\xDE\xDF\x7D\xC7\x00\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x01\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\xF9\x7D\xDF\xDE\x73\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\xEB\x7D\xDF\xDE\x73\x01\x00\x00\x01\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\xB2\xA8\xA7\x5F\x1B\x61\x72\xD5"} err
|
||||
assert_match "*Bad data format*" $err
|
||||
r ping
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - stream bad lp_count - unsanitized} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _stream 0 "\x0F\x01\x10\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x56\x01\x02\x01\x22\x01\x00\x01\x01\x01\x82\x5F\x31\x03\x05\x01\x02\x01\x2C\x01\x00\x01\x01\x01\x02\x01\x05\x01\xFF\x03\x81\x00\x00\x01\x73\xDE\xDF\x7D\xC7\x00\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x01\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\xF9\x7D\xDF\xDE\x73\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\xEB\x7D\xDF\xDE\x73\x01\x00\x00\x01\x00\x00\x01\x73\xDE\xDF\x7D\x9B\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\xB2\xA8\xA7\x5F\x1B\x61\x72\xD5"
|
||||
catch { r XREVRANGE _stream 638932639 738}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - stream integrity check issue} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _stream 0 "\x0F\x02\x10\x00\x00\x01\x75\x2D\xA2\x90\x67\x00\x00\x00\x00\x00\x00\x00\x00\xC3\x40\x4F\x40\x5C\x18\x5C\x00\x00\x00\x24\x00\x05\x01\x00\x01\x4A\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x40\x10\x00\x00\x20\x01\x00\x01\x20\x03\x00\x05\x20\x1C\x40\x09\x05\x01\x01\x82\x5F\x31\x03\x80\x0D\x00\x02\x20\x0D\x00\x02\xA0\x19\x00\x03\x20\x0B\x02\x82\x5F\x33\xA0\x19\x00\x04\x20\x0D\x00\x04\x20\x19\x00\xFF\x10\x00\x00\x01\x75\x2D\xA2\x90\x67\x00\x00\x00\x00\x00\x00\x00\x05\xC3\x40\x56\x40\x60\x18\x60\x00\x00\x00\x24\x00\x05\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x40\x10\x00\x00\x20\x01\x06\x01\x01\x82\x5F\x35\x03\x05\x20\x1E\x40\x0B\x03\x01\x01\x06\x01\x80\x0B\x00\x02\x20\x0B\x02\x82\x5F\x37\x60\x19\x03\x01\x01\xDF\xFB\x20\x05\x00\x08\x60\x1A\x20\x0C\x00\xFC\x20\x05\x02\x82\x5F\x39\x20\x1B\x00\xFF\x0A\x81\x00\x00\x01\x75\x2D\xA2\x90\x68\x01\x00\x09\x00\x1D\x6F\xC0\x69\x8A\xDE\xF7\x92" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - infinite loop} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _stream 0 "\x0F\x01\x10\x00\x00\x01\x75\x3A\xA6\xD0\x93\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x05\x01\x02\x01\x00\x01\x01\x01\x01\x01\x82\x5F\x31\x03\xFD\x01\x02\x01\x00\x01\x02\x01\x01\x01\x02\x01\x05\x01\xFF\x03\x81\x00\x00\x01\x75\x3A\xA6\xD0\x93\x02\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x75\x3A\xA6\xD0\x93\x00\x01\x00\x00\x01\x75\x3A\xA6\xD0\x93\x00\x00\x00\x00\x00\x00\x00\x00\x94\xD0\xA6\x3A\x75\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\x94\xD0\xA6\x3A\x75\x01\x00\x00\x01\x00\x00\x01\x75\x3A\xA6\xD0\x93\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\xC4\x09\xAD\x69\x7E\xEE\xA6\x2F"
|
||||
catch { r XREVRANGE _stream 288270516 971031845 }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - hash convert asserts on RESTORE with shallow sanitization} {
|
||||
# if we don't perform full sanitization, and the next command can assert on converting
|
||||
# a ziplist to hash records, then we're ok with that happning in RESTORE too
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE _hash 0 "\x0D\x3D\x3D\x00\x00\x00\x3A\x00\x00\x00\x14\x13\x00\xF5\x02\xF5\x02\xF2\x02\x53\x5F\x31\x04\xF3\x02\xF3\x02\xF7\x02\xF7\x02\xF8\x02\x02\x5F\x37\x04\xF1\x02\xF1\x02\xF6\x02\x02\x5F\x35\x04\xF4\x02\x02\x5F\x33\x04\xFA\x02\x02\x5F\x39\x04\xF9\x02\xF9\xFF\x09\x00\xB5\x48\xDE\x62\x31\xD0\xE5\x63" }
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: OOM in rdbGenericLoadStringObject} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
catch { r RESTORE x 0 "\x0A\x81\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x13\x00\x00\x00\x0E\x00\x00\x00\x02\x00\x00\x02\x61\x00\x04\x02\x62\x00\xFF\x09\x00\x57\x04\xE5\xCD\xD4\x37\x6C\x57" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
r ping
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - OOM in dictExpand} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch { r RESTORE x 0 "\x02\x81\x02\x5F\x31\xC0\x00\xC0\x02\x09\x00\xCD\x84\x2C\xB7\xE8\xA4\x49\x57" } err
|
||||
assert_match "*Bad data format*" $err
|
||||
r ping
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - invalid tail offset after removal} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _zset 0 "\x0C\x19\x19\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\xF1\x02\xF1\x02\x02\x5F\x31\x04\xF2\x02\xF3\x02\xF3\xFF\x09\x00\x4D\x72\x7B\x97\xCD\x9A\x70\xC1"
|
||||
catch {r ZPOPMIN _zset}
|
||||
catch {r ZPOPMAX _zset}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - negative reply length} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload no
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _stream 0 "\x0F\x01\x10\x00\x00\x01\x75\xCF\xA1\x16\xA7\x00\x00\x00\x00\x00\x00\x00\x00\x40\x42\x42\x00\x00\x00\x18\x00\x03\x01\x00\x01\x02\x01\x84\x69\x74\x65\x6D\x05\x85\x76\x61\x6C\x75\x65\x06\x00\x01\x02\x01\x00\x01\x00\x01\x01\x01\x00\x01\x05\x01\x02\x01\x00\x01\x01\x01\x01\x01\x14\x5F\x31\x03\x05\x01\x02\x01\x00\x01\x02\x01\x01\x01\x02\x01\x05\x01\xFF\x03\x81\x00\x00\x01\x75\xCF\xA1\x16\xA7\x02\x01\x07\x6D\x79\x67\x72\x6F\x75\x70\x81\x00\x00\x01\x75\xCF\xA1\x16\xA7\x01\x01\x00\x00\x01\x75\xCF\xA1\x16\xA7\x00\x00\x00\x00\x00\x00\x00\x01\xA7\x16\xA1\xCF\x75\x01\x00\x00\x01\x01\x05\x41\x6C\x69\x63\x65\xA7\x16\xA1\xCF\x75\x01\x00\x00\x01\x00\x00\x01\x75\xCF\xA1\x16\xA7\x00\x00\x00\x00\x00\x00\x00\x01\x09\x00\x1B\x42\x52\xB8\xDD\x5C\xE5\x4E"
|
||||
catch {r XADD _stream * -956 -2601503852}
|
||||
catch {r XINFO STREAM _stream FULL}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind negative malloc} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {r RESTORE _key 0 "\x0E\x01\x81\xD6\xD6\x00\x00\x00\x0A\x00\x00\x00\x01\x00\x00\x40\xC8\x6F\x2F\x36\xE2\xDF\xE3\x2E\x26\x64\x8B\x87\xD1\x7A\xBD\xFF\xEF\xEF\x63\x65\xF6\xF8\x8C\x4E\xEC\x96\x89\x56\x88\xF8\x3D\x96\x5A\x32\xBD\xD1\x36\xD8\x02\xE6\x66\x37\xCB\x34\x34\xC4\x52\xA7\x2A\xD5\x6F\x2F\x7E\xEE\xA2\x94\xD9\xEB\xA9\x09\x38\x3B\xE1\xA9\x60\xB6\x4E\x09\x44\x1F\x70\x24\xAA\x47\xA8\x6E\x30\xE1\x13\x49\x4E\xA1\x92\xC4\x6C\xF0\x35\x83\xD9\x4F\xD9\x9C\x0A\x0D\x7A\xE7\xB1\x61\xF5\xC1\x2D\xDC\xC3\x0E\x87\xA6\x80\x15\x18\xBA\x7F\x72\xDD\x14\x75\x46\x44\x0B\xCA\x9C\x8F\x1C\x3C\xD7\xDA\x06\x62\x18\x7E\x15\x17\x24\xAB\x45\x21\x27\xC2\xBC\xBB\x86\x6E\xD8\xBD\x8E\x50\xE0\xE0\x88\xA4\x9B\x9D\x15\x2A\x98\xFF\x5E\x78\x6C\x81\xFC\xA8\xC9\xC8\xE6\x61\xC8\xD1\x4A\x7F\x81\xD6\xA6\x1A\xAD\x4C\xC1\xA2\x1C\x90\x68\x15\x2A\x8A\x36\xC0\x58\xC3\xCC\xA6\x54\x19\x12\x0F\xEB\x46\xFF\x6E\xE3\xA7\x92\xF8\xFF\x09\x00\xD0\x71\xF7\x9F\xF7\x6A\xD6\x2E"} err
|
||||
assert_match "*Bad data format*" $err
|
||||
r ping
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - valgrind invalid read} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
catch {r RESTORE _key 0 "\x05\x0A\x02\x5F\x39\x00\x00\x00\x00\x00\x00\x22\x40\xC0\x08\x00\x00\x00\x00\x00\x00\x20\x40\x02\x5F\x37\x00\x00\x00\x00\x00\x00\x1C\x40\xC0\x06\x00\x00\x00\x00\x00\x00\x18\x40\x02\x5F\x33\x00\x00\x00\x00\x00\x00\x14\x40\xC0\x04\x00\x00\x00\x00\x00\x00\x10\x40\x02\x5F\x33\x00\x00\x00\x00\x00\x00\x08\x40\xC0\x02\x00\x00\x00\x00\x00\x00\x00\x40\x02\x5F\x31\x00\x00\x00\x00\x00\x00\xF0\x3F\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x3C\x66\xD7\x14\xA9\xDA\x3C\x69"} err
|
||||
assert_match "*Bad data format*" $err
|
||||
r ping
|
||||
}
|
||||
}
|
||||
|
||||
test {corrupt payload: fuzzer findings - HRANDFIELD on bad ziplist} {
|
||||
start_server [list overrides [list loglevel verbose use-exit-on-panic yes crash-memcheck-enabled no] ] {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug set-skip-checksum-validation 1
|
||||
r RESTORE _int 0 "\x04\xC0\x01\x09\x00\xF6\x8A\xB6\x7A\x85\x87\x72\x4D"
|
||||
catch {r HRANDFIELD _int}
|
||||
assert_equal [count_log_message 0 "crashed by signal"] 0
|
||||
assert_equal [count_log_message 0 "ASSERTION FAILED"] 1
|
||||
}
|
||||
}
|
||||
|
||||
} ;# tags
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
start_server {tags {"failover"}} {
|
||||
start_server {} {
|
||||
start_server {} {
|
||||
set node_0 [srv 0 client]
|
||||
set node_0_host [srv 0 host]
|
||||
set node_0_port [srv 0 port]
|
||||
set node_0_pid [srv 0 pid]
|
||||
|
||||
set node_1 [srv -1 client]
|
||||
set node_1_host [srv -1 host]
|
||||
set node_1_port [srv -1 port]
|
||||
set node_1_pid [srv -1 pid]
|
||||
|
||||
set node_2 [srv -2 client]
|
||||
set node_2_host [srv -2 host]
|
||||
set node_2_port [srv -2 port]
|
||||
set node_2_pid [srv -2 pid]
|
||||
|
||||
proc assert_digests_match {n1 n2 n3} {
|
||||
assert_equal [$n1 debug digest] [$n2 debug digest]
|
||||
assert_equal [$n2 debug digest] [$n3 debug digest]
|
||||
}
|
||||
|
||||
test {failover command fails without connected replica} {
|
||||
catch { $node_0 failover to $node_1_host $node_1_port } err
|
||||
if {! [string match "ERR*" $err]} {
|
||||
fail "failover command succeeded when replica not connected"
|
||||
}
|
||||
}
|
||||
|
||||
test {setup replication for following tests} {
|
||||
$node_1 replicaof $node_0_host $node_0_port
|
||||
$node_2 replicaof $node_0_host $node_0_port
|
||||
wait_for_sync $node_1
|
||||
wait_for_sync $node_2
|
||||
}
|
||||
|
||||
test {failover command fails with invalid host} {
|
||||
catch { $node_0 failover to invalidhost $node_1_port } err
|
||||
assert_match "ERR*" $err
|
||||
}
|
||||
|
||||
test {failover command fails with invalid port} {
|
||||
catch { $node_0 failover to $node_1_host invalidport } err
|
||||
assert_match "ERR*" $err
|
||||
}
|
||||
|
||||
test {failover command fails with just force and timeout} {
|
||||
catch { $node_0 FAILOVER FORCE TIMEOUT 100} err
|
||||
assert_match "ERR*" $err
|
||||
}
|
||||
|
||||
test {failover command fails when sent to a replica} {
|
||||
catch { $node_1 failover to $node_1_host $node_1_port } err
|
||||
assert_match "ERR*" $err
|
||||
}
|
||||
|
||||
test {failover command fails with force without timeout} {
|
||||
catch { $node_0 failover to $node_1_host $node_1_port FORCE } err
|
||||
assert_match "ERR*" $err
|
||||
}
|
||||
|
||||
test {failover command to specific replica works} {
|
||||
set initial_psyncs [s -1 sync_partial_ok]
|
||||
set initial_syncs [s -1 sync_full]
|
||||
|
||||
# Generate a delta between primary and replica
|
||||
set load_handler [start_write_load $node_0_host $node_0_port 5]
|
||||
exec kill -SIGSTOP [srv -1 pid]
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 total_commands_processed] > 100
|
||||
} else {
|
||||
fail "Node 0 did not accept writes"
|
||||
}
|
||||
exec kill -SIGCONT [srv -1 pid]
|
||||
|
||||
# Execute the failover
|
||||
$node_0 failover to $node_1_host $node_1_port
|
||||
|
||||
# Wait for failover to end
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 master_failover_state] == "no-failover"
|
||||
} else {
|
||||
fail "Failover from node 0 to node 1 did not finish"
|
||||
}
|
||||
stop_write_load $load_handler
|
||||
$node_2 replicaof $node_1_host $node_1_port
|
||||
wait_for_sync $node_0
|
||||
wait_for_sync $node_2
|
||||
|
||||
assert_match *slave* [$node_0 role]
|
||||
assert_match *master* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
# We should accept psyncs from both nodes
|
||||
assert_equal [expr [s -1 sync_partial_ok] - $initial_psyncs] 2
|
||||
assert_equal [expr [s -1 sync_full] - $initial_psyncs] 0
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
|
||||
test {failover command to any replica works} {
|
||||
set initial_psyncs [s -2 sync_partial_ok]
|
||||
set initial_syncs [s -2 sync_full]
|
||||
|
||||
wait_for_ofs_sync $node_1 $node_2
|
||||
# We stop node 0 to and make sure node 2 is selected
|
||||
exec kill -SIGSTOP $node_0_pid
|
||||
$node_1 set CASE 1
|
||||
$node_1 FAILOVER
|
||||
|
||||
# Wait for failover to end
|
||||
wait_for_condition 50 100 {
|
||||
[s -1 master_failover_state] == "no-failover"
|
||||
} else {
|
||||
fail "Failover from node 1 to node 2 did not finish"
|
||||
}
|
||||
exec kill -SIGCONT $node_0_pid
|
||||
$node_0 replicaof $node_2_host $node_2_port
|
||||
|
||||
wait_for_sync $node_0
|
||||
wait_for_sync $node_1
|
||||
|
||||
assert_match *slave* [$node_0 role]
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *master* [$node_2 role]
|
||||
|
||||
# We should accept Psyncs from both nodes
|
||||
assert_equal [expr [s -2 sync_partial_ok] - $initial_psyncs] 2
|
||||
assert_equal [expr [s -1 sync_full] - $initial_psyncs] 0
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
|
||||
test {failover to a replica with force works} {
|
||||
set initial_psyncs [s 0 sync_partial_ok]
|
||||
set initial_syncs [s 0 sync_full]
|
||||
|
||||
exec kill -SIGSTOP $node_0_pid
|
||||
# node 0 will never acknowledge this write
|
||||
$node_2 set case 2
|
||||
$node_2 failover to $node_0_host $node_0_port TIMEOUT 100 FORCE
|
||||
|
||||
# Wait for node 0 to give up on sync attempt and start failover
|
||||
wait_for_condition 50 100 {
|
||||
[s -2 master_failover_state] == "failover-in-progress"
|
||||
} else {
|
||||
fail "Failover from node 2 to node 0 did not timeout"
|
||||
}
|
||||
|
||||
# Quick check that everyone is a replica, we never want a
|
||||
# state where there are two masters.
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
exec kill -SIGCONT $node_0_pid
|
||||
|
||||
# Wait for failover to end
|
||||
wait_for_condition 50 100 {
|
||||
[s -2 master_failover_state] == "no-failover"
|
||||
} else {
|
||||
fail "Failover from node 2 to node 0 did not finish"
|
||||
}
|
||||
$node_1 replicaof $node_0_host $node_0_port
|
||||
|
||||
wait_for_sync $node_1
|
||||
wait_for_sync $node_2
|
||||
|
||||
assert_match *master* [$node_0 role]
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
assert_equal [count_log_message -2 "time out exceeded, failing over."] 1
|
||||
|
||||
# We should accept both psyncs, although this is the condition we might not
|
||||
# since we didn't catch up.
|
||||
assert_equal [expr [s 0 sync_partial_ok] - $initial_psyncs] 2
|
||||
assert_equal [expr [s 0 sync_full] - $initial_syncs] 0
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
|
||||
test {failover with timeout aborts if replica never catches up} {
|
||||
set initial_psyncs [s 0 sync_partial_ok]
|
||||
set initial_syncs [s 0 sync_full]
|
||||
|
||||
# Stop replica so it never catches up
|
||||
exec kill -SIGSTOP [srv -1 pid]
|
||||
$node_0 SET CASE 1
|
||||
|
||||
$node_0 failover to [srv -1 host] [srv -1 port] TIMEOUT 500
|
||||
# Wait for failover to end
|
||||
wait_for_condition 50 20 {
|
||||
[s 0 master_failover_state] == "no-failover"
|
||||
} else {
|
||||
fail "Failover from node_0 to replica did not finish"
|
||||
}
|
||||
|
||||
exec kill -SIGCONT [srv -1 pid]
|
||||
|
||||
# We need to make sure the nodes actually sync back up
|
||||
wait_for_ofs_sync $node_0 $node_1
|
||||
wait_for_ofs_sync $node_0 $node_2
|
||||
|
||||
assert_match *master* [$node_0 role]
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
# Since we never caught up, there should be no syncs
|
||||
assert_equal [expr [s 0 sync_partial_ok] - $initial_psyncs] 0
|
||||
assert_equal [expr [s 0 sync_full] - $initial_syncs] 0
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
|
||||
test {failovers can be aborted} {
|
||||
set initial_psyncs [s 0 sync_partial_ok]
|
||||
set initial_syncs [s 0 sync_full]
|
||||
|
||||
# Stop replica so it never catches up
|
||||
exec kill -SIGSTOP [srv -1 pid]
|
||||
$node_0 SET CASE 2
|
||||
|
||||
$node_0 failover to [srv -1 host] [srv -1 port] TIMEOUT 60000
|
||||
assert_match [s 0 master_failover_state] "waiting-for-sync"
|
||||
|
||||
# Sanity check that read commands are still accepted
|
||||
$node_0 GET CASE
|
||||
|
||||
$node_0 failover abort
|
||||
assert_match [s 0 master_failover_state] "no-failover"
|
||||
|
||||
exec kill -SIGCONT [srv -1 pid]
|
||||
|
||||
# Just make sure everything is still synced
|
||||
wait_for_ofs_sync $node_0 $node_1
|
||||
wait_for_ofs_sync $node_0 $node_2
|
||||
|
||||
assert_match *master* [$node_0 role]
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
# Since we never caught up, there should be no syncs
|
||||
assert_equal [expr [s 0 sync_partial_ok] - $initial_psyncs] 0
|
||||
assert_equal [expr [s 0 sync_full] - $initial_syncs] 0
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
|
||||
test {failover aborts if target rejects sync request} {
|
||||
set initial_psyncs [s 0 sync_partial_ok]
|
||||
set initial_syncs [s 0 sync_full]
|
||||
|
||||
# We block psync, so the failover will fail
|
||||
$node_1 acl setuser default -psync
|
||||
|
||||
# We pause the target long enough to send a write command
|
||||
# during the pause. This write will not be interrupted.
|
||||
exec kill -SIGSTOP [srv -1 pid]
|
||||
set rd [redis_deferring_client]
|
||||
$rd SET FOO BAR
|
||||
$node_0 failover to $node_1_host $node_1_port
|
||||
exec kill -SIGCONT [srv -1 pid]
|
||||
|
||||
# Wait for failover to end
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 master_failover_state] == "no-failover"
|
||||
} else {
|
||||
fail "Failover from node_0 to replica did not finish"
|
||||
}
|
||||
|
||||
assert_equal [$rd read] "OK"
|
||||
$rd close
|
||||
|
||||
# restore access to psync
|
||||
$node_1 acl setuser default +psync
|
||||
|
||||
# We need to make sure the nodes actually sync back up
|
||||
wait_for_sync $node_1
|
||||
wait_for_sync $node_2
|
||||
|
||||
assert_match *master* [$node_0 role]
|
||||
assert_match *slave* [$node_1 role]
|
||||
assert_match *slave* [$node_2 role]
|
||||
|
||||
# We will cycle all of our replicas here and force a psync.
|
||||
assert_equal [expr [s 0 sync_partial_ok] - $initial_psyncs] 2
|
||||
assert_equal [expr [s 0 sync_full] - $initial_syncs] 0
|
||||
|
||||
assert_equal [count_log_message 0 "Failover target rejected psync request"] 1
|
||||
assert_digests_match $node_0 $node_1 $node_2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
set server_path [tmpdir server.log]
|
||||
set system_name [string tolower [exec uname -s]]
|
||||
# ldd --version returns 1 under musl for unknown reasons. If this check stops working, that may be why
|
||||
set is_musl [catch {exec ldd --version}]
|
||||
set system_supported 0
|
||||
|
||||
if {$system_name eq {linux} && $is_musl eq 0 || $system_name eq {darwin}} {
|
||||
# We only support darwin or Linux with glibc
|
||||
if {$system_name eq {darwin}} {
|
||||
set system_supported 1
|
||||
} elseif {$system_name eq {linux} && $is_musl eq 0} {
|
||||
# Avoid the test on libmusl, which does not support backtrace
|
||||
set ldd [exec ldd src/keydb-server]
|
||||
if {![string match {*libc.musl*} $ldd]} {
|
||||
set system_supported 1
|
||||
}
|
||||
}
|
||||
|
||||
if {$system_supported} {
|
||||
set server_path [tmpdir server.log]
|
||||
start_server [list overrides [list dir $server_path]] {
|
||||
test "Server is able to generate a stack trace on selected systems" {
|
||||
r config set watchdog-period 200
|
||||
r debug sleep 1
|
||||
set pattern "*watchdogSignalHandler*"
|
||||
set pattern "*STACK TRACE*"
|
||||
set retry 10
|
||||
while {$retry} {
|
||||
set result [exec tail -100 < [srv 0 stdout]]
|
||||
@@ -23,4 +35,19 @@ if {$system_name eq {linux} && $is_musl eq 0 || $system_name eq {darwin}} {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Valgrind will complain that the process terminated by a signal, skip it.
|
||||
if {!$::valgrind} {
|
||||
set server_path [tmpdir server1.log]
|
||||
start_server [list overrides [list dir $server_path]] {
|
||||
test "Crash report generated on SIGABRT" {
|
||||
set pid [s process_id]
|
||||
exec kill -SIGABRT $pid
|
||||
set pattern "*STACK TRACE*"
|
||||
set result [exec tail -1000 < [srv 0 stdout]]
|
||||
assert {[string match $pattern $result]}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ proc show_cluster_status {} {
|
||||
# time info. Logs are in the following form:
|
||||
#
|
||||
# 11296:M 25 May 2020 17:37:14.652 # Server initialized
|
||||
set log_regexp {^[0-9]+:[A-Z] [0-9]+ [A-z]+ [0-9]+ ([0-9:.]+) .*}
|
||||
set log_regexp {^[0-9]+:^[0-9]+:[A-Z] [0-9]+ [A-z]+ [0-9]+ ([0-9:.]+) .*}
|
||||
set repl_regexp {(master|repl|sync|backlog|meaningful|offset)}
|
||||
|
||||
puts "Master ID is $master_id"
|
||||
@@ -25,15 +25,11 @@ proc show_cluster_status {} {
|
||||
array set log {}
|
||||
for {set j 0} {$j < 5} {incr j} {
|
||||
set fd [open $R_log($j)]
|
||||
set found 0
|
||||
set tries 0
|
||||
while {([gets $fd l] >= 0 || !$found) && $tries < 1000} {
|
||||
while {[gets $fd l] >= 0} {
|
||||
if {[regexp $log_regexp $l] &&
|
||||
[regexp -nocase $repl_regexp $l]} {
|
||||
lappend log($j) $l
|
||||
set found 1
|
||||
}
|
||||
incr $tries
|
||||
}
|
||||
close $fd
|
||||
}
|
||||
@@ -98,7 +94,7 @@ start_server {} {
|
||||
# master and slave instances while the
|
||||
# master is loaded with writes.
|
||||
|
||||
set disconnect_period 2000 ; # Disconnect repl link every N ms.
|
||||
set disconnect_period 1000 ; # Disconnect repl link every N ms.
|
||||
|
||||
for {set j 0} {$j < 5} {incr j} {
|
||||
set R($j) [srv [expr 0-$j] client]
|
||||
@@ -160,7 +156,7 @@ start_server {} {
|
||||
test "PSYNC2: cluster is consistent after failover" {
|
||||
$R($master_id) incr x; incr counter_value
|
||||
for {set j 0} {$j < 5} {incr j} {
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[$R($j) get x] == $counter_value
|
||||
} else {
|
||||
show_cluster_status
|
||||
@@ -196,7 +192,7 @@ start_server {} {
|
||||
set x [$R($master_id) get x]
|
||||
test "PSYNC2: cluster is consistent after load (x = $x)" {
|
||||
for {set j 0} {$j < 5} {incr j} {
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[$R($j) get x] == $counter_value
|
||||
} else {
|
||||
show_cluster_status
|
||||
@@ -284,12 +280,12 @@ start_server {} {
|
||||
set sync_partial_err [status $R($master_id) sync_partial_err]
|
||||
catch {
|
||||
$R($slave_id) config rewrite
|
||||
restart_server [expr {0-$slave_id}] true
|
||||
restart_server [expr {0-$slave_id}] true false
|
||||
set R($slave_id) [srv [expr {0-$slave_id}] client]
|
||||
}
|
||||
# note: just waiting for connected_slaves==4 has a race condition since
|
||||
# we might do the check before the master realized that the slave disconnected
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[status $R($master_id) sync_partial_ok] == $sync_partial + 1
|
||||
} else {
|
||||
puts "prev sync_full: $sync_count"
|
||||
@@ -315,7 +311,7 @@ start_server {} {
|
||||
$R($master_id) EVALSHA e6e0b547500efcec21eddb619ac3724081afee89 0
|
||||
|
||||
# Wait for the two to sync
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[$R($master_id) debug digest] == [$R($slave_id) debug digest]
|
||||
} else {
|
||||
show_cluster_status
|
||||
@@ -333,7 +329,7 @@ start_server {} {
|
||||
|
||||
catch {
|
||||
$R($slave_id) config rewrite
|
||||
restart_server [expr {0-$slave_id}] true
|
||||
restart_server [expr {0-$slave_id}] true false
|
||||
set R($slave_id) [srv [expr {0-$slave_id}] client]
|
||||
}
|
||||
|
||||
@@ -343,7 +339,7 @@ start_server {} {
|
||||
if {[catch {
|
||||
$R($slave_id) slaveof $master_host $master_port
|
||||
}]} {
|
||||
after 2000
|
||||
after 1000
|
||||
} else {
|
||||
break
|
||||
}
|
||||
@@ -351,7 +347,7 @@ start_server {} {
|
||||
}
|
||||
|
||||
# The master should be back at 4 slaves eventually
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[status $R($master_id) connected_slaves] == 4
|
||||
} else {
|
||||
show_cluster_status
|
||||
@@ -362,7 +358,7 @@ start_server {} {
|
||||
|
||||
# However if the slave started with the full state of the
|
||||
# scripting engine, we should now have the same digest.
|
||||
wait_for_condition 50 2000 {
|
||||
wait_for_condition 50 1000 {
|
||||
[$R($master_id) debug digest] == [$R($slave_id) debug digest]
|
||||
} else {
|
||||
show_cluster_status
|
||||
@@ -371,7 +367,8 @@ start_server {} {
|
||||
}
|
||||
|
||||
if {$no_exit} {
|
||||
while 1 { puts -nonewline .; flush stdout; after 2000}
|
||||
while 1 { puts -nonewline .; flush stdout; after 1000}
|
||||
}
|
||||
|
||||
}}}}}
|
||||
|
||||
+126
-3
@@ -1,3 +1,5 @@
|
||||
tags {"rdb"} {
|
||||
|
||||
set server_path [tmpdir "server.rdb-encoding-test"]
|
||||
|
||||
# Copy RDB with different encodings in server path
|
||||
@@ -49,13 +51,23 @@ start_server [list overrides [list "dir" $server_path] keep_persistence true] {
|
||||
}
|
||||
}
|
||||
r xgroup create stream mygroup 0
|
||||
r xreadgroup GROUP mygroup Alice COUNT 1 STREAMS stream >
|
||||
set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >]
|
||||
r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0]
|
||||
r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0]
|
||||
set digest [r debug digest]
|
||||
r config set sanitize-dump-payload no
|
||||
r debug reload
|
||||
set newdigest [r debug digest]
|
||||
assert {$digest eq $newdigest}
|
||||
r del stream
|
||||
}
|
||||
test {Test RDB stream encoding - sanitize dump} {
|
||||
r config set sanitize-dump-payload yes
|
||||
r debug reload
|
||||
set newdigest [r debug digest]
|
||||
assert {$digest eq $newdigest}
|
||||
}
|
||||
# delete the stream, maybe valgrind will find something
|
||||
r del stream
|
||||
}
|
||||
|
||||
# Helper function to start a server and kill it, just to check the error
|
||||
@@ -155,7 +167,7 @@ test {client freed during loading} {
|
||||
# 100mb of rdb, 100k keys will load in more than 1 second
|
||||
r debug populate 100000 key 1000
|
||||
|
||||
restart_server 0 false
|
||||
restart_server 0 false false
|
||||
|
||||
# make sure it's still loading
|
||||
assert_equal [s loading] 1
|
||||
@@ -189,3 +201,114 @@ test {client freed during loading} {
|
||||
exec kill [srv 0 pid]
|
||||
}
|
||||
}
|
||||
|
||||
# Our COW metrics (Private_Dirty) work only on Linux
|
||||
set system_name [string tolower [exec uname -s]]
|
||||
if {$system_name eq {linux}} {
|
||||
|
||||
start_server {overrides {save ""}} {
|
||||
test {Test child sending info} {
|
||||
# make sure that rdb_last_cow_size and current_cow_size are zero (the test using new server),
|
||||
# so that the comparisons during the test will be valid
|
||||
assert {[s current_cow_size] == 0}
|
||||
assert {[s current_save_keys_processed] == 0}
|
||||
assert {[s current_save_keys_total] == 0}
|
||||
|
||||
assert {[s rdb_last_cow_size] == 0}
|
||||
|
||||
# using a 200us delay, the bgsave is empirically taking about 10 seconds.
|
||||
# we need it to take more than some 5 seconds, since redis only report COW once a second.
|
||||
r config set rdb-key-save-delay 200
|
||||
r config set loglevel debug
|
||||
|
||||
# populate the db with 10k keys of 4k each
|
||||
set rd [redis_deferring_client 0]
|
||||
set size 4096
|
||||
set cmd_count 10000
|
||||
for {set k 0} {$k < $cmd_count} {incr k} {
|
||||
$rd set key$k [string repeat A $size]
|
||||
}
|
||||
|
||||
for {set k 0} {$k < $cmd_count} {incr k} {
|
||||
catch { $rd read }
|
||||
}
|
||||
|
||||
$rd close
|
||||
|
||||
# start background rdb save
|
||||
r bgsave
|
||||
|
||||
set current_save_keys_total [s current_save_keys_total]
|
||||
if {$::verbose} {
|
||||
puts "Keys before bgsave start: current_save_keys_total"
|
||||
}
|
||||
|
||||
# on each iteration, we will write some key to the server to trigger copy-on-write, and
|
||||
# wait to see that it reflected in INFO.
|
||||
set iteration 1
|
||||
while 1 {
|
||||
# take samples before writing new data to the server
|
||||
set cow_size [s current_cow_size]
|
||||
if {$::verbose} {
|
||||
puts "COW info before copy-on-write: $cow_size"
|
||||
}
|
||||
|
||||
set keys_processed [s current_save_keys_processed]
|
||||
if {$::verbose} {
|
||||
puts "current_save_keys_processed info : $keys_processed"
|
||||
}
|
||||
|
||||
# trigger copy-on-write
|
||||
r setrange key$iteration 0 [string repeat B $size]
|
||||
|
||||
# wait to see that current_cow_size value updated (as long as the child is in progress)
|
||||
wait_for_condition 80 100 {
|
||||
[s rdb_bgsave_in_progress] == 0 ||
|
||||
[s current_cow_size] >= $cow_size + $size &&
|
||||
[s current_save_keys_processed] > $keys_processed &&
|
||||
[s current_fork_perc] > 0
|
||||
} else {
|
||||
if {$::verbose} {
|
||||
puts "COW info on fail: [s current_cow_size]"
|
||||
puts [exec tail -n 100 < [srv 0 stdout]]
|
||||
}
|
||||
fail "COW info wasn't reported"
|
||||
}
|
||||
|
||||
# assert that $keys_processed is not greater than total keys.
|
||||
assert_morethan_equal $current_save_keys_total $keys_processed
|
||||
|
||||
# for no accurate, stop after 2 iterations
|
||||
if {!$::accurate && $iteration == 2} {
|
||||
break
|
||||
}
|
||||
|
||||
# stop iterating if the bgsave completed
|
||||
if { [s rdb_bgsave_in_progress] == 0 } {
|
||||
break
|
||||
}
|
||||
|
||||
incr iteration 1
|
||||
}
|
||||
|
||||
# make sure we saw report of current_cow_size
|
||||
if {$iteration < 2 && $::verbose} {
|
||||
puts [exec tail -n 100 < [srv 0 stdout]]
|
||||
}
|
||||
assert_morethan_equal $iteration 2
|
||||
|
||||
# if bgsave completed, check that rdb_last_cow_size (fork exit report)
|
||||
# is at least 90% of last rdb_active_cow_size.
|
||||
if { [s rdb_bgsave_in_progress] == 0 } {
|
||||
set final_cow [s rdb_last_cow_size]
|
||||
set cow_size [expr $cow_size * 0.9]
|
||||
if {$final_cow < $cow_size && $::verbose} {
|
||||
puts [exec tail -n 100 < [srv 0 stdout]]
|
||||
}
|
||||
assert_morethan_equal $final_cow $cow_size
|
||||
}
|
||||
}
|
||||
}
|
||||
} ;# system_name
|
||||
|
||||
} ;# tags
|
||||
@@ -0,0 +1,168 @@
|
||||
source tests/support/benchmark.tcl
|
||||
|
||||
|
||||
proc cmdstat {cmd} {
|
||||
return [cmdrstat $cmd r]
|
||||
}
|
||||
|
||||
start_server {tags {"benchmark network"}} {
|
||||
start_server {} {
|
||||
set master_host [srv 0 host]
|
||||
set master_port [srv 0 port]
|
||||
|
||||
test {benchmark: set,get} {
|
||||
r config resetstat
|
||||
r flushall
|
||||
set cmd [redisbenchmark $master_host $master_port "-c 5 -n 10 -e -t set,get"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=10,*} [cmdstat set]
|
||||
assert_match {*calls=10,*} [cmdstat get]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat lrange]
|
||||
}
|
||||
|
||||
test {benchmark: full test suite} {
|
||||
r config resetstat
|
||||
set cmd [redisbenchmark $master_host $master_port "-c 10 -n 100 -e"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
# ping total calls are 2*issued commands per test due to PING_INLINE and PING_MBULK
|
||||
assert_match {*calls=200,*} [cmdstat ping]
|
||||
assert_match {*calls=100,*} [cmdstat set]
|
||||
assert_match {*calls=100,*} [cmdstat get]
|
||||
assert_match {*calls=100,*} [cmdstat incr]
|
||||
# lpush total calls are 2*issued commands per test due to the lrange tests
|
||||
assert_match {*calls=200,*} [cmdstat lpush]
|
||||
assert_match {*calls=100,*} [cmdstat rpush]
|
||||
assert_match {*calls=100,*} [cmdstat lpop]
|
||||
assert_match {*calls=100,*} [cmdstat rpop]
|
||||
assert_match {*calls=100,*} [cmdstat sadd]
|
||||
assert_match {*calls=100,*} [cmdstat hset]
|
||||
assert_match {*calls=100,*} [cmdstat spop]
|
||||
assert_match {*calls=100,*} [cmdstat zadd]
|
||||
assert_match {*calls=100,*} [cmdstat zpopmin]
|
||||
assert_match {*calls=400,*} [cmdstat lrange]
|
||||
assert_match {*calls=100,*} [cmdstat mset]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat rpoplpush]
|
||||
}
|
||||
|
||||
test {benchmark: multi-thread set,get} {
|
||||
r config resetstat
|
||||
r flushall
|
||||
set cmd [redisbenchmark $master_host $master_port "--threads 10 -c 5 -n 10 -e -t set,get"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=10,*} [cmdstat set]
|
||||
assert_match {*calls=10,*} [cmdstat get]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat lrange]
|
||||
|
||||
# ensure only one key was populated
|
||||
assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
|
||||
}
|
||||
|
||||
test {benchmark: pipelined full set,get} {
|
||||
r config resetstat
|
||||
r flushall
|
||||
set cmd [redisbenchmark $master_host $master_port "-P 5 -c 10 -n 10010 -e -t set,get"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=10010,*} [cmdstat set]
|
||||
assert_match {*calls=10010,*} [cmdstat get]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat lrange]
|
||||
|
||||
# ensure only one key was populated
|
||||
assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
|
||||
}
|
||||
|
||||
test {benchmark: arbitrary command} {
|
||||
r config resetstat
|
||||
r flushall
|
||||
set cmd [redisbenchmark $master_host $master_port "-c 5 -n 150 -e INCRBYFLOAT mykey 10.0"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=150,*} [cmdstat incrbyfloat]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat get]
|
||||
|
||||
# ensure only one key was populated
|
||||
assert_match {1} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
|
||||
}
|
||||
|
||||
test {benchmark: keyspace length} {
|
||||
r flushall
|
||||
r config resetstat
|
||||
set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000"]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=1000,*} [cmdstat set]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat get]
|
||||
|
||||
# ensure the keyspace has the desired size
|
||||
assert_match {50} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
|
||||
}
|
||||
|
||||
# tls specific tests
|
||||
if {$::tls} {
|
||||
test {benchmark: specific tls-ciphers} {
|
||||
r flushall
|
||||
r config resetstat
|
||||
set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphers \"DEFAULT:-AES128-SHA256\""]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
assert_match {*calls=1000,*} [cmdstat set]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat get]
|
||||
}
|
||||
|
||||
test {benchmark: specific tls-ciphersuites} {
|
||||
r flushall
|
||||
r config resetstat
|
||||
set ciphersuites_supported 1
|
||||
set cmd [redisbenchmark $master_host $master_port "-r 50 -t set -n 1000 --tls-ciphersuites \"TLS_AES_128_GCM_SHA256\""]
|
||||
if {[catch { exec {*}$cmd } error]} {
|
||||
set first_line [lindex [split $error "\n"] 0]
|
||||
if {[string match "*Invalid option*" $first_line]} {
|
||||
set ciphersuites_supported 0
|
||||
if {$::verbose} {
|
||||
puts "Skipping test, TLSv1.3 not supported."
|
||||
}
|
||||
} else {
|
||||
puts [colorstr red "keydb-benchmark non zero code. first line: $first_line"]
|
||||
fail "keydb-benchmark non zero code. first line: $first_line"
|
||||
}
|
||||
}
|
||||
if {$ciphersuites_supported} {
|
||||
assert_match {*calls=1000,*} [cmdstat set]
|
||||
# assert one of the non benchmarked commands is not present
|
||||
assert_match {} [cmdstat get]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ start_server {tags {"cli"}} {
|
||||
test_interactive_cli "INFO response should be printed raw" {
|
||||
set lines [split [run_command $fd info] "\n"]
|
||||
foreach line $lines {
|
||||
assert [regexp {^$|^#|^[a-z0-9_]+:.+} $line]
|
||||
assert [regexp {^$|^#|^[^#:]+:} $line]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,17 +39,19 @@ start_server {tags {"repl"}} {
|
||||
}
|
||||
|
||||
test {No write if min-slaves-max-lag is > of the slave lag} {
|
||||
r -1 deferred 1
|
||||
r config set min-slaves-to-write 1
|
||||
r config set min-slaves-max-lag 2
|
||||
r -1 debug sleep 6
|
||||
exec kill -SIGSTOP [srv -1 pid]
|
||||
assert {[r set foo 12345] eq {OK}}
|
||||
after 4000
|
||||
wait_for_condition 100 100 {
|
||||
[catch {r set foo 12345}] != 0
|
||||
} else {
|
||||
fail "Master didn't become readonly"
|
||||
}
|
||||
catch {r set foo 12345} err
|
||||
assert {[r -1 read] eq {OK}}
|
||||
r -1 deferred 0
|
||||
set err
|
||||
} {NOREPLICAS*}
|
||||
assert_match {NOREPLICAS*} $err
|
||||
}
|
||||
exec kill -SIGCONT [srv -1 pid]
|
||||
|
||||
test {min-slaves-to-write is ignored by slaves} {
|
||||
r config set min-slaves-to-write 1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
start_server {tags {"repl"}} {
|
||||
start_server {tags {"repl network"}} {
|
||||
start_server {} {
|
||||
|
||||
set master [srv -1 client]
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
start_server {tags {"repl"} overrides {hz 100}} {
|
||||
proc log_file_matches {log pattern} {
|
||||
set fp [open $log r]
|
||||
set content [read $fp]
|
||||
close $fp
|
||||
string match $pattern $content
|
||||
}
|
||||
|
||||
start_server {tags {"repl network"}} {
|
||||
set slave [srv 0 client]
|
||||
set slave_host [srv 0 host]
|
||||
set slave_port [srv 0 port]
|
||||
@@ -70,7 +77,29 @@ start_server {tags {"repl"}} {
|
||||
assert_equal [$A debug digest] [$B debug digest]
|
||||
}
|
||||
|
||||
test {GETSET replication} {
|
||||
$A config resetstat
|
||||
$A config set loglevel debug
|
||||
$B config set loglevel debug
|
||||
r set test foo
|
||||
assert_equal [r getset test bar] foo
|
||||
wait_for_condition 500 10 {
|
||||
[$A get test] eq "bar"
|
||||
} else {
|
||||
fail "getset wasn't propagated"
|
||||
}
|
||||
assert_equal [r set test vaz get] bar
|
||||
wait_for_condition 500 10 {
|
||||
[$A get test] eq "vaz"
|
||||
} else {
|
||||
fail "set get wasn't propagated"
|
||||
}
|
||||
assert_match {*calls=3,*} [cmdrstat set $A]
|
||||
assert_match {} [cmdrstat getset $A]
|
||||
}
|
||||
|
||||
test {BRPOPLPUSH replication, when blocking against empty list} {
|
||||
$A config resetstat
|
||||
set rd [redis_deferring_client]
|
||||
$rd brpoplpush a b 5
|
||||
r lpush a foo
|
||||
@@ -79,9 +108,12 @@ start_server {tags {"repl"}} {
|
||||
} else {
|
||||
fail "Master and replica have different digest: [$A debug digest] VS [$B debug digest]"
|
||||
}
|
||||
assert_match {*calls=1,*} [cmdrstat rpoplpush $A]
|
||||
assert_match {} [cmdrstat lmove $A]
|
||||
}
|
||||
|
||||
test {BRPOPLPUSH replication, list exists} {
|
||||
$A config resetstat
|
||||
set rd [redis_deferring_client]
|
||||
r lpush c 1
|
||||
r lpush c 2
|
||||
@@ -89,6 +121,39 @@ start_server {tags {"repl"}} {
|
||||
$rd brpoplpush c d 5
|
||||
after 1000
|
||||
assert_equal [$A debug digest] [$B debug digest]
|
||||
assert_match {*calls=1,*} [cmdrstat rpoplpush $A]
|
||||
assert_match {} [cmdrstat lmove $A]
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "BLMOVE ($wherefrom, $whereto) replication, when blocking against empty list" {
|
||||
$A config resetstat
|
||||
set rd [redis_deferring_client]
|
||||
$rd blmove a b $wherefrom $whereto 5
|
||||
r lpush a foo
|
||||
wait_for_condition 50 100 {
|
||||
[$A debug digest] eq [$B debug digest]
|
||||
} else {
|
||||
fail "Master and replica have different digest: [$A debug digest] VS [$B debug digest]"
|
||||
}
|
||||
assert_match {*calls=1,*} [cmdrstat lmove $A]
|
||||
assert_match {} [cmdrstat rpoplpush $A]
|
||||
}
|
||||
|
||||
test "BLMOVE ($wherefrom, $whereto) replication, list exists" {
|
||||
$A config resetstat
|
||||
set rd [redis_deferring_client]
|
||||
r lpush c 1
|
||||
r lpush c 2
|
||||
r lpush c 3
|
||||
$rd blmove c d $wherefrom $whereto 5
|
||||
after 1000
|
||||
assert_equal [$A debug digest] [$B debug digest]
|
||||
assert_match {*calls=1,*} [cmdrstat lmove $A]
|
||||
assert_match {} [cmdrstat rpoplpush $A]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test {BLPOP followed by role change, issue #2473} {
|
||||
@@ -400,7 +465,12 @@ test {diskless loading short read} {
|
||||
$master config set repl-diskless-sync yes
|
||||
$master config set rdbcompression no
|
||||
$replica config set repl-diskless-load swapdb
|
||||
$master config set hz 500
|
||||
$replica config set hz 500
|
||||
$master config set dynamic-hz no
|
||||
$replica config set dynamic-hz no
|
||||
# Try to fill the master with all types of data types / encodings
|
||||
set start [clock clicks -milliseconds]
|
||||
for {set k 0} {$k < 3} {incr k} {
|
||||
for {set i 0} {$i < 10} {incr i} {
|
||||
r set "$k int_$i" [expr {int(rand()*10000)}]
|
||||
@@ -422,14 +492,21 @@ test {diskless loading short read} {
|
||||
}
|
||||
}
|
||||
|
||||
if {$::verbose} {
|
||||
set end [clock clicks -milliseconds]
|
||||
set duration [expr $end - $start]
|
||||
puts "filling took $duration ms (TODO: use pipeline)"
|
||||
set start [clock clicks -milliseconds]
|
||||
}
|
||||
|
||||
# Start the replication process...
|
||||
set loglines [count_log_lines -1]
|
||||
$master config set repl-diskless-sync-delay 0
|
||||
$replica replicaof $master_host $master_port
|
||||
|
||||
# kill the replication at various points
|
||||
set attempts 3
|
||||
if {$::accurate} { set attempts 10 }
|
||||
set attempts 100
|
||||
if {$::accurate} { set attempts 500 }
|
||||
for {set i 0} {$i < $attempts} {incr i} {
|
||||
# wait for the replica to start reading the rdb
|
||||
# using the log file since the replica only responds to INFO once in 2mb
|
||||
@@ -462,6 +539,11 @@ test {diskless loading short read} {
|
||||
fail "Replica didn't disconnect"
|
||||
}
|
||||
}
|
||||
if {$::verbose} {
|
||||
set end [clock clicks -milliseconds]
|
||||
set duration [expr $end - $start]
|
||||
puts "test took $duration ms"
|
||||
}
|
||||
# enable fast shutdown
|
||||
$master config set rdb-key-save-delay 0
|
||||
}
|
||||
@@ -635,6 +717,47 @@ start_server {tags {"repl"}} {
|
||||
}
|
||||
}
|
||||
|
||||
test "diskless replication child being killed is collected" {
|
||||
# when diskless master is waiting for the replica to become writable
|
||||
# it removes the read event from the rdb pipe so if the child gets killed
|
||||
# the replica will hung. and the master may not collect the pid with wait3
|
||||
start_server {tags {"repl"}} {
|
||||
set master [srv 0 client]
|
||||
set master_host [srv 0 host]
|
||||
set master_port [srv 0 port]
|
||||
set master_pid [srv 0 pid]
|
||||
$master config set repl-diskless-sync yes
|
||||
$master config set repl-diskless-sync-delay 0
|
||||
# put enough data in the db that the rdb file will be bigger than the socket buffers
|
||||
$master debug populate 20000 test 10000
|
||||
$master config set rdbcompression no
|
||||
start_server {} {
|
||||
set replica [srv 0 client]
|
||||
set loglines [count_log_lines 0]
|
||||
$replica config set repl-diskless-load swapdb
|
||||
$replica config set key-load-delay 1000000
|
||||
$replica replicaof $master_host $master_port
|
||||
|
||||
# wait for the replicas to start reading the rdb
|
||||
wait_for_log_messages 0 {"*Loading DB in memory*"} $loglines 800 10
|
||||
|
||||
# wait to be sure the eplica is hung and the master is blocked on write
|
||||
after 500
|
||||
|
||||
# simulate the OOM killer or anyone else kills the child
|
||||
set fork_child_pid [get_child_pid -1]
|
||||
exec kill -9 $fork_child_pid
|
||||
|
||||
# wait for the parent to notice the child have exited
|
||||
wait_for_condition 50 100 {
|
||||
[s -1 rdb_bgsave_in_progress] == 0
|
||||
} else {
|
||||
fail "rdb child didn't terminate"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test {replicaof right after disconnection} {
|
||||
# this is a rare race condition that was reproduced sporadically by the psync2 unit.
|
||||
# see details in #7205
|
||||
@@ -686,3 +809,68 @@ test {replicaof right after disconnection} {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test {Kill rdb child process if its dumping RDB is not useful} {
|
||||
start_server {tags {"repl"}} {
|
||||
set slave1 [srv 0 client]
|
||||
start_server {} {
|
||||
set slave2 [srv 0 client]
|
||||
start_server {} {
|
||||
set master [srv 0 client]
|
||||
set master_host [srv 0 host]
|
||||
set master_port [srv 0 port]
|
||||
for {set i 0} {$i < 10} {incr i} {
|
||||
$master set $i $i
|
||||
}
|
||||
# Generating RDB will cost 10s(10 * 1s)
|
||||
$master config set rdb-key-save-delay 1000000
|
||||
$master config set repl-diskless-sync no
|
||||
$master config set save ""
|
||||
|
||||
$slave1 slaveof $master_host $master_port
|
||||
$slave2 slaveof $master_host $master_port
|
||||
|
||||
# Wait for starting child
|
||||
wait_for_condition 50 100 {
|
||||
([s 0 rdb_bgsave_in_progress] == 1) &&
|
||||
([string match "*wait_bgsave*" [s 0 slave0]]) &&
|
||||
([string match "*wait_bgsave*" [s 0 slave1]])
|
||||
} else {
|
||||
fail "rdb child didn't start"
|
||||
}
|
||||
|
||||
# Slave1 disconnect with master
|
||||
$slave1 slaveof no one
|
||||
# Shouldn't kill child since another slave wait for rdb
|
||||
after 100
|
||||
assert {[s 0 rdb_bgsave_in_progress] == 1}
|
||||
|
||||
# Slave2 disconnect with master
|
||||
$slave2 slaveof no one
|
||||
# Should kill child
|
||||
wait_for_condition 20 10 {
|
||||
[s 0 rdb_bgsave_in_progress] eq 0
|
||||
} else {
|
||||
fail "can't kill rdb child"
|
||||
}
|
||||
|
||||
# If have save parameters, won't kill child
|
||||
$master config set save "900 1"
|
||||
$slave1 slaveof $master_host $master_port
|
||||
$slave2 slaveof $master_host $master_port
|
||||
wait_for_condition 50 100 {
|
||||
([s 0 rdb_bgsave_in_progress] == 1) &&
|
||||
([string match "*wait_bgsave*" [s 0 slave0]]) &&
|
||||
([string match "*wait_bgsave*" [s 0 slave1]])
|
||||
} else {
|
||||
fail "rdb child didn't start"
|
||||
}
|
||||
$slave1 slaveof no one
|
||||
$slave2 slaveof no one
|
||||
after 200
|
||||
assert {[s 0 rdb_bgsave_in_progress] == 1}
|
||||
catch {$master shutdown nosave}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user