Fix race in slot dict resize test (#12942)

The test have a race:
```
*** [err]: Redis can rewind and trigger smaller slot resizing in tests/unit/other.tcl
Expected '[Dictionary HT]
Hash table 0 stats (main hash table):
 table size: 12
 number of elements: 2
[Expires HT]
Hash table 0 stats (main hash table):
No stats available for empty dictionaries
' to match '*table size: 8*' (context: type eval line 12 cmd {assert_match "*table size: 8*" [r debug HTSTATS 0]} proc ::test)
```

When `r del "{alice}$j"` is executed in the loop, when the key is
deleted to [9, 12], the load factor has meet HASHTABLE_MIN_FILL,
if serverCron happens to trigger slot dict resize, then the test
will fail. Because there is not way to meet HASHTABLE_MIN_FILL in
the subsequent dels.

The solution is to avoid triggering the resize in advance. We can
use multi to delete them at once, or we can disable the resize.
Since we disabled resize in the previous test, the fix also uses
the method of disabling resize.

The test is introduced in #12802.
This commit is contained in:
Binbin 2024-01-17 14:46:09 +08:00 committed by GitHub
parent ecc31bc697
commit 131d95f203
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -459,15 +459,30 @@ start_cluster 1 0 {tags {"other external:skip cluster slow"}} {
} {} {needs:debug}
test "Redis can rewind and trigger smaller slot resizing" {
# hashslot(foo) is 12182
# hashslot(alice) is 749, smaller than hashslot(foo),
# attempt to trigger a resize on it, see details in #12802.
for {set j 1} {$j <= 128} {incr j} {
r set "{alice}$j" a
}
# disable resizing
r config set rdb-key-save-delay 10000000
r bgsave
for {set j 1} {$j <= 127} {incr j} {
r del "{alice}$j"
}
# enable resizing
r config set rdb-key-save-delay 0
catch {exec kill -9 [get_child_pid 0]}
wait_for_condition 1000 10 {
[s rdb_bgsave_in_progress] eq 0
} else {
fail "bgsave did not stop in time."
}
after 200;# waiting for serverCron
assert_match "*table size: 8*" [r debug HTSTATS 0]
} {} {needs:debug}