Skip to content

Commit 630da94

Browse files
committed
Refactor dict restoring abstraction
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
1 parent d2db0c2 commit 630da94

18 files changed

Lines changed: 380 additions & 292 deletions

src/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ ENGINE_SERVER_OBJ = \
498498
db.o \
499499
debug.o \
500500
defrag.o \
501+
dict_ht.o \
501502
entry.o \
502503
eval.o \
503504
evict.o \
@@ -594,6 +595,7 @@ ENGINE_CLI_OBJ = \
594595
crc64.o \
595596
crccombine.o \
596597
crcspeed.o \
598+
dict_ht.o \
597599
hashtable.o \
598600
monotonic.o \
599601
mt19937-64.o \
@@ -618,6 +620,7 @@ ENGINE_BENCHMARK_OBJ = \
618620
crc64.o \
619621
crccombine.o \
620622
crcspeed.o \
623+
dict_ht.o \
621624
fuzzer_client.o \
622625
fuzzer_command_generator.o \
623626
hashtable.o \

src/cluster_legacy.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ static_assert(offsetof(clusterMsg, type) + sizeof(uint16_t) == RCVBUF_MIN_READ_L
247247
/* Cluster nodes hash table, mapping nodes addresses 1.2.3.4:6379 to
248248
* clusterNode structures. */
249249
dictType clusterNodesDictType = {
250-
.entryGetKey = dictEntryGetKey,
251250
.hashFunction = dictSdsHash,
252251
.keyCompare = dictSdsKeyCompare,
253252
.entryDestructor = dictEntryDestructorSdsKey,
@@ -257,15 +256,13 @@ dictType clusterNodesDictType = {
257256
* we can re-add this node. The goal is to avoid reading a removed
258257
* node for some time. */
259258
dictType clusterNodesBlackListDictType = {
260-
.entryGetKey = dictEntryGetKey,
261259
.hashFunction = dictSdsCaseHash,
262260
.keyCompare = dictSdsKeyCaseCompare,
263261
.entryDestructor = dictEntryDestructorSdsKey,
264262
};
265263

266264
/* Cluster shards hash table, mapping shard id to list of nodes */
267265
dictType clusterSdsToListType = {
268-
.entryGetKey = dictEntryGetKey,
269266
.hashFunction = dictSdsHash,
270267
.keyCompare = dictSdsKeyCompare,
271268
.entryDestructor = dictEntryDestructorSdsKeyListValue,
@@ -283,7 +280,6 @@ static int dictPtrCompare(const void *key1, const void *key2) {
283280
/* Dictionary type for mapping hash slots to cluster nodes.
284281
* Keys are slot numbers encoded directly as pointer values, values are clusterNode pointers. */
285282
dictType clusterSlotDictType = {
286-
.entryGetKey = dictEntryGetKey,
287283
.hashFunction = dictPtrHash,
288284
.keyCompare = dictPtrCompare,
289285
.entryDestructor = zfree,

src/config.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,14 +1047,12 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state);
10471047
* like "maxmemory" -> list of line numbers (first line is zero).
10481048
*/
10491049
dictType optionToLineDictType = {
1050-
.entryGetKey = dictEntryGetKey,
10511050
.hashFunction = dictSdsCaseHash,
10521051
.keyCompare = dictSdsKeyCaseCompare,
10531052
.entryDestructor = dictEntryDestructorSdsKeyListValue,
10541053
};
10551054

10561055
dictType optionSetDictType = {
1057-
.entryGetKey = dictEntryGetKey,
10581056
.hashFunction = dictSdsCaseHash,
10591057
.keyCompare = dictSdsKeyCaseCompare,
10601058
.entryDestructor = dictEntryDestructorSdsKey,

src/defrag.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -299,41 +299,18 @@ static void activeDefragZsetNode(void *privdata, void *entry_ref) {
299299
#define DEFRAG_SDS_DICT_VAL_VOID_PTR 3
300300
#define DEFRAG_SDS_DICT_VAL_LUA_SCRIPT 4
301301

302-
typedef void *(dictDefragAllocFunction)(void *ptr);
303-
typedef struct {
304-
dictDefragAllocFunction *defragKey;
305-
dictDefragAllocFunction *defragVal;
306-
} dictDefragFunctions;
307302

308303
static void activeDefragDictCallback(void *privdata, void *entry_ref) {
309304
dictDefragFunctions *defragfns = privdata;
310305
dictEntry **de_ref = (dictEntry **)entry_ref;
311-
dictEntry *de = *de_ref;
312-
313-
/* Defrag the entry itself */
314-
dictEntry *newentry = activeDefragAlloc(de);
315-
if (newentry) {
316-
de = newentry;
317-
*de_ref = newentry;
318-
}
319-
320-
/* Defrag the key */
321-
if (defragfns->defragKey) {
322-
void *newkey = defragfns->defragKey(de->key);
323-
if (newkey) de->key = newkey;
324-
}
325-
326-
/* Defrag the value */
327-
if (defragfns->defragVal) {
328-
void *newval = defragfns->defragVal(de->v.val);
329-
if (newval) de->v.val = newval;
330-
}
306+
htdictDefragEntry(de_ref, defragfns);
331307
}
332308

333309
/* Defrag a dict with sds key and optional value (either ptr, sds or robj string) */
334310
static void activeDefragSdsDict(dict *d, int val_type) {
335311
unsigned long cursor = 0;
336312
dictDefragFunctions defragfns = {
313+
.defragAlloc = activeDefragAlloc,
337314
.defragKey = (dictDefragAllocFunction *)activeDefragSds,
338315
.defragVal = (val_type == DEFRAG_SDS_DICT_VAL_IS_SDS ? (dictDefragAllocFunction *)activeDefragSds
339316
: val_type == DEFRAG_SDS_DICT_VAL_IS_STROB ? (dictDefragAllocFunction *)activeDefragStringOb

0 commit comments

Comments
 (0)