2021-06-09 08:13:24 -04:00
|
|
|
tags {"rdb external:skip"} {
|
2021-01-17 08:48:48 -05:00
|
|
|
|
2012-03-23 10:22:25 -04:00
|
|
|
set server_path [tmpdir "server.rdb-encoding-test"]
|
|
|
|
|
2012-03-23 15:20:43 -04:00
|
|
|
# Copy RDB with different encodings in server path
|
2012-03-23 10:22:25 -04:00
|
|
|
exec cp tests/assets/encodings.rdb $server_path
|
2021-11-03 14:47:18 -04:00
|
|
|
exec cp tests/assets/list-quicklist.rdb $server_path
|
|
|
|
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
start_server [list overrides [list "dir" $server_path "dbfilename" "list-quicklist.rdb" save ""]] {
|
2021-11-03 14:47:18 -04:00
|
|
|
test "test old version rdb file" {
|
|
|
|
r select 0
|
|
|
|
assert_equal [r get x] 7
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
assert_encoding listpack list
|
2021-11-03 14:47:18 -04:00
|
|
|
r lpop list
|
|
|
|
} {7}
|
|
|
|
}
|
2012-03-23 10:22:25 -04:00
|
|
|
|
|
|
|
start_server [list overrides [list "dir" $server_path "dbfilename" "encodings.rdb"]] {
|
|
|
|
test "RDB encoding loading test" {
|
|
|
|
r select 0
|
|
|
|
csvdump r
|
2015-08-05 08:05:34 -04:00
|
|
|
} {"0","compressible","string","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
"0","hash","hash","a","1","aa","10","aaa","100","b","2","bb","20","bbb","200","c","3","cc","30","ccc","300","ddd","400","eee","5000000000",
|
|
|
|
"0","hash_zipped","hash","a","1","b","2","c","3",
|
|
|
|
"0","list","list","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000",
|
|
|
|
"0","list_zipped","list","1","2","3","a","b","c","100000","6000000000",
|
|
|
|
"0","number","string","10"
|
|
|
|
"0","set","set","1","100000","2","3","6000000000","a","b","c",
|
|
|
|
"0","set_zipped_1","set","1","2","3","4",
|
|
|
|
"0","set_zipped_2","set","100000","200000","300000","400000",
|
|
|
|
"0","set_zipped_3","set","1000000000","2000000000","3000000000","4000000000","5000000000","6000000000",
|
|
|
|
"0","string","string","Hello World"
|
2023-02-06 11:26:40 -05:00
|
|
|
"0","zset","zset","a","1","b","2","c","3","aa","10","bb","20","cc","30","aaa","100","bbb","200","ccc","300","aaaa","1000","cccc","123456789","bbbb","5000000000",
|
2015-08-05 08:05:34 -04:00
|
|
|
"0","zset_zipped","zset","a","1","b","2","c","3",
|
2012-03-23 10:22:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 14:55:33 -04:00
|
|
|
set server_path [tmpdir "server.rdb-startup-test"]
|
|
|
|
|
2020-08-31 03:44:43 -04:00
|
|
|
start_server [list overrides [list "dir" $server_path] keep_persistence true] {
|
2013-03-12 14:55:33 -04:00
|
|
|
test {Server started empty with non-existing RDB file} {
|
2021-12-19 10:41:51 -05:00
|
|
|
debug_digest
|
2013-03-12 14:55:33 -04:00
|
|
|
} {0000000000000000000000000000000000000000}
|
2013-03-13 05:04:33 -04:00
|
|
|
# Save an RDB file, needed for the next test.
|
|
|
|
r save
|
|
|
|
}
|
|
|
|
|
2020-08-31 03:44:43 -04:00
|
|
|
start_server [list overrides [list "dir" $server_path] keep_persistence true] {
|
2013-03-13 05:04:33 -04:00
|
|
|
test {Server started empty with empty RDB file} {
|
2021-12-19 10:41:51 -05:00
|
|
|
debug_digest
|
2013-03-13 05:04:33 -04:00
|
|
|
} {0000000000000000000000000000000000000000}
|
|
|
|
}
|
|
|
|
|
2020-08-31 03:44:43 -04:00
|
|
|
start_server [list overrides [list "dir" $server_path] keep_persistence true] {
|
2018-06-19 10:29:15 -04:00
|
|
|
test {Test RDB stream encoding} {
|
|
|
|
for {set j 0} {$j < 1000} {incr j} {
|
|
|
|
if {rand() < 0.9} {
|
2021-09-26 11:46:22 -04:00
|
|
|
r xadd stream * foo abc
|
2018-06-19 10:29:15 -04:00
|
|
|
} else {
|
|
|
|
r xadd stream * bar $j
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 08:32:18 -04:00
|
|
|
r xgroup create stream mygroup 0
|
2020-11-22 13:58:33 -05:00
|
|
|
set records [r xreadgroup GROUP mygroup Alice COUNT 2 STREAMS stream >]
|
2021-03-01 10:23:29 -05:00
|
|
|
r xdel stream [lindex [lindex [lindex [lindex $records 0] 1] 1] 0]
|
2020-11-22 13:58:33 -05:00
|
|
|
r xack stream mygroup [lindex [lindex [lindex [lindex $records 0] 1] 0] 0]
|
2021-12-19 10:41:51 -05:00
|
|
|
set digest [debug_digest]
|
2020-11-22 13:58:33 -05:00
|
|
|
r config set sanitize-dump-payload no
|
2018-06-19 10:29:15 -04:00
|
|
|
r debug reload
|
2021-12-19 10:41:51 -05:00
|
|
|
set newdigest [debug_digest]
|
2018-06-19 10:29:15 -04:00
|
|
|
assert {$digest eq $newdigest}
|
|
|
|
}
|
2020-11-22 13:58:33 -05:00
|
|
|
test {Test RDB stream encoding - sanitize dump} {
|
|
|
|
r config set sanitize-dump-payload yes
|
|
|
|
r debug reload
|
2021-12-19 10:41:51 -05:00
|
|
|
set newdigest [debug_digest]
|
2020-11-22 13:58:33 -05:00
|
|
|
assert {$digest eq $newdigest}
|
|
|
|
}
|
|
|
|
# delete the stream, maybe valgrind will find something
|
|
|
|
r del stream
|
2018-06-19 10:29:15 -04:00
|
|
|
}
|
|
|
|
|
2013-03-13 05:04:33 -04:00
|
|
|
# Helper function to start a server and kill it, just to check the error
|
|
|
|
# logged.
|
|
|
|
set defaults {}
|
|
|
|
proc start_server_and_kill_it {overrides code} {
|
|
|
|
upvar defaults defaults srv srv server_path server_path
|
|
|
|
set config [concat $defaults $overrides]
|
2020-08-31 03:44:43 -04:00
|
|
|
set srv [start_server [list overrides $config keep_persistence true]]
|
2013-03-13 05:04:33 -04:00
|
|
|
uplevel 1 $code
|
|
|
|
kill_server $srv
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make the RDB file unreadable
|
|
|
|
file attributes [file join $server_path dump.rdb] -permissions 0222
|
|
|
|
|
2013-04-23 08:08:42 -04:00
|
|
|
# Detect root account (it is able to read the file even with 002 perm)
|
|
|
|
set isroot 0
|
|
|
|
catch {
|
|
|
|
open [file join $server_path dump.rdb]
|
|
|
|
set isroot 1
|
|
|
|
}
|
|
|
|
|
2013-03-13 05:04:33 -04:00
|
|
|
# Now make sure the server aborted with an error
|
2013-04-23 08:08:42 -04:00
|
|
|
if {!$isroot} {
|
|
|
|
start_server_and_kill_it [list "dir" $server_path] {
|
|
|
|
test {Server should not start if RDB file can't be open} {
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[string match {*Fatal error loading*} \
|
2017-02-22 07:08:21 -05:00
|
|
|
[exec tail -1 < [dict get $srv stdout]]]
|
2013-04-23 08:08:42 -04:00
|
|
|
} else {
|
|
|
|
fail "Server started even if RDB was unreadable!"
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 05:04:33 -04:00
|
|
|
}
|
2013-03-12 14:55:33 -04:00
|
|
|
}
|
2013-03-13 06:12:45 -04:00
|
|
|
|
2013-04-22 05:25:44 -04:00
|
|
|
# Fix permissions of the RDB file.
|
2013-03-13 06:12:45 -04:00
|
|
|
file attributes [file join $server_path dump.rdb] -permissions 0666
|
2013-04-22 05:25:44 -04:00
|
|
|
|
|
|
|
# Corrupt its CRC64 checksum.
|
2013-03-13 06:12:45 -04:00
|
|
|
set filesize [file size [file join $server_path dump.rdb]]
|
|
|
|
set fd [open [file join $server_path dump.rdb] r+]
|
|
|
|
fconfigure $fd -translation binary
|
|
|
|
seek $fd -8 end
|
|
|
|
puts -nonewline $fd "foobar00"; # Corrupt the checksum
|
|
|
|
close $fd
|
|
|
|
|
|
|
|
# Now make sure the server aborted with an error
|
|
|
|
start_server_and_kill_it [list "dir" $server_path] {
|
2013-04-23 08:08:42 -04:00
|
|
|
test {Server should not start if RDB is corrupted} {
|
|
|
|
wait_for_condition 50 100 {
|
2016-07-04 06:41:25 -04:00
|
|
|
[string match {*CRC error*} \
|
2017-02-22 07:08:21 -05:00
|
|
|
[exec tail -10 < [dict get $srv stdout]]]
|
2013-04-23 08:08:42 -04:00
|
|
|
} else {
|
|
|
|
fail "Server started even if RDB was corrupted!"
|
|
|
|
}
|
2013-03-13 06:12:45 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-26 08:16:34 -04:00
|
|
|
|
|
|
|
start_server {} {
|
|
|
|
test {Test FLUSHALL aborts bgsave} {
|
2022-01-26 12:46:02 -05:00
|
|
|
r config set save ""
|
|
|
|
# 5000 keys with 1ms sleep per key should take 5 second
|
2019-09-26 08:16:34 -04:00
|
|
|
r config set rdb-key-save-delay 1000
|
2022-01-26 12:46:02 -05:00
|
|
|
populate 5000
|
|
|
|
assert_lessthan 999 [s rdb_changes_since_last_save]
|
2019-09-26 08:16:34 -04:00
|
|
|
r bgsave
|
|
|
|
assert_equal [s rdb_bgsave_in_progress] 1
|
|
|
|
r flushall
|
2022-01-26 12:46:02 -05:00
|
|
|
# wait a second max (bgsave should take 5)
|
|
|
|
wait_for_condition 10 100 {
|
2020-07-23 06:06:24 -04:00
|
|
|
[s rdb_bgsave_in_progress] == 0
|
|
|
|
} else {
|
|
|
|
fail "bgsave not aborted"
|
|
|
|
}
|
2022-01-26 12:46:02 -05:00
|
|
|
# verify that bgsave failed, by checking that the change counter is still high
|
2020-07-23 06:06:24 -04:00
|
|
|
assert_lessthan 999 [s rdb_changes_since_last_save]
|
2019-09-26 08:16:34 -04:00
|
|
|
# make sure the server is still writable
|
|
|
|
r set x xx
|
|
|
|
}
|
2020-07-23 06:06:24 -04:00
|
|
|
|
|
|
|
test {bgsave resets the change counter} {
|
|
|
|
r config set rdb-key-save-delay 0
|
|
|
|
r bgsave
|
2020-08-04 01:53:50 -04:00
|
|
|
wait_for_condition 50 100 {
|
2020-07-23 06:06:24 -04:00
|
|
|
[s rdb_bgsave_in_progress] == 0
|
|
|
|
} else {
|
2020-08-04 01:53:50 -04:00
|
|
|
fail "bgsave not done"
|
2020-07-23 06:06:24 -04:00
|
|
|
}
|
|
|
|
assert_equal [s rdb_changes_since_last_save] 0
|
|
|
|
}
|
2020-05-10 12:13:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
test {client freed during loading} {
|
2023-04-18 09:14:26 -04:00
|
|
|
start_server [list overrides [list key-load-delay 50 loading-process-events-interval-bytes 1024 rdbcompression no save "900 1"]] {
|
2020-05-10 12:13:47 -04:00
|
|
|
# create a big rdb that will take long to load. it is important
|
|
|
|
# for keys to be big since the server processes events only once in 2mb.
|
2021-06-22 04:10:11 -04:00
|
|
|
# 100mb of rdb, 100k keys will load in more than 5 seconds
|
2020-05-10 12:13:47 -04:00
|
|
|
r debug populate 100000 key 1000
|
|
|
|
|
2020-08-14 09:05:34 -04:00
|
|
|
restart_server 0 false false
|
2020-05-10 12:13:47 -04:00
|
|
|
|
|
|
|
# make sure it's still loading
|
|
|
|
assert_equal [s loading] 1
|
|
|
|
|
2021-06-22 04:10:11 -04:00
|
|
|
# connect and disconnect 5 clients
|
2020-05-10 12:13:47 -04:00
|
|
|
set clients {}
|
2021-06-22 04:10:11 -04:00
|
|
|
for {set j 0} {$j < 5} {incr j} {
|
2020-05-10 12:13:47 -04:00
|
|
|
lappend clients [redis_deferring_client]
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd debug log bla
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd read
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd close
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure the server freed the clients
|
|
|
|
wait_for_condition 100 100 {
|
|
|
|
[s connected_clients] < 3
|
|
|
|
} else {
|
|
|
|
fail "clients didn't disconnect"
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure it's still loading
|
|
|
|
assert_equal [s loading] 1
|
|
|
|
|
|
|
|
# no need to keep waiting for loading to complete
|
|
|
|
exec kill [srv 0 pid]
|
|
|
|
}
|
tests/valgrind: don't use debug restart (#7404)
* tests/valgrind: don't use debug restart
DEBUG REATART causes two issues:
1. it uses execve which replaces the original process and valgrind doesn't
have a chance to check for errors, so leaks go unreported.
2. valgrind report invalid calls to close() which we're unable to resolve.
So now the tests use restart_server mechanism in the tests, that terminates
the old server and starts a new one, new PID, but same stdout, stderr.
since the stderr can contain two or more valgrind report, it is not enough
to just check for the absence of leaks, we also need to check for some known
errors, we do both, and fail if we either find an error, or can't find a
report saying there are no leaks.
other changes:
- when killing a server that was already terminated we check for leaks too.
- adding DEBUG LEAK which was used to test it.
- adding --trace-children to valgrind, although no longer needed.
- since the stdout contains two or more runs, we need slightly different way
of checking if the new process is up (explicitly looking for the new PID)
- move the code that handles --wait-server to happen earlier (before
watching the startup message in the log), and serve the restarted server too.
* squashme - CR fixes
2020-07-10 01:26:52 -04:00
|
|
|
}
|
2020-12-20 13:23:20 -05:00
|
|
|
|
2021-09-13 03:39:11 -04:00
|
|
|
start_server {} {
|
|
|
|
test {Test RDB load info} {
|
|
|
|
r debug populate 1000
|
|
|
|
r save
|
Add reply_schema to command json files (internal for now) (#10273)
Work in progress towards implementing a reply schema as part of COMMAND DOCS, see #9845
Since ironing the details of the reply schema of each and every command can take a long time, we
would like to merge this PR when the infrastructure is ready, and let this mature in the unstable branch.
Meanwhile the changes of this PR are internal, they are part of the repo, but do not affect the produced build.
### Background
In #9656 we add a lot of information about Redis commands, but we are missing information about the replies
### Motivation
1. Documentation. This is the primary goal.
2. It should be possible, based on the output of COMMAND, to be able to generate client code in typed
languages. In order to do that, we need Redis to tell us, in detail, what each reply looks like.
3. We would like to build a fuzzer that verifies the reply structure (for now we use the existing
testsuite, see the "Testing" section)
### Schema
The idea is to supply some sort of schema for the various replies of each command.
The schema will describe the conceptual structure of the reply (for generated clients), as defined in RESP3.
Note that the reply structure itself may change, depending on the arguments (e.g. `XINFO STREAM`, with
and without the `FULL` modifier)
We decided to use the standard json-schema (see https://json-schema.org/) as the reply-schema.
Example for `BZPOPMIN`:
```
"reply_schema": {
"oneOf": [
{
"description": "Timeout reached and no elements were popped.",
"type": "null"
},
{
"description": "The keyname, popped member, and its score.",
"type": "array",
"minItems": 3,
"maxItems": 3,
"items": [
{
"description": "Keyname",
"type": "string"
},
{
"description": "Member",
"type": "string"
},
{
"description": "Score",
"type": "number"
}
]
}
]
}
```
#### Notes
1. It is ok that some commands' reply structure depends on the arguments and it's the caller's responsibility
to know which is the relevant one. this comes after looking at other request-reply systems like OpenAPI,
where the reply schema can also be oneOf and the caller is responsible to know which schema is the relevant one.
2. The reply schemas will describe RESP3 replies only. even though RESP3 is structured, we want to use reply
schema for documentation (and possibly to create a fuzzer that validates the replies)
3. For documentation, the description field will include an explanation of the scenario in which the reply is sent,
including any relation to arguments. for example, for `ZRANGE`'s two schemas we will need to state that one
is with `WITHSCORES` and the other is without.
4. For documentation, there will be another optional field "notes" in which we will add a short description of
the representation in RESP2, in case it's not trivial (RESP3's `ZRANGE`'s nested array vs. RESP2's flat
array, for example)
Given the above:
1. We can generate the "return" section of all commands in [redis-doc](https://redis.io/commands/)
(given that "description" and "notes" are comprehensive enough)
2. We can generate a client in a strongly typed language (but the return type could be a conceptual
`union` and the caller needs to know which schema is relevant). see the section below for RESP2 support.
3. We can create a fuzzer for RESP3.
### Limitations (because we are using the standard json-schema)
The problem is that Redis' replies are more diverse than what the json format allows. This means that,
when we convert the reply to a json (in order to validate the schema against it), we lose information (see
the "Testing" section below).
The other option would have been to extend the standard json-schema (and json format) to include stuff
like sets, bulk-strings, error-string, etc. but that would mean also extending the schema-validator - and that
seemed like too much work, so we decided to compromise.
Examples:
1. We cannot tell the difference between an "array" and a "set"
2. We cannot tell the difference between simple-string and bulk-string
3. we cannot verify true uniqueness of items in commands like ZRANGE: json-schema doesn't cover the
case of two identical members with different scores (e.g. `[["m1",6],["m1",7]]`) because `uniqueItems`
compares (member,score) tuples and not just the member name.
### Testing
This commit includes some changes inside Redis in order to verify the schemas (existing and future ones)
are indeed correct (i.e. describe the actual response of Redis).
To do that, we added a debugging feature to Redis that causes it to produce a log of all the commands
it executed and their replies.
For that, Redis needs to be compiled with `-DLOG_REQ_RES` and run with
`--reg-res-logfile <file> --client-default-resp 3` (the testsuite already does that if you run it with
`--log-req-res --force-resp3`)
You should run the testsuite with the above args (and `--dont-clean`) in order to make Redis generate
`.reqres` files (same dir as the `stdout` files) which contain request-response pairs.
These files are later on processed by `./utils/req-res-log-validator.py` which does:
1. Goes over req-res files, generated by redis-servers, spawned by the testsuite (see logreqres.c)
2. For each request-response pair, it validates the response against the request's reply_schema
(obtained from the extended COMMAND DOCS)
5. In order to get good coverage of the Redis commands, and all their different replies, we chose to use
the existing redis test suite, rather than attempt to write a fuzzer.
#### Notes about RESP2
1. We will not be able to use the testing tool to verify RESP2 replies (we are ok with that, it's time to
accept RESP3 as the future RESP)
2. Since the majority of the test suite is using RESP2, and we want the server to reply with RESP3
so that we can validate it, we will need to know how to convert the actual reply to the one expected.
- number and boolean are always strings in RESP2 so the conversion is easy
- objects (maps) are always a flat array in RESP2
- others (nested array in RESP3's `ZRANGE` and others) will need some special per-command
handling (so the client will not be totally auto-generated)
Example for ZRANGE:
```
"reply_schema": {
"anyOf": [
{
"description": "A list of member elements",
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
},
{
"description": "Members and their scores. Returned in case `WITHSCORES` was used.",
"notes": "In RESP2 this is returned as a flat array",
"type": "array",
"uniqueItems": true,
"items": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"description": "Member",
"type": "string"
},
{
"description": "Score",
"type": "number"
}
]
}
}
]
}
```
### Other changes
1. Some tests that behave differently depending on the RESP are now being tested for both RESP,
regardless of the special log-req-res mode ("Pub/Sub PING" for example)
2. Update the history field of CLIENT LIST
3. Added basic tests for commands that were not covered at all by the testsuite
### TODO
- [x] (maybe a different PR) add a "condition" field to anyOf/oneOf schemas that refers to args. e.g.
when `SET` return NULL, the condition is `arguments.get||arguments.condition`, for `OK` the condition
is `!arguments.get`, and for `string` the condition is `arguments.get` - https://github.com/redis/redis/issues/11896
- [x] (maybe a different PR) also run `runtest-cluster` in the req-res logging mode
- [x] add the new tests to GH actions (i.e. compile with `-DLOG_REQ_RES`, run the tests, and run the validator)
- [x] (maybe a different PR) figure out a way to warn about (sub)schemas that are uncovered by the output
of the tests - https://github.com/redis/redis/issues/11897
- [x] (probably a separate PR) add all missing schemas
- [x] check why "SDOWN is triggered by misconfigured instance replying with errors" fails with --log-req-res
- [x] move the response transformers to their own file (run both regular, cluster, and sentinel tests - need to
fight with the tcl including mechanism a bit)
- [x] issue: module API - https://github.com/redis/redis/issues/11898
- [x] (probably a separate PR): improve schemas: add `required` to `object`s - https://github.com/redis/redis/issues/11899
Co-authored-by: Ozan Tezcan <ozantezcan@gmail.com>
Co-authored-by: Hanna Fadida <hanna.fadida@redislabs.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Shaya Potter <shaya@redislabs.com>
2023-03-11 03:14:16 -05:00
|
|
|
assert {[r lastsave] <= [lindex [r time] 0]}
|
2021-09-13 03:39:11 -04:00
|
|
|
restart_server 0 true false
|
|
|
|
wait_done_loading r
|
|
|
|
assert {[s rdb_last_load_keys_expired] == 0}
|
|
|
|
assert {[s rdb_last_load_keys_loaded] == 1000}
|
|
|
|
|
|
|
|
r debug set-active-expire 0
|
|
|
|
for {set j 0} {$j < 1024} {incr j} {
|
|
|
|
r select [expr $j%16]
|
|
|
|
r set $j somevalue px 10
|
|
|
|
}
|
|
|
|
after 20
|
|
|
|
|
|
|
|
r save
|
|
|
|
restart_server 0 true false
|
|
|
|
wait_done_loading r
|
|
|
|
assert {[s rdb_last_load_keys_expired] == 1024}
|
|
|
|
assert {[s rdb_last_load_keys_loaded] == 1000}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 16:35:30 -05:00
|
|
|
# Our COW metrics (Private_Dirty) work only on Linux
|
|
|
|
set system_name [string tolower [exec uname -s]]
|
2021-10-04 03:32:26 -04:00
|
|
|
set page_size [exec getconf PAGESIZE]
|
|
|
|
if {$system_name eq {linux} && $page_size == 4096} {
|
2021-01-08 16:35:30 -05:00
|
|
|
|
2020-12-20 13:23:20 -05:00
|
|
|
start_server {overrides {save ""}} {
|
2021-02-16 09:06:51 -05:00
|
|
|
test {Test child sending info} {
|
2020-12-20 13:23:20 -05:00
|
|
|
# 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}
|
2021-02-16 09:06:51 -05:00
|
|
|
assert {[s current_save_keys_processed] == 0}
|
|
|
|
assert {[s current_save_keys_total] == 0}
|
|
|
|
|
2020-12-20 13:23:20 -05:00
|
|
|
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
|
2021-01-08 16:35:30 -05:00
|
|
|
r config set loglevel debug
|
2020-12-20 13:23:20 -05:00
|
|
|
|
2021-10-04 03:32:26 -04:00
|
|
|
# populate the db with 10k keys of 512B each (since we want to measure the COW size by
|
|
|
|
# changing some keys and read the reported COW size, we are using small key size to prevent from
|
|
|
|
# the "dismiss mechanism" free memory and reduce the COW size)
|
2020-12-20 13:23:20 -05:00
|
|
|
set rd [redis_deferring_client 0]
|
2021-10-04 03:32:26 -04:00
|
|
|
set size 500 ;# aim for the 512 bin (sds overhead)
|
2020-12-20 13:23:20 -05:00
|
|
|
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
|
|
|
|
|
2021-02-16 09:06:51 -05:00
|
|
|
set current_save_keys_total [s current_save_keys_total]
|
|
|
|
if {$::verbose} {
|
FLUSHDB and FLUSHALL add call forceCommandPropagation / FLUSHALL reset dirty counter to 0 if we enable save (#10691)
## FLUSHALL
We used to restore the dirty counter after `rdbSave` zeroed it if we enable save.
Otherwise FLUSHALL will not be replicated nor put into the AOF.
And then we do increment it again below.
Without that extra dirty++, when db was already empty, FLUSHALL
will not be replicated nor put into the AOF.
We now gonna replace all that dirty counter magic with a call
to forceCommandPropagation (REPL and AOF), instead of all the
messing around with the dirty counter.
Added tests to cover three part (dirty counter, REPL, AOF).
One benefit other than cleaner code is that the `rdb_changes_since_last_save` is correct in this case.
## FLUSHDB
FLUSHDB was not replicated nor put into the AOF when db was already empty.
Unlike DEL on a non-existing key, FLUSHDB always does something, and that's to call the module hook.
So basically FLUSHDB is never a NOP, and thus it should always be propagated.
Not doing that, could mean that if a module does something in that hook, and wants to
avoid issues of that hook being missing on the replica if the db is empty, it'll need to do complicated things.
So now FLUSHDB add call forceCommandPropagation, we will always propagate FLUSHDB.
Always propagating FLUSHDB seems like a safe approach that shouldn't have any drawbacks (other than looking odd)
This was mentioned in #8972
## Test section:
We actually found it while solving a race condition in the BGSAVE test (other.tcl).
It was found in extra_ci Daily Arm64 (test-libc-malloc).
```
[exception]: Executing test client: ERR Background save already in progress.
ERR Background save already in progress
```
It look like `r flushdb` trigger (schedule) a bgsave right after `waitForBgsave r` and before `r save`.
Changing flushdb to flushall, FLUSHALL will do a foreground save and then set the dirty counter to 0.
2022-05-11 04:21:16 -04:00
|
|
|
puts "Keys before bgsave start: $current_save_keys_total"
|
2021-02-16 09:06:51 -05:00
|
|
|
}
|
|
|
|
|
2020-12-20 13:23:20 -05:00
|
|
|
# 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
|
2021-10-04 03:32:26 -04:00
|
|
|
set key_idx 0
|
2020-12-20 13:23:20 -05:00
|
|
|
while 1 {
|
2021-02-16 09:06:51 -05:00
|
|
|
# take samples before writing new data to the server
|
2020-12-20 13:23:20 -05:00
|
|
|
set cow_size [s current_cow_size]
|
|
|
|
if {$::verbose} {
|
|
|
|
puts "COW info before copy-on-write: $cow_size"
|
|
|
|
}
|
|
|
|
|
2021-02-16 09:06:51 -05:00
|
|
|
set keys_processed [s current_save_keys_processed]
|
|
|
|
if {$::verbose} {
|
|
|
|
puts "current_save_keys_processed info : $keys_processed"
|
|
|
|
}
|
|
|
|
|
2020-12-20 13:23:20 -05:00
|
|
|
# trigger copy-on-write
|
2021-10-04 03:32:26 -04:00
|
|
|
set modified_keys 16
|
|
|
|
for {set k 0} {$k < $modified_keys} {incr k} {
|
|
|
|
r setrange key$key_idx 0 [string repeat B $size]
|
|
|
|
incr key_idx 1
|
|
|
|
}
|
2020-12-20 13:23:20 -05:00
|
|
|
|
2021-10-04 03:32:26 -04:00
|
|
|
# changing 16 keys (512B each) will create at least 8192 COW (2 pages), but we don't want the test
|
|
|
|
# to be too strict, so we check for a change of at least 4096 bytes
|
|
|
|
set exp_cow [expr $cow_size + 4096]
|
2020-12-20 13:23:20 -05:00
|
|
|
# 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 ||
|
2021-10-04 03:32:26 -04:00
|
|
|
[s current_cow_size] >= $exp_cow &&
|
2021-02-16 09:06:51 -05:00
|
|
|
[s current_save_keys_processed] > $keys_processed &&
|
|
|
|
[s current_fork_perc] > 0
|
2020-12-20 13:23:20 -05:00
|
|
|
} else {
|
|
|
|
if {$::verbose} {
|
|
|
|
puts "COW info on fail: [s current_cow_size]"
|
2021-01-08 16:35:30 -05:00
|
|
|
puts [exec tail -n 100 < [srv 0 stdout]]
|
2020-12-20 13:23:20 -05:00
|
|
|
}
|
2021-01-08 16:35:30 -05:00
|
|
|
fail "COW info wasn't reported"
|
2020-12-20 13:23:20 -05:00
|
|
|
}
|
|
|
|
|
2021-02-16 09:06:51 -05:00
|
|
|
# assert that $keys_processed is not greater than total keys.
|
|
|
|
assert_morethan_equal $current_save_keys_total $keys_processed
|
|
|
|
|
2020-12-20 13:23:20 -05:00
|
|
|
# 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
|
2021-01-08 16:35:30 -05:00
|
|
|
if {$iteration < 2 && $::verbose} {
|
|
|
|
puts [exec tail -n 100 < [srv 0 stdout]]
|
|
|
|
}
|
2020-12-20 13:23:20 -05:00
|
|
|
assert_morethan_equal $iteration 2
|
|
|
|
|
2021-01-08 16:35:30 -05:00
|
|
|
# if bgsave completed, check that rdb_last_cow_size (fork exit report)
|
|
|
|
# is at least 90% of last rdb_active_cow_size.
|
2020-12-20 13:23:20 -05:00
|
|
|
if { [s rdb_bgsave_in_progress] == 0 } {
|
2021-01-08 16:35:30 -05:00
|
|
|
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
|
2020-12-20 13:23:20 -05:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 16:35:30 -05:00
|
|
|
}
|
|
|
|
} ;# system_name
|
2021-01-17 08:48:48 -05:00
|
|
|
|
2021-12-21 01:32:42 -05:00
|
|
|
exec cp -f tests/assets/scriptbackup.rdb $server_path
|
|
|
|
start_server [list overrides [list "dir" $server_path "dbfilename" "scriptbackup.rdb" "appendonly" "no"]] {
|
|
|
|
# the script is: "return redis.call('set', 'foo', 'bar')""
|
|
|
|
# its sha1 is: a0c38691e9fffe4563723c32ba77a34398e090e6
|
|
|
|
test {script won't load anymore if it's in rdb} {
|
|
|
|
assert_equal [r script exists a0c38691e9fffe4563723c32ba77a34398e090e6] 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix broken protocol in MISCONF error, RM_Yield bugs, RM_Call(EVAL) OOM check bug, and new RM_Call checks. (#10786)
* Fix broken protocol when redis can't persist to RDB (general commands, not
modules), excessive newline. regression of #10372 (7.0 RC3)
* Fix broken protocol when Redis can't persist to AOF (modules and
scripts), missing newline.
* Fix bug in OOM check of EVAL scripts called from RM_Call.
set the cached OOM state for scripts before executing module commands too,
so that it can serve scripts that are executed by modules.
i.e. in the past EVAL executed by RM_Call could have either falsely
fail or falsely succeeded because of a wrong cached OOM state flag.
* Fix bugs with RM_Yield:
1. SHUTDOWN should only accept the NOSAVE mode
2. Avoid eviction during yield command processing.
3. Avoid processing master client commands while yielding from another client
* Add new two more checks to RM_Call script mode.
1. READONLY You can't write against a read only replica
2. MASTERDOWN Link with MASTER is down and `replica-serve-stale-data` is set to `no`
* Add new RM_Call flag to let redis automatically refuse `deny-oom` commands
while over the memory limit.
* Add tests to cover various errors from Scripts, Modules, Modules
calling scripts, and Modules calling commands in script mode.
Add tests:
* Looks like the MISCONF error was completely uncovered by the tests,
add tests for it, including from scripts, and modules
* Add tests for NOREPLICAS from scripts
* Add tests for the various errors in module RM_Call, including RM_Call that
calls EVAL, and RM_call in "eval mode". that includes:
NOREPLICAS, READONLY, MASTERDOWN, MISCONF
2022-06-01 06:04:22 -04:00
|
|
|
start_server {} {
|
|
|
|
test "failed bgsave prevents writes" {
|
2023-04-18 09:14:26 -04:00
|
|
|
# Make sure the server saves an RDB on shutdown
|
|
|
|
r config set save "900 1"
|
|
|
|
|
Fix broken protocol in MISCONF error, RM_Yield bugs, RM_Call(EVAL) OOM check bug, and new RM_Call checks. (#10786)
* Fix broken protocol when redis can't persist to RDB (general commands, not
modules), excessive newline. regression of #10372 (7.0 RC3)
* Fix broken protocol when Redis can't persist to AOF (modules and
scripts), missing newline.
* Fix bug in OOM check of EVAL scripts called from RM_Call.
set the cached OOM state for scripts before executing module commands too,
so that it can serve scripts that are executed by modules.
i.e. in the past EVAL executed by RM_Call could have either falsely
fail or falsely succeeded because of a wrong cached OOM state flag.
* Fix bugs with RM_Yield:
1. SHUTDOWN should only accept the NOSAVE mode
2. Avoid eviction during yield command processing.
3. Avoid processing master client commands while yielding from another client
* Add new two more checks to RM_Call script mode.
1. READONLY You can't write against a read only replica
2. MASTERDOWN Link with MASTER is down and `replica-serve-stale-data` is set to `no`
* Add new RM_Call flag to let redis automatically refuse `deny-oom` commands
while over the memory limit.
* Add tests to cover various errors from Scripts, Modules, Modules
calling scripts, and Modules calling commands in script mode.
Add tests:
* Looks like the MISCONF error was completely uncovered by the tests,
add tests for it, including from scripts, and modules
* Add tests for NOREPLICAS from scripts
* Add tests for the various errors in module RM_Call, including RM_Call that
calls EVAL, and RM_call in "eval mode". that includes:
NOREPLICAS, READONLY, MASTERDOWN, MISCONF
2022-06-01 06:04:22 -04:00
|
|
|
r config set rdb-key-save-delay 10000000
|
|
|
|
populate 1000
|
|
|
|
r set x x
|
|
|
|
r bgsave
|
|
|
|
set pid1 [get_child_pid 0]
|
|
|
|
catch {exec kill -9 $pid1}
|
|
|
|
waitForBgsave r
|
|
|
|
|
|
|
|
# make sure a read command succeeds
|
|
|
|
assert_equal [r get x] x
|
|
|
|
|
|
|
|
# make sure a write command fails
|
|
|
|
assert_error {MISCONF *} {r set x y}
|
|
|
|
|
|
|
|
# repeate with script
|
|
|
|
assert_error {MISCONF *} {r eval {
|
|
|
|
return redis.call('set','x',1)
|
|
|
|
} 1 x
|
|
|
|
}
|
|
|
|
assert_equal {x} [r eval {
|
|
|
|
return redis.call('get','x')
|
|
|
|
} 1 x
|
|
|
|
]
|
|
|
|
|
|
|
|
# again with script using shebang
|
|
|
|
assert_error {MISCONF *} {r eval {#!lua
|
|
|
|
return redis.call('set','x',1)
|
|
|
|
} 1 x
|
|
|
|
}
|
|
|
|
assert_equal {x} [r eval {#!lua flags=no-writes
|
|
|
|
return redis.call('get','x')
|
|
|
|
} 1 x
|
|
|
|
]
|
|
|
|
|
|
|
|
r config set rdb-key-save-delay 0
|
|
|
|
r bgsave
|
|
|
|
waitForBgsave r
|
|
|
|
|
|
|
|
# server is writable again
|
|
|
|
r set x y
|
|
|
|
} {OK}
|
|
|
|
}
|
|
|
|
|
2021-01-17 08:48:48 -05:00
|
|
|
} ;# tags
|