Commit e6e1853f authored by Vitaly Arbuzov's avatar Vitaly Arbuzov
Browse files

NULL out intset when cluster mode is disabled

parent eed189ff
......@@ -72,6 +72,7 @@ void dbIteratorInit(dbIterator *dbit, redisDb *db) {
/* Returns next non-empty dictionary strictly after provided slot and updates slot id in the supplied reference. */
dict *dbGetNextNonEmptySlot(redisDb *db, int *slot) {
if (server.cluster_enabled) {
uint32_t pos;
int found = intsetSearch(db->non_empty_dicts, *slot, &pos);
if (found) pos++; /* If current slot exists in the non-empty list, then we want next one, otherwise pos already points to it. */
......@@ -80,6 +81,7 @@ dict *dbGetNextNonEmptySlot(redisDb *db, int *slot) {
*slot = (int) next_slot;
return db->dict[*slot];
}
}
*slot = -1;
return NULL;
}
......@@ -404,7 +406,7 @@ robj *dbRandomKey(redisDb *db) {
/* Return random non-empty dictionary from this DB. */
dict *getRandomDict(redisDb *db) {
if (db->dict_count == 1 || dbSize(db) == 0) return db->dict[0];
if (!server.cluster_enabled || dbSize(db) == 0) return db->dict[0];
int64_t slot = intsetRandom(db->non_empty_dicts);
return db->dict[slot];
}
......@@ -539,9 +541,11 @@ long long emptyDbStructure(redisDb *dbarray, int dbnum, int async,
dbarray[j].expires_cursor = 0;
dbarray[j].resize_cursor = 0;
dbarray[j].key_count = 0;
if (server.cluster_enabled) {
zfree(dbarray[j].non_empty_dicts);
dbarray[j].non_empty_dicts = intsetNew();
}
}
return removed;
}
......@@ -608,7 +612,7 @@ redisDb *initTempDb(void) {
tempDb[i].dict_count = (server.cluster_enabled) ? CLUSTER_SLOTS : 1;
tempDb[i].dict = dictCreateMultiple(&dbDictType, tempDb[i].dict_count);
tempDb[i].expires = dictCreate(&dbExpiresDictType);
tempDb[i].non_empty_dicts = intsetNew();
tempDb[i].non_empty_dicts = server.cluster_enabled ? intsetNew() : NULL;
}
return tempDb;
......@@ -626,7 +630,7 @@ void discardTempDb(redisDb *tempDb, void(callback)(dict*)) {
}
zfree(tempDb[i].dict);
dictRelease(tempDb[i].expires);
zfree(tempDb[i].non_empty_dicts);
if (server.cluster_enabled) zfree(tempDb[i].non_empty_dicts);
}
zfree(tempDb);
......
......@@ -2602,7 +2602,7 @@ void initServer(void) {
server.db[j].rehashing = listCreate();
server.db[j].dict_count = slotCount;
server.db[j].key_count = 0;
server.db[j].non_empty_dicts = intsetNew();
server.db[j].non_empty_dicts = server.cluster_enabled ? intsetNew() : NULL;
listSetFreeMethod(server.db[j].defrag_later,(void (*)(void*))sdsfree);
}
evictionPoolAlloc(); /* Initialize the LRU keys pool. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment