From f1a02b47c3d9d0344150571eccff3cdf26a606cb Mon Sep 17 00:00:00 2001 From: ranshid <88133677+ranshid@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:36:33 +0200 Subject: [PATCH] Fix for when active rehashing kvstore dictionaries are replaced by defrag (#1512) The kvstore operates the active rehashing by traversing a list of dictionaries which were registered to it when they started rehashing. The problem is that active defrag may realloc some of the dictionary structures while they are registered on the list.where the dictionary might be relocated in dictDefragTables. The Solution is to make sure we update the rehashing list node withy the new(or not) dictionary pointer after applying the defrag function. Signed-off-by: Ran Shidlansik --- src/kvstore.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kvstore.c b/src/kvstore.c index 66f92db54..1347e216a 100644 --- a/src/kvstore.c +++ b/src/kvstore.c @@ -753,7 +753,13 @@ void kvstoreDictLUTDefrag(kvstore *kvs, kvstoreDictLUTDefragFunction *defragfn) for (int didx = 0; didx < kvs->num_dicts; didx++) { dict **d = kvstoreGetDictRef(kvs, didx), *newd; if (!*d) continue; + /* In case we will defrag the dictionary while it is registered to active-rehashing + * we need to make sure to update the registration in the rehashing list. + * So we keep the list node and after the defrag operation completes we reassign the value to the + * dictionary pointer. */ + listNode *rehashing_node = ((kvstoreDictMetadata *)dictMetadata(*d))->rehashing_node; if ((newd = defragfn(*d))) *d = newd; + if (rehashing_node) listNodeValue(rehashing_node) = *d; } }