summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2022-09-19 14:47:52 +0800
committerGitHub <noreply@github.com>2022-09-19 09:47:52 +0300
commit13d25dd95eec5e21925ef474b5d43f2acb23e54e (patch)
tree1b5df982d8b82bc028aabeca3c109413dae9900b /tests/support
parent464aa04188c42c82f411ac7d43fabf0f6038c98e (diff)
downloadredis-13d25dd95eec5e21925ef474b5d43f2acb23e54e.tar.gz
Fix crash due to delete entry from compress quicklistNode and wrongly split quicklistNode (#11242)
This PR mainly deals with 2 crashes introduced in #9357, and fix the QUICKLIST-PACKED-THRESHOLD mess in external test mode. 1. Fix crash due to deleting an entry from a compress quicklistNode When inserting a large element, we need to create a new quicklistNode first, and then delete its previous element, if the node where the deleted element is located is compressed, it will cause a crash. Now add `dont_compress` to quicklistNode, if we want to use a quicklistNode after some operation, we can use this flag like following: ```c node->dont_compress = 1; /* Prevent to be compressed */ some_operation(node); /* This operation might try to compress this node */ some_other_operation(node); /* We can use this node without decompress it */ node->dont_compress = 0; /* Re-able compression */ quicklistCompressNode(node); ``` Perhaps in the future, we could just disable the current entry from being compressed during the iterator loop, but that would require more work. 2. Fix crash due to wrongly split quicklist before #9357, the offset param of _quicklistSplitNode() will not negative. For now, when offset is negative, the split extent will be wrong. following example: ```c int orig_start = after ? offset + 1 : 0; int orig_extent = after ? -1 : offset; int new_start = after ? 0 : offset; int new_extent = after ? offset + 1 : -1; # offset: -2, after: 1, node->count: 2 # current wrong range: [-1,-1] [0,-1] # correct range: [1,-1] [0, 1] ``` Because only `_quicklistInsert()` splits the quicklistNode and only `quicklistInsertAfter()`, `quicklistInsertBefore()` call _quicklistInsert(), so `quicklistReplaceEntry()` and `listTypeInsert()` might occur this crash. But the iterator of `listTypeInsert()` is alway from head to tail(iter->offset is always positive), so it is not affected. The final conclusion is this crash only occur when we insert a large element with negative index into a list, that affects `LSET` command and `RM_ListSet` module api. 3. In external test mode, we need to restore quicklist packed threshold after when the end of test. 4. Show `node->count` in quicklistRepr(). 5. Add new tcl proc `config_get_set` to support restoring config in tests.
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/util.tcl6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index 0499fd055..51a8420a3 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -928,6 +928,12 @@ proc config_set {param value {options {}}} {
}
}
+proc config_get_set {param value {options {}}} {
+ set config [lindex [r config get $param] 1]
+ config_set $param $value $options
+ return $config
+}
+
proc delete_lines_with_pattern {filename tmpfilename pattern} {
set fh_in [open $filename r]
set fh_out [open $tmpfilename w]