Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xbasel committed Jan 27, 2025
1 parent cc457a7 commit 26256e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
28 changes: 11 additions & 17 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,23 +651,6 @@ long long emptyData(int dbnum, int flags, void(callback)(hashtable *)) {
return removed;
}

/* Initialize temporary db on replica for use during diskless replication. */
serverDb *initTempDb(int id) {
int slot_count_bits = 0;
int flags = KVSTORE_ALLOCATE_HASHTABLES_ON_DEMAND;
if (server.cluster_enabled) {
slot_count_bits = CLUSTER_SLOT_MASK_BITS;
flags |= KVSTORE_FREE_EMPTY_HASHTABLES;
}
serverDb *tempDb = zcalloc(sizeof(serverDb) * server.dbnum);

tempDb->id = id;
tempDb->keys = kvstoreCreate(&kvstoreKeysHashtableType, slot_count_bits, flags);
tempDb->expires = kvstoreCreate(&kvstoreExpiresHashtableType, slot_count_bits, flags);

return tempDb;
}

/* Discard tempDb, it's always async. */
void discardTempDb(serverDb **tempDb) {
/* Release temp DBs. */
Expand All @@ -676,6 +659,17 @@ void discardTempDb(serverDb **tempDb) {
if (tempDb[i]) {
kvstoreRelease(tempDb[i]->keys);
kvstoreRelease(tempDb[i]->expires);

/* These are expected to be empty on temporary databases */
serverAssert(dictSize(tempDb[i]->blocking_keys) == 0);
serverAssert(dictSize(tempDb[i]->blocking_keys_unblock_on_nokey) == 0);
serverAssert(dictSize(tempDb[i]->ready_keys) == 0);
serverAssert(dictSize(tempDb[i]->watched_keys) == 0);

dictRelease(tempDb[i]->blocking_keys);
dictRelease(tempDb[i]->blocking_keys_unblock_on_nokey);
dictRelease(tempDb[i]->ready_keys);
dictRelease(tempDb[i]->watched_keys);
zfree(tempDb[i]);
tempDb[i] = NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
uint64_t db_size = 0, expires_size = 0;
int should_expand_db = 0;
if (rdb_loading_ctx->dbarray[0] == NULL) {
rdb_loading_ctx->dbarray[0] = initTempDb(0);
rdb_loading_ctx->dbarray[0] = createDatabase(0);
}
serverDb *db = rdb_loading_ctx->dbarray[0];
char buf[1024];
Expand Down Expand Up @@ -3094,7 +3094,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
exit(1);
}
if (rdb_loading_ctx->dbarray[dbid] == NULL) {
rdb_loading_ctx->dbarray[dbid] = initTempDb(dbid);
rdb_loading_ctx->dbarray[dbid] = createDatabase(dbid);
}
db = rdb_loading_ctx->dbarray[dbid];
continue; /* Read next opcode. */
Expand Down
16 changes: 16 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,22 @@ int databaseEmpty(int id) {
return id < 0 || id >= server.dbnum || !server.db[id] || kvstoreSize(server.db[id]->keys) == 0;
}

// /* Initialize temporary db on replica for use during diskless replication. */
// serverDb *initTempDb(int id) {
// int slot_count_bits = 0;
// int flags = KVSTORE_ALLOCATE_HASHTABLES_ON_DEMAND;
// if (server.cluster_enabled) {
// slot_count_bits = CLUSTER_SLOT_MASK_BITS;
// flags |= KVSTORE_FREE_EMPTY_HASHTABLES;
// }
// serverDb *tempDb = zcalloc(sizeof(serverDb) * server.dbnum);
//
// tempDb->id = id;
// tempDb->keys = kvstoreCreate(&kvstoreKeysHashtableType, slot_count_bits, flags);
// tempDb->expires = kvstoreCreate(&kvstoreExpiresHashtableType, slot_count_bits, flags);
//
// return tempDb;
// }
serverDb *createDatabase(int id) {
int slot_count_bits = 0;
int flags = KVSTORE_ALLOCATE_HASHTABLES_ON_DEMAND;
Expand Down

0 comments on commit 26256e0

Please sign in to comment.