mirror of
https://github.com/redis/redis.git
synced 2026-05-28 04:02:46 -04:00
Fix DB hash tables not expanding during RDB load (#14789)
In standalone mode, we create dicts on demand. by default, there is no dicts, and RESIZEDB hint doesn't expand dict actually. so we should create dict first when expanding if the dict does not exist.
This commit is contained in:
parent
95314a93e5
commit
099203cb2a
3 changed files with 23 additions and 3 deletions
|
|
@ -385,9 +385,10 @@ unsigned long long kvstoreScan(kvstore *kvs, unsigned long long cursor,
|
|||
*/
|
||||
int kvstoreExpand(kvstore *kvs, uint64_t newsize, int try_expand, kvstoreExpandShouldSkipDictIndex *skip_cb) {
|
||||
for (int i = 0; i < kvs->num_dicts; i++) {
|
||||
dict *d = kvstoreGetDict(kvs, i);
|
||||
if (!d || (skip_cb && skip_cb(i)))
|
||||
continue;
|
||||
if (skip_cb && skip_cb(i)) continue;
|
||||
dict *d = createDictIfNeeded(kvs, i);
|
||||
if (!d) continue;
|
||||
|
||||
int result = try_expand ? dictTryExpand(d, newsize) : dictExpand(d, newsize);
|
||||
if (try_expand && result == DICT_ERR)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -3902,6 +3902,8 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
|
|||
dbExpand(db, db_size, 0);
|
||||
dbExpandExpires(db, expires_size, 0);
|
||||
should_expand_db = 0;
|
||||
serverLog(LL_VERBOSE, "DB %d resized: %lu key buckets, %lu expire buckets",
|
||||
db->id, kvstoreBuckets(db->keys), kvstoreBuckets(db->expires));
|
||||
}
|
||||
|
||||
/* With metadata, type = RDB_OPCODE_KEY_META. Layout: [<META>,]<TYPE>,<KEY>,<VALUE> */
|
||||
|
|
|
|||
|
|
@ -80,6 +80,23 @@ start_server [list overrides [list "dir" $server_path] keep_persistence true] {
|
|||
r del stream
|
||||
}
|
||||
|
||||
start_server {overrides {loglevel verbose}} {
|
||||
test {RDB load applies RESIZEDB hint to expand hash tables} {
|
||||
# Populate keys and save RDB
|
||||
r flushall sync
|
||||
regexp {db=(\d+)} [r client info] -> dbid
|
||||
# 500 keys with 3600 second expiration, 500 without
|
||||
populate 500 "key1:" 3 0 false 3600
|
||||
populate 500 "key2:" 3 0 false 0
|
||||
r save
|
||||
|
||||
restart_server 0 true false
|
||||
|
||||
# Verify DB resize log message
|
||||
verify_log_message 0 "*DB $dbid resized*1024 key*512 expire*" 0
|
||||
}
|
||||
}
|
||||
|
||||
# Helper function to start a server and kill it, just to check the error
|
||||
# logged.
|
||||
set defaults {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue