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 <ranshid@amazon.com>
This commit is contained in:
ranshid 2025-01-06 23:36:33 +02:00 committed by GitHub
parent 4fbab5740b
commit f1a02b47c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}
}