2010-05-14 11:31:11 -04:00
|
|
|
proc randstring {min max {type binary}} {
|
|
|
|
set len [expr {$min+int(rand()*($max-$min+1))}]
|
|
|
|
set output {}
|
|
|
|
if {$type eq {binary}} {
|
|
|
|
set minval 0
|
|
|
|
set maxval 255
|
|
|
|
} elseif {$type eq {alpha}} {
|
|
|
|
set minval 48
|
|
|
|
set maxval 122
|
|
|
|
} elseif {$type eq {compr}} {
|
|
|
|
set minval 48
|
|
|
|
set maxval 52
|
|
|
|
}
|
|
|
|
while {$len} {
|
|
|
|
append output [format "%c" [expr {$minval+int(rand()*($maxval-$minval+1))}]]
|
|
|
|
incr len -1
|
|
|
|
}
|
|
|
|
return $output
|
|
|
|
}
|
|
|
|
|
|
|
|
# Useful for some test
|
|
|
|
proc zlistAlikeSort {a b} {
|
|
|
|
if {[lindex $a 0] > [lindex $b 0]} {return 1}
|
|
|
|
if {[lindex $a 0] < [lindex $b 0]} {return -1}
|
|
|
|
string compare [lindex $a 1] [lindex $b 1]
|
|
|
|
}
|
|
|
|
|
2010-05-15 17:48:08 -04:00
|
|
|
# Return all log lines starting with the first line that contains a warning.
|
|
|
|
# Generally, this will be an assertion error with a stack trace.
|
|
|
|
proc warnings_from_file {filename} {
|
|
|
|
set lines [split [exec cat $filename] "\n"]
|
|
|
|
set matched 0
|
2012-05-22 07:13:24 -04:00
|
|
|
set logall 0
|
2010-05-15 17:48:08 -04:00
|
|
|
set result {}
|
|
|
|
foreach line $lines {
|
2012-05-22 07:13:24 -04:00
|
|
|
if {[string match {*REDIS BUG REPORT START*} $line]} {
|
|
|
|
set logall 1
|
|
|
|
}
|
2010-05-15 17:48:08 -04:00
|
|
|
if {[regexp {^\[\d+\]\s+\d+\s+\w+\s+\d{2}:\d{2}:\d{2} \#} $line]} {
|
|
|
|
set matched 1
|
|
|
|
}
|
2012-05-22 07:13:24 -04:00
|
|
|
if {$logall || $matched} {
|
2010-05-15 17:48:08 -04:00
|
|
|
lappend result $line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
join $result "\n"
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:48:57 -04:00
|
|
|
# Return value for INFO property
|
|
|
|
proc status {r property} {
|
2010-07-28 08:08:46 -04:00
|
|
|
if {[regexp "\r\n$property:(.*?)\r\n" [{*}$r info] _ value]} {
|
2010-05-14 14:48:57 -04:00
|
|
|
set _ $value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:31:11 -04:00
|
|
|
proc waitForBgsave r {
|
|
|
|
while 1 {
|
2012-05-25 09:20:59 -04:00
|
|
|
if {[status r rdb_bgsave_in_progress] eq 1} {
|
2010-12-10 10:13:21 -05:00
|
|
|
if {$::verbose} {
|
|
|
|
puts -nonewline "\nWaiting for background save to finish... "
|
|
|
|
flush stdout
|
|
|
|
}
|
2010-05-14 11:31:11 -04:00
|
|
|
after 1000
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc waitForBgrewriteaof r {
|
|
|
|
while 1 {
|
2012-05-25 09:20:59 -04:00
|
|
|
if {[status r aof_rewrite_in_progress] eq 1} {
|
2010-12-10 10:13:21 -05:00
|
|
|
if {$::verbose} {
|
|
|
|
puts -nonewline "\nWaiting for background AOF rewrite to finish... "
|
|
|
|
flush stdout
|
|
|
|
}
|
2010-05-14 11:31:11 -04:00
|
|
|
after 1000
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:50:58 -04:00
|
|
|
proc wait_for_sync r {
|
|
|
|
while 1 {
|
2012-06-02 17:29:57 -04:00
|
|
|
if {[status $r master_link_status] eq "down"} {
|
2010-05-14 14:50:58 -04:00
|
|
|
after 10
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-11 02:22:42 -05:00
|
|
|
proc wait_for_ofs_sync {r1 r2} {
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[status $r1 master_repl_offset] eq [status $r2 master_repl_offset]
|
|
|
|
} else {
|
|
|
|
fail "replica didn't sync in time"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 04:20:02 -04:00
|
|
|
proc wait_done_loading r {
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[catch {$r ping} e] == 0
|
|
|
|
} else {
|
|
|
|
fail "Loading DB is taking too much time."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 01:28:22 -04:00
|
|
|
# count current log lines in server's stdout
|
|
|
|
proc count_log_lines {srv_idx} {
|
2020-12-08 09:22:16 -05:00
|
|
|
set _ [string trim [exec wc -l < [srv $srv_idx stdout]]]
|
2020-07-10 01:28:22 -04:00
|
|
|
}
|
|
|
|
|
Sanitize dump payload: ziplist, listpack, zipmap, intset, stream
When loading an encoded payload we will at least do a shallow validation to
check that the size that's encoded in the payload matches the size of the
allocation.
This let's us later use this encoded size to make sure the various offsets
inside encoded payload don't reach outside the allocation, if they do, we'll
assert/panic, but at least we won't segfault or smear memory.
We can also do 'deep' validation which runs on all the records of the encoded
payload and validates that they don't contain invalid offsets. This lets us
detect corruptions early and reject a RESTORE command rather than accepting
it and asserting (crashing) later when accessing that payload via some command.
configuration:
- adding ACL flag skip-sanitize-payload
- adding config sanitize-dump-payload [yes/no/clients]
For now, we don't have a good way to ensure MIGRATE in cluster resharding isn't
being slowed down by these sanitation, so i'm setting the default value to `no`,
but later on it should be set to `clients` by default.
changes:
- changing rdbReportError not to `exit` in RESTORE command
- adding a new stat to be able to later check if cluster MIGRATE isn't being
slowed down by sanitation.
2020-08-13 09:41:05 -04:00
|
|
|
# returns the number of times a line with that pattern appears in a file
|
|
|
|
proc count_message_lines {file pattern} {
|
|
|
|
set res 0
|
|
|
|
# exec fails when grep exists with status other than 0 (when the patter wasn't found)
|
|
|
|
catch {
|
2020-12-08 09:22:16 -05:00
|
|
|
set res [string trim [exec grep $pattern $file 2> /dev/null | wc -l]]
|
Sanitize dump payload: ziplist, listpack, zipmap, intset, stream
When loading an encoded payload we will at least do a shallow validation to
check that the size that's encoded in the payload matches the size of the
allocation.
This let's us later use this encoded size to make sure the various offsets
inside encoded payload don't reach outside the allocation, if they do, we'll
assert/panic, but at least we won't segfault or smear memory.
We can also do 'deep' validation which runs on all the records of the encoded
payload and validates that they don't contain invalid offsets. This lets us
detect corruptions early and reject a RESTORE command rather than accepting
it and asserting (crashing) later when accessing that payload via some command.
configuration:
- adding ACL flag skip-sanitize-payload
- adding config sanitize-dump-payload [yes/no/clients]
For now, we don't have a good way to ensure MIGRATE in cluster resharding isn't
being slowed down by these sanitation, so i'm setting the default value to `no`,
but later on it should be set to `clients` by default.
changes:
- changing rdbReportError not to `exit` in RESTORE command
- adding a new stat to be able to later check if cluster MIGRATE isn't being
slowed down by sanitation.
2020-08-13 09:41:05 -04:00
|
|
|
}
|
|
|
|
return $res
|
|
|
|
}
|
|
|
|
|
|
|
|
# returns the number of times a line with that pattern appears in the log
|
|
|
|
proc count_log_message {srv_idx pattern} {
|
|
|
|
set stdout [srv $srv_idx stdout]
|
|
|
|
return [count_message_lines $stdout $pattern]
|
|
|
|
}
|
|
|
|
|
2020-07-10 01:28:22 -04:00
|
|
|
# verify pattern exists in server's sdtout after a certain line number
|
|
|
|
proc verify_log_message {srv_idx pattern from_line} {
|
2020-07-28 04:15:29 -04:00
|
|
|
incr from_line
|
|
|
|
set result [exec tail -n +$from_line < [srv $srv_idx stdout]]
|
2020-07-10 01:28:22 -04:00
|
|
|
if {![string match $pattern $result]} {
|
|
|
|
error "assertion:expected message not found in log file: $pattern"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# wait for pattern to be found in server's stdout after certain line number
|
2020-07-28 04:15:29 -04:00
|
|
|
# return value is a list containing the line that matched the pattern and the line number
|
|
|
|
proc wait_for_log_messages {srv_idx patterns from_line maxtries delay} {
|
2019-07-16 04:00:34 -04:00
|
|
|
set retry $maxtries
|
2020-07-28 04:15:29 -04:00
|
|
|
set next_line [expr $from_line + 1] ;# searching form the line after
|
2019-07-16 04:00:34 -04:00
|
|
|
set stdout [srv $srv_idx stdout]
|
|
|
|
while {$retry} {
|
2020-10-26 05:55:24 -04:00
|
|
|
# re-read the last line (unless it's before to our first), last time we read it, it might have been incomplete
|
|
|
|
set next_line [expr $next_line - 1 > $from_line + 1 ? $next_line - 1 : $from_line + 1]
|
2020-07-28 04:15:29 -04:00
|
|
|
set result [exec tail -n +$next_line < $stdout]
|
2019-07-16 04:00:34 -04:00
|
|
|
set result [split $result "\n"]
|
|
|
|
foreach line $result {
|
2020-07-28 04:15:29 -04:00
|
|
|
foreach pattern $patterns {
|
|
|
|
if {[string match $pattern $line]} {
|
|
|
|
return [list $line $next_line]
|
|
|
|
}
|
2019-07-16 04:00:34 -04:00
|
|
|
}
|
2020-07-28 04:15:29 -04:00
|
|
|
incr next_line
|
2019-07-16 04:00:34 -04:00
|
|
|
}
|
|
|
|
incr retry -1
|
|
|
|
after $delay
|
|
|
|
}
|
|
|
|
if {$retry == 0} {
|
2020-10-22 04:34:54 -04:00
|
|
|
if {$::verbose} {
|
|
|
|
puts "content of $stdout from line: $from_line:"
|
|
|
|
puts [exec tail -n +$from_line < $stdout]
|
|
|
|
}
|
2020-07-28 04:15:29 -04:00
|
|
|
fail "log message of '$patterns' not found in $stdout after line: $from_line till line: [expr $next_line -1]"
|
2019-07-16 04:00:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 03:23:09 -04:00
|
|
|
# write line to server log file
|
|
|
|
proc write_log_line {srv_idx msg} {
|
|
|
|
set logfile [srv $srv_idx stdout]
|
|
|
|
set fd [open $logfile "a+"]
|
|
|
|
puts $fd "### $msg"
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|
2013-06-25 09:32:37 -04:00
|
|
|
# Random integer between 0 and max (excluded).
|
2010-05-14 11:31:11 -04:00
|
|
|
proc randomInt {max} {
|
|
|
|
expr {int(rand()*$max)}
|
|
|
|
}
|
|
|
|
|
2013-06-25 09:32:37 -04:00
|
|
|
# Random signed integer between -max and max (both extremes excluded).
|
2012-06-11 09:19:46 -04:00
|
|
|
proc randomSignedInt {max} {
|
|
|
|
set i [randomInt $max]
|
|
|
|
if {rand() > 0.5} {
|
|
|
|
set i -$i
|
|
|
|
}
|
|
|
|
return $i
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:31:11 -04:00
|
|
|
proc randpath args {
|
|
|
|
set path [expr {int(rand()*[llength $args])}]
|
|
|
|
uplevel 1 [lindex $args $path]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc randomValue {} {
|
|
|
|
randpath {
|
|
|
|
# Small enough to likely collide
|
2012-06-11 09:19:46 -04:00
|
|
|
randomSignedInt 1000
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
|
|
|
# 32 bit compressible signed/unsigned
|
2012-06-11 09:19:46 -04:00
|
|
|
randpath {randomSignedInt 2000000000} {randomSignedInt 4000000000}
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
|
|
|
# 64 bit
|
2012-06-11 09:19:46 -04:00
|
|
|
randpath {randomSignedInt 1000000000000}
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
|
|
|
# Random string
|
|
|
|
randpath {randstring 0 256 alpha} \
|
|
|
|
{randstring 0 256 compr} \
|
|
|
|
{randstring 0 256 binary}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc randomKey {} {
|
|
|
|
randpath {
|
|
|
|
# Small enough to likely collide
|
|
|
|
randomInt 1000
|
|
|
|
} {
|
|
|
|
# 32 bit compressible signed/unsigned
|
|
|
|
randpath {randomInt 2000000000} {randomInt 4000000000}
|
|
|
|
} {
|
|
|
|
# 64 bit
|
|
|
|
randpath {randomInt 1000000000000}
|
|
|
|
} {
|
|
|
|
# Random string
|
|
|
|
randpath {randstring 1 256 alpha} \
|
|
|
|
{randstring 1 256 compr}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-06 12:30:38 -04:00
|
|
|
proc findKeyWithType {r type} {
|
|
|
|
for {set j 0} {$j < 20} {incr j} {
|
2010-07-28 08:08:46 -04:00
|
|
|
set k [{*}$r randomkey]
|
2010-07-06 12:30:38 -04:00
|
|
|
if {$k eq {}} {
|
|
|
|
return {}
|
|
|
|
}
|
2010-07-28 08:08:46 -04:00
|
|
|
if {[{*}$r type $k] eq $type} {
|
2010-07-06 12:30:38 -04:00
|
|
|
return $k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
2010-08-03 07:38:39 -04:00
|
|
|
proc createComplexDataset {r ops {opt {}}} {
|
2010-05-14 11:31:11 -04:00
|
|
|
for {set j 0} {$j < $ops} {incr j} {
|
|
|
|
set k [randomKey]
|
2010-07-06 12:30:38 -04:00
|
|
|
set k2 [randomKey]
|
2010-05-14 11:31:11 -04:00
|
|
|
set f [randomValue]
|
|
|
|
set v [randomValue]
|
2010-08-03 07:38:39 -04:00
|
|
|
|
|
|
|
if {[lsearch -exact $opt useexpire] != -1} {
|
|
|
|
if {rand() < 0.1} {
|
|
|
|
{*}$r expire [randomKey] [randomInt 2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:31:11 -04:00
|
|
|
randpath {
|
|
|
|
set d [expr {rand()}]
|
|
|
|
} {
|
|
|
|
set d [expr {rand()}]
|
|
|
|
} {
|
|
|
|
set d [expr {rand()}]
|
|
|
|
} {
|
|
|
|
set d [expr {rand()}]
|
|
|
|
} {
|
|
|
|
set d [expr {rand()}]
|
|
|
|
} {
|
|
|
|
randpath {set d +inf} {set d -inf}
|
|
|
|
}
|
2010-07-28 08:08:46 -04:00
|
|
|
set t [{*}$r type $k]
|
2010-05-14 11:31:11 -04:00
|
|
|
|
|
|
|
if {$t eq {none}} {
|
|
|
|
randpath {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r set $k $v
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r lpush $k $v
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r sadd $k $v
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r zadd $k $d $v
|
2010-05-14 11:31:11 -04:00
|
|
|
} {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r hset $k $f $v
|
2010-07-06 12:30:38 -04:00
|
|
|
} {
|
2010-07-28 08:08:46 -04:00
|
|
|
{*}$r del $k
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
2010-07-28 08:08:46 -04:00
|
|
|
set t [{*}$r type $k]
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch $t {
|
|
|
|
{string} {
|
|
|
|
# Nothing to do
|
|
|
|
}
|
|
|
|
{list} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {{*}$r lpush $k $v} \
|
|
|
|
{{*}$r rpush $k $v} \
|
|
|
|
{{*}$r lrem $k 0 $v} \
|
|
|
|
{{*}$r rpop $k} \
|
|
|
|
{{*}$r lpop $k}
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
|
|
|
{set} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {{*}$r sadd $k $v} \
|
|
|
|
{{*}$r srem $k $v} \
|
2010-07-06 12:30:38 -04:00
|
|
|
{
|
2010-11-04 05:48:49 -04:00
|
|
|
set otherset [findKeyWithType {*}$r set]
|
2010-07-06 12:30:38 -04:00
|
|
|
if {$otherset ne {}} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {
|
|
|
|
{*}$r sunionstore $k2 $k $otherset
|
|
|
|
} {
|
|
|
|
{*}$r sinterstore $k2 $k $otherset
|
|
|
|
} {
|
|
|
|
{*}$r sdiffstore $k2 $k $otherset
|
|
|
|
}
|
2010-07-06 12:30:38 -04:00
|
|
|
}
|
|
|
|
}
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
|
|
|
{zset} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {{*}$r zadd $k $d $v} \
|
|
|
|
{{*}$r zrem $k $v} \
|
2010-07-06 12:30:38 -04:00
|
|
|
{
|
2010-11-04 05:48:49 -04:00
|
|
|
set otherzset [findKeyWithType {*}$r zset]
|
2010-07-06 12:30:38 -04:00
|
|
|
if {$otherzset ne {}} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {
|
|
|
|
{*}$r zunionstore $k2 2 $k $otherzset
|
|
|
|
} {
|
|
|
|
{*}$r zinterstore $k2 2 $k $otherzset
|
|
|
|
}
|
2010-07-06 12:30:38 -04:00
|
|
|
}
|
|
|
|
}
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
|
|
|
{hash} {
|
2010-07-28 08:08:46 -04:00
|
|
|
randpath {{*}$r hset $k $f $v} \
|
|
|
|
{{*}$r hdel $k $f}
|
2010-05-14 11:31:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-19 08:33:39 -04:00
|
|
|
|
|
|
|
proc formatCommand {args} {
|
|
|
|
set cmd "*[llength $args]\r\n"
|
|
|
|
foreach a $args {
|
|
|
|
append cmd "$[string length $a]\r\n$a\r\n"
|
|
|
|
}
|
|
|
|
set _ $cmd
|
|
|
|
}
|
2010-07-27 08:42:11 -04:00
|
|
|
|
|
|
|
proc csvdump r {
|
|
|
|
set o {}
|
2015-08-05 06:27:15 -04:00
|
|
|
for {set db 0} {$db < 16} {incr db} {
|
|
|
|
{*}$r select $db
|
|
|
|
foreach k [lsort [{*}$r keys *]] {
|
|
|
|
set type [{*}$r type $k]
|
|
|
|
append o [csvstring $db] , [csvstring $k] , [csvstring $type] ,
|
|
|
|
switch $type {
|
|
|
|
string {
|
|
|
|
append o [csvstring [{*}$r get $k]] "\n"
|
2010-07-27 08:42:11 -04:00
|
|
|
}
|
2015-08-05 06:27:15 -04:00
|
|
|
list {
|
|
|
|
foreach e [{*}$r lrange $k 0 -1] {
|
|
|
|
append o [csvstring $e] ,
|
|
|
|
}
|
|
|
|
append o "\n"
|
2010-07-27 08:42:11 -04:00
|
|
|
}
|
2015-08-05 06:27:15 -04:00
|
|
|
set {
|
|
|
|
foreach e [lsort [{*}$r smembers $k]] {
|
|
|
|
append o [csvstring $e] ,
|
|
|
|
}
|
|
|
|
append o "\n"
|
2010-07-27 08:42:11 -04:00
|
|
|
}
|
2015-08-05 06:27:15 -04:00
|
|
|
zset {
|
|
|
|
foreach e [{*}$r zrange $k 0 -1 withscores] {
|
|
|
|
append o [csvstring $e] ,
|
|
|
|
}
|
|
|
|
append o "\n"
|
2010-07-27 08:42:11 -04:00
|
|
|
}
|
2015-08-05 06:27:15 -04:00
|
|
|
hash {
|
|
|
|
set fields [{*}$r hgetall $k]
|
|
|
|
set newfields {}
|
|
|
|
foreach {k v} $fields {
|
|
|
|
lappend newfields [list $k $v]
|
|
|
|
}
|
|
|
|
set fields [lsort -index 0 $newfields]
|
|
|
|
foreach kv $fields {
|
|
|
|
append o [csvstring [lindex $kv 0]] ,
|
|
|
|
append o [csvstring [lindex $kv 1]] ,
|
|
|
|
}
|
|
|
|
append o "\n"
|
2010-07-27 08:42:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 06:27:15 -04:00
|
|
|
{*}$r select 9
|
2010-07-27 08:42:11 -04:00
|
|
|
return $o
|
|
|
|
}
|
|
|
|
|
|
|
|
proc csvstring s {
|
|
|
|
return "\"$s\""
|
|
|
|
}
|
2011-11-16 08:40:50 -05:00
|
|
|
|
|
|
|
proc roundFloat f {
|
|
|
|
format "%.10g" $f
|
|
|
|
}
|
2014-02-17 06:29:54 -05:00
|
|
|
|
2020-05-27 09:12:30 -04:00
|
|
|
set ::last_port_attempted 0
|
2020-05-26 04:00:48 -04:00
|
|
|
proc find_available_port {start count} {
|
2020-05-27 09:12:30 -04:00
|
|
|
set port [expr $::last_port_attempted + 1]
|
|
|
|
for {set attempts 0} {$attempts < $count} {incr attempts} {
|
|
|
|
if {$port < $start || $port >= $start+$count} {
|
|
|
|
set port $start
|
|
|
|
}
|
|
|
|
if {[catch {set fd1 [socket 127.0.0.1 $port]}] &&
|
|
|
|
[catch {set fd2 [socket 127.0.0.1 [expr $port+10000]]}]} {
|
|
|
|
set ::last_port_attempted $port
|
|
|
|
return $port
|
2014-02-17 06:29:54 -05:00
|
|
|
} else {
|
2014-06-30 06:07:26 -04:00
|
|
|
catch {
|
|
|
|
close $fd1
|
|
|
|
close $fd2
|
|
|
|
}
|
2014-02-17 06:29:54 -05:00
|
|
|
}
|
2020-05-27 09:12:30 -04:00
|
|
|
incr port
|
2014-02-17 06:29:54 -05:00
|
|
|
}
|
2020-05-27 09:12:30 -04:00
|
|
|
error "Can't find a non busy port in the $start-[expr {$start+$count-1}] range."
|
2014-02-17 06:29:54 -05:00
|
|
|
}
|
2014-02-17 11:36:50 -05:00
|
|
|
|
|
|
|
# Test if TERM looks like to support colors
|
|
|
|
proc color_term {} {
|
|
|
|
expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc colorstr {color str} {
|
|
|
|
if {[color_term]} {
|
|
|
|
set b 0
|
|
|
|
if {[string range $color 0 4] eq {bold-}} {
|
|
|
|
set b 1
|
|
|
|
set color [string range $color 5 end]
|
|
|
|
}
|
|
|
|
switch $color {
|
|
|
|
red {set colorcode {31}}
|
|
|
|
green {set colorcode {32}}
|
|
|
|
yellow {set colorcode {33}}
|
|
|
|
blue {set colorcode {34}}
|
|
|
|
magenta {set colorcode {35}}
|
|
|
|
cyan {set colorcode {36}}
|
|
|
|
white {set colorcode {37}}
|
|
|
|
default {set colorcode {37}}
|
|
|
|
}
|
|
|
|
if {$colorcode ne {}} {
|
2014-08-05 08:50:44 -04:00
|
|
|
return "\033\[$b;${colorcode};49m$str\033\[0m"
|
2014-02-17 11:36:50 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $str
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 05:24:59 -04:00
|
|
|
|
2020-08-14 09:05:34 -04:00
|
|
|
proc find_valgrind_errors {stderr on_termination} {
|
2020-09-06 04:11:49 -04:00
|
|
|
set fd [open $stderr]
|
|
|
|
set buf [read $fd]
|
|
|
|
close $fd
|
|
|
|
|
|
|
|
# Look for stack trace (" at 0x") and other errors (Invalid, Mismatched, etc).
|
|
|
|
# Look for "Warnings", but not the "set address range perms". These don't indicate any real concern.
|
2020-08-14 09:05:34 -04:00
|
|
|
# corrupt-dump unit, not sure why but it seems they don't indicate any real concern.
|
2020-09-06 04:11:49 -04:00
|
|
|
if {[regexp -- { at 0x} $buf] ||
|
|
|
|
[regexp -- {^(?=.*Warning)(?:(?!set address range perms).)*$} $buf] ||
|
|
|
|
[regexp -- {Invalid} $buf] ||
|
|
|
|
[regexp -- {Mismatched} $buf] ||
|
|
|
|
[regexp -- {uninitialized} $buf] ||
|
|
|
|
[regexp -- {has a fishy} $buf] ||
|
2020-08-14 09:05:34 -04:00
|
|
|
[regexp -- {overlap} $buf]} {
|
|
|
|
return $buf
|
|
|
|
}
|
|
|
|
|
|
|
|
# If the process didn't terminate yet, we can't look for the summary report
|
|
|
|
if {!$on_termination} {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
# Look for the absense of a leak free summary (happens when redis isn't terminated properly).
|
|
|
|
if {(![regexp -- {definitely lost: 0 bytes} $buf] &&
|
2020-09-06 04:11:49 -04:00
|
|
|
![regexp -- {no leaks are possible} $buf])} {
|
|
|
|
return $buf
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2014-07-10 05:24:59 -04:00
|
|
|
# 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]
|
2019-09-12 03:56:54 -04:00
|
|
|
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds $::tls &
|
2014-07-10 05:24:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Stop a process generating write load executed with start_write_load.
|
|
|
|
proc stop_write_load {handle} {
|
|
|
|
catch {exec /bin/kill -9 $handle}
|
|
|
|
}
|
2018-07-13 11:51:03 -04:00
|
|
|
|
2018-07-13 11:52:39 -04:00
|
|
|
proc K { x y } { set x }
|
|
|
|
|
2018-07-13 11:51:03 -04:00
|
|
|
# Shuffle a list. From Tcl wiki. Originally from Steve Cohen that improved
|
|
|
|
# other versions. Code should be under public domain.
|
|
|
|
proc lshuffle {list} {
|
|
|
|
set n [llength $list]
|
|
|
|
while {$n>0} {
|
|
|
|
set j [expr {int(rand()*$n)}]
|
|
|
|
lappend slist [lindex $list $j]
|
|
|
|
incr n -1
|
|
|
|
set temp [lindex $list $n]
|
|
|
|
set list [lreplace [K $list [set list {}]] $j $j $temp]
|
|
|
|
}
|
|
|
|
return $slist
|
|
|
|
}
|
2019-07-01 08:22:29 -04:00
|
|
|
|
|
|
|
# Execute a background process writing complex data for the specified number
|
|
|
|
# of ops to the specified Redis instance.
|
|
|
|
proc start_bg_complex_data {host port db ops} {
|
|
|
|
set tclsh [info nameofexecutable]
|
2019-09-12 03:56:54 -04:00
|
|
|
exec $tclsh tests/helpers/bg_complex_data.tcl $host $port $db $ops $::tls &
|
2019-07-01 08:22:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Stop a process generating write load executed with start_bg_complex_data.
|
|
|
|
proc stop_bg_complex_data {handle} {
|
|
|
|
catch {exec /bin/kill -9 $handle}
|
|
|
|
}
|
2020-09-03 01:47:29 -04:00
|
|
|
|
|
|
|
proc populate {num prefix size} {
|
|
|
|
set rd [redis_deferring_client]
|
|
|
|
for {set j 0} {$j < $num} {incr j} {
|
|
|
|
$rd set $prefix$j [string repeat A $size]
|
|
|
|
}
|
|
|
|
for {set j 0} {$j < $num} {incr j} {
|
|
|
|
$rd read
|
|
|
|
}
|
|
|
|
$rd close
|
|
|
|
}
|
if diskless repl child is killed, make sure to reap the pid (#7742)
Starting redis 6.0 and the changes we made to the diskless master to be
suitable for TLS, I made the master avoid reaping (wait3) the pid of the
child until we know all replicas are done reading their rdb.
I did that in order to avoid a state where the rdb_child_pid is -1 but
we don't yet want to start another fork (still busy serving that data to
replicas).
It turns out that the solution used so far was problematic in case the
fork child was being killed (e.g. by the kernel OOM killer), in that
case there's a chance that we currently disabled the read event on the
rdb pipe, since we're waiting for a replica to become writable again.
and in that scenario the master would have never realized the child
exited, and the replica will remain hung too.
Note that there's no mechanism to detect a hung replica while it's in
rdb transfer state.
The solution here is to add another pipe which is used by the parent to
tell the child it is safe to exit. this mean that when the child exits,
for whatever reason, it is safe to reap it.
Besides that, i'm re-introducing an adjustment to REPLCONF ACK which was
part of #6271 (Accelerate diskless master connections) but was dropped
when that PR was rebased after the TLS fork/pipe changes (5a47794).
Now that RdbPipeCleanup no longer calls checkChildrenDone, and the ACK
has chance to detect that the child exited, it should be the one to call
it so that we don't have to wait for cron (server.hz) to do that.
2020-09-06 09:43:57 -04:00
|
|
|
|
|
|
|
proc get_child_pid {idx} {
|
|
|
|
set pid [srv $idx pid]
|
2020-10-18 07:50:29 -04:00
|
|
|
if {[file exists "/usr/bin/pgrep"]} {
|
2020-09-07 22:45:03 -04:00
|
|
|
set fd [open "|pgrep -P $pid" "r"]
|
|
|
|
set child_pid [string trim [lindex [split [read $fd] \n] 0]]
|
|
|
|
} else {
|
|
|
|
set fd [open "|ps --ppid $pid -o pid" "r"]
|
|
|
|
set child_pid [string trim [lindex [split [read $fd] \n] 1]]
|
|
|
|
}
|
if diskless repl child is killed, make sure to reap the pid (#7742)
Starting redis 6.0 and the changes we made to the diskless master to be
suitable for TLS, I made the master avoid reaping (wait3) the pid of the
child until we know all replicas are done reading their rdb.
I did that in order to avoid a state where the rdb_child_pid is -1 but
we don't yet want to start another fork (still busy serving that data to
replicas).
It turns out that the solution used so far was problematic in case the
fork child was being killed (e.g. by the kernel OOM killer), in that
case there's a chance that we currently disabled the read event on the
rdb pipe, since we're waiting for a replica to become writable again.
and in that scenario the master would have never realized the child
exited, and the replica will remain hung too.
Note that there's no mechanism to detect a hung replica while it's in
rdb transfer state.
The solution here is to add another pipe which is used by the parent to
tell the child it is safe to exit. this mean that when the child exits,
for whatever reason, it is safe to reap it.
Besides that, i'm re-introducing an adjustment to REPLCONF ACK which was
part of #6271 (Accelerate diskless master connections) but was dropped
when that PR was rebased after the TLS fork/pipe changes (5a47794).
Now that RdbPipeCleanup no longer calls checkChildrenDone, and the ACK
has chance to detect that the child exited, it should be the one to call
it so that we don't have to wait for cron (server.hz) to do that.
2020-09-06 09:43:57 -04:00
|
|
|
close $fd
|
|
|
|
|
|
|
|
return $child_pid
|
|
|
|
}
|
2020-10-08 01:33:17 -04:00
|
|
|
|
|
|
|
proc cmdrstat {cmd r} {
|
|
|
|
if {[regexp "\r\ncmdstat_$cmd:(.*?)\r\n" [$r info commandstats] _ value]} {
|
|
|
|
set _ $value
|
|
|
|
}
|
|
|
|
}
|
2020-08-14 09:05:34 -04:00
|
|
|
|
|
|
|
proc generate_fuzzy_traffic_on_key {key duration} {
|
|
|
|
# Commands per type, blocking commands removed
|
|
|
|
# TODO: extract these from help.h or elsewhere, and improve to include other types
|
|
|
|
set string_commands {APPEND BITCOUNT BITFIELD BITOP BITPOS DECR DECRBY GET GETBIT GETRANGE GETSET INCR INCRBY INCRBYFLOAT MGET MSET MSETNX PSETEX SET SETBIT SETEX SETNX SETRANGE STRALGO STRLEN}
|
|
|
|
set hash_commands {HDEL HEXISTS HGET HGETALL HINCRBY HINCRBYFLOAT HKEYS HLEN HMGET HMSET HSCAN HSET HSETNX HSTRLEN HVALS}
|
|
|
|
set zset_commands {ZADD ZCARD ZCOUNT ZINCRBY ZINTERSTORE ZLEXCOUNT ZPOPMAX ZPOPMIN ZRANGE ZRANGEBYLEX ZRANGEBYSCORE ZRANK ZREM ZREMRANGEBYLEX ZREMRANGEBYRANK ZREMRANGEBYSCORE ZREVRANGE ZREVRANGEBYLEX ZREVRANGEBYSCORE ZREVRANK ZSCAN ZSCORE ZUNIONSTORE}
|
|
|
|
set list_commands {LINDEX LINSERT LLEN LPOP LPOS LPUSH LPUSHX LRANGE LREM LSET LTRIM RPOP RPOPLPUSH RPUSH RPUSHX}
|
|
|
|
set set_commands {SADD SCARD SDIFF SDIFFSTORE SINTER SINTERSTORE SISMEMBER SMEMBERS SMOVE SPOP SRANDMEMBER SREM SSCAN SUNION SUNIONSTORE}
|
|
|
|
set stream_commands {XACK XADD XCLAIM XDEL XGROUP XINFO XLEN XPENDING XRANGE XREAD XREADGROUP XREVRANGE XTRIM}
|
|
|
|
set commands [dict create string $string_commands hash $hash_commands zset $zset_commands list $list_commands set $set_commands stream $stream_commands]
|
|
|
|
|
|
|
|
set type [r type $key]
|
|
|
|
set cmds [dict get $commands $type]
|
|
|
|
set start_time [clock seconds]
|
|
|
|
set sent {}
|
|
|
|
set succeeded 0
|
|
|
|
while {([clock seconds]-$start_time) < $duration} {
|
|
|
|
# find a random command for our key type
|
|
|
|
set cmd_idx [expr {int(rand()*[llength $cmds])}]
|
|
|
|
set cmd [lindex $cmds $cmd_idx]
|
|
|
|
# get the command details from redis
|
|
|
|
if { [ catch {
|
|
|
|
set cmd_info [lindex [r command info $cmd] 0]
|
|
|
|
} err ] } {
|
|
|
|
# if we failed, it means redis crashed after the previous command
|
|
|
|
return $sent
|
|
|
|
}
|
|
|
|
# try to build a valid command argument
|
|
|
|
set arity [lindex $cmd_info 1]
|
|
|
|
set arity [expr $arity < 0 ? - $arity: $arity]
|
|
|
|
set firstkey [lindex $cmd_info 3]
|
|
|
|
set i 1
|
|
|
|
if {$cmd == "XINFO"} {
|
|
|
|
lappend cmd "STREAM"
|
|
|
|
lappend cmd $key
|
|
|
|
lappend cmd "FULL"
|
|
|
|
incr i 3
|
|
|
|
}
|
|
|
|
if {$cmd == "XREAD"} {
|
|
|
|
lappend cmd "STREAMS"
|
|
|
|
lappend cmd $key
|
|
|
|
randpath {
|
|
|
|
lappend cmd \$
|
|
|
|
} {
|
|
|
|
lappend cmd [randomValue]
|
|
|
|
}
|
|
|
|
incr i 3
|
|
|
|
}
|
|
|
|
if {$cmd == "XADD"} {
|
|
|
|
lappend cmd $key
|
|
|
|
randpath {
|
|
|
|
lappend cmd "*"
|
|
|
|
} {
|
|
|
|
lappend cmd [randomValue]
|
|
|
|
}
|
|
|
|
lappend cmd [randomValue]
|
|
|
|
lappend cmd [randomValue]
|
|
|
|
incr i 4
|
|
|
|
}
|
|
|
|
for {} {$i < $arity} {incr i} {
|
|
|
|
if {$i == $firstkey} {
|
|
|
|
lappend cmd $key
|
|
|
|
} else {
|
|
|
|
lappend cmd [randomValue]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# execute the command, we expect commands to fail on syntax errors
|
|
|
|
lappend sent $cmd
|
|
|
|
if { ! [ catch {
|
|
|
|
r {*}$cmd
|
|
|
|
} err ] } {
|
|
|
|
incr succeeded
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# print stats so that we know if we managed to generate commands that actually made senes
|
|
|
|
#if {$::verbose} {
|
|
|
|
# set count [llength $sent]
|
|
|
|
# puts "Fuzzy traffic sent: $count, succeeded: $succeeded"
|
|
|
|
#}
|
|
|
|
|
|
|
|
# return the list of commands we sent
|
|
|
|
return $sent
|
|
|
|
}
|
|
|
|
|
|
|
|
# write line to server log file
|
|
|
|
proc write_log_line {srv_idx msg} {
|
|
|
|
set logfile [srv $srv_idx stdout]
|
|
|
|
set fd [open $logfile "a+"]
|
|
|
|
puts $fd "### $msg"
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
|
|
|
|
proc string2printable s {
|
|
|
|
set res {}
|
|
|
|
set has_special_chars false
|
|
|
|
foreach i [split $s {}] {
|
|
|
|
scan $i %c int
|
|
|
|
# non printable characters, including space and excluding: " \ $ { }
|
|
|
|
if {$int < 32 || $int > 122 || $int == 34 || $int == 36 || $int == 92} {
|
|
|
|
set has_special_chars true
|
|
|
|
}
|
|
|
|
# TCL8.5 has issues mixing \x notation and normal chars in the same
|
|
|
|
# source code string, so we'll convert the entire string.
|
|
|
|
append res \\x[format %02X $int]
|
|
|
|
}
|
|
|
|
if {!$has_special_chars} {
|
|
|
|
return $s
|
|
|
|
}
|
|
|
|
set res "\"$res\""
|
|
|
|
return $res
|
|
|
|
}
|