Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
e6e1853f
Commit
e6e1853f
authored
Mar 16, 2023
by
Vitaly Arbuzov
Browse files
NULL out intset when cluster mode is disabled
parent
eed189ff
Changes
2
Show whitespace changes
Inline
Side-by-side
src/db.c
View file @
e6e1853f
...
@@ -72,6 +72,7 @@ void dbIteratorInit(dbIterator *dbit, redisDb *db) {
...
@@ -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. */
/* Returns next non-empty dictionary strictly after provided slot and updates slot id in the supplied reference. */
dict *dbGetNextNonEmptySlot(redisDb *db, int *slot) {
dict *dbGetNextNonEmptySlot(redisDb *db, int *slot) {
if (server.cluster_enabled) {
uint32_t pos;
uint32_t pos;
int found = intsetSearch(db->non_empty_dicts, *slot, &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. */
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) {
...
@@ -80,6 +81,7 @@ dict *dbGetNextNonEmptySlot(redisDb *db, int *slot) {
*slot = (int) next_slot;
*slot = (int) next_slot;
return db->dict[*slot];
return db->dict[*slot];
}
}
}
*slot = -1;
*slot = -1;
return NULL;
return NULL;
}
}
...
@@ -404,7 +406,7 @@ robj *dbRandomKey(redisDb *db) {
...
@@ -404,7 +406,7 @@ robj *dbRandomKey(redisDb *db) {
/* Return random non-empty dictionary from this DB. */
/* Return random non-empty dictionary from this DB. */
dict *getRandomDict(redisDb *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);
int64_t slot = intsetRandom(db->non_empty_dicts);
return db->dict[slot];
return db->dict[slot];
}
}
...
@@ -539,9 +541,11 @@ long long emptyDbStructure(redisDb *dbarray, int dbnum, int async,
...
@@ -539,9 +541,11 @@ long long emptyDbStructure(redisDb *dbarray, int dbnum, int async,
dbarray[j].expires_cursor = 0;
dbarray[j].expires_cursor = 0;
dbarray[j].resize_cursor = 0;
dbarray[j].resize_cursor = 0;
dbarray[j].key_count = 0;
dbarray[j].key_count = 0;
if (server.cluster_enabled) {
zfree(dbarray[j].non_empty_dicts);
zfree(dbarray[j].non_empty_dicts);
dbarray[j].non_empty_dicts = intsetNew();
dbarray[j].non_empty_dicts = intsetNew();
}
}
}
return removed;
return removed;
}
}
...
@@ -608,7 +612,7 @@ redisDb *initTempDb(void) {
...
@@ -608,7 +612,7 @@ redisDb *initTempDb(void) {
tempDb[i].dict_count = (server.cluster_enabled) ? CLUSTER_SLOTS : 1;
tempDb[i].dict_count = (server.cluster_enabled) ? CLUSTER_SLOTS : 1;
tempDb[i].dict = dictCreateMultiple(&dbDictType, tempDb[i].dict_count);
tempDb[i].dict = dictCreateMultiple(&dbDictType, tempDb[i].dict_count);
tempDb[i].expires = dictCreate(&dbExpiresDictType);
tempDb[i].expires = dictCreate(&dbExpiresDictType);
tempDb
[
i
].
non_empty_dicts
=
intsetNew
();
tempDb[i].non_empty_dicts =
server.cluster_enabled ?
intsetNew()
: NULL
;
}
}
return tempDb;
return tempDb;
...
@@ -626,7 +630,7 @@ void discardTempDb(redisDb *tempDb, void(callback)(dict*)) {
...
@@ -626,7 +630,7 @@ void discardTempDb(redisDb *tempDb, void(callback)(dict*)) {
}
}
zfree(tempDb[i].dict);
zfree(tempDb[i].dict);
dictRelease(tempDb[i].expires);
dictRelease(tempDb[i].expires);
zfree
(
tempDb
[
i
].
non_empty_dicts
);
if (server.cluster_enabled)
zfree(tempDb[i].non_empty_dicts);
}
}
zfree(tempDb);
zfree(tempDb);
...
...
src/server.c
View file @
e6e1853f
...
@@ -2602,7 +2602,7 @@ void initServer(void) {
...
@@ -2602,7 +2602,7 @@ void initServer(void) {
server.db[j].rehashing = listCreate();
server.db[j].rehashing = listCreate();
server.db[j].dict_count = slotCount;
server.db[j].dict_count = slotCount;
server.db[j].key_count = 0;
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);
listSetFreeMethod(server.db[j].defrag_later,(void (*)(void*))sdsfree);
}
}
evictionPoolAlloc(); /* Initialize the LRU keys pool. */
evictionPoolAlloc(); /* Initialize the LRU keys pool. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment