Skip to content

Commit 08ff852

Browse files
committed
Defrag should only skip non-existent dbs, not empty dbs
In valkey-io#1609, we now doing on-demand database allocation instead of preallocation. And in beginDefragCycle, we should not skip empty databases if they exist. The defrag still defrags the internal allocations of the hashtables structs if they exist. Call chain: defragStageDbKeys -> defragStageKvstoreHelper -> kvstoreHashtableDefragTables -> hashtableDefragTables. Signed-off-by: Binbin <[email protected]>
1 parent a739531 commit 08ff852

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/defrag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ static doneStatus defragStageDbKeys(monotime endtime, void *target, void *privda
941941
UNUSED(privdata);
942942
int dbid = (uintptr_t)target;
943943
serverDb *db = server.db[dbid];
944+
if (db == NULL) return DEFRAG_DONE;
944945

945946
static defragKeysCtx ctx; // STATIC - this persists
946947
if (endtime == 0) {
@@ -959,6 +960,7 @@ static doneStatus defragStageExpiresKvstore(monotime endtime, void *target, void
959960
UNUSED(privdata);
960961
int dbid = (uintptr_t)target;
961962
serverDb *db = server.db[dbid];
963+
if (db == NULL) return DEFRAG_DONE;
962964
return defragStageKvstoreHelper(endtime, db->expires,
963965
scanHashtableCallbackCountScanned, NULL, NULL);
964966
}
@@ -1227,7 +1229,6 @@ static void beginDefragCycle(void) {
12271229
defrag.remaining_stages = listCreate();
12281230

12291231
for (int dbid = 0; dbid < server.dbnum; dbid++) {
1230-
if (dbHasNoKeys(dbid)) continue;
12311232
addDefragStage(defragStageDbKeys, (void *)(uintptr_t)dbid, NULL);
12321233
addDefragStage(defragStageExpiresKvstore, (void *)(uintptr_t)dbid, NULL);
12331234
}

0 commit comments

Comments
 (0)