mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 08:08:53 -05:00
Fix dbExpand not dividing by slots, resulting in consuming slots times the dictExpand (#12773)
We meant to divide it by the number of slots, otherwise it will do slots times dictExpand, bug was introduced in #11695.
This commit is contained in:
parent
58cb302526
commit
dedbf99a80
@ -80,6 +80,7 @@ int clusterNodeIsMyself(clusterNode *n);
|
|||||||
clusterNode *getMyClusterNode(void);
|
clusterNode *getMyClusterNode(void);
|
||||||
char *getMyClusterId(void);
|
char *getMyClusterId(void);
|
||||||
int getClusterSize(void);
|
int getClusterSize(void);
|
||||||
|
int getMyClusterSlotCount(void);
|
||||||
int handleDebugClusterCommand(client *c);
|
int handleDebugClusterCommand(client *c);
|
||||||
int clusterNodePending(clusterNode *node);
|
int clusterNodePending(clusterNode *node);
|
||||||
int clusterNodeIsMaster(clusterNode *n);
|
int clusterNodeIsMaster(clusterNode *n);
|
||||||
|
@ -5773,6 +5773,10 @@ int getClusterSize(void) {
|
|||||||
return dictSize(server.cluster->nodes);
|
return dictSize(server.cluster->nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getMyClusterSlotCount(void) {
|
||||||
|
return server.cluster->myself->numslots;
|
||||||
|
}
|
||||||
|
|
||||||
char **getClusterNodesList(size_t *numnodes) {
|
char **getClusterNodesList(size_t *numnodes) {
|
||||||
size_t count = dictSize(server.cluster->nodes);
|
size_t count = dictSize(server.cluster->nodes);
|
||||||
char **ids = zmalloc((count+1)*CLUSTER_NAMELEN);
|
char **ids = zmalloc((count+1)*CLUSTER_NAMELEN);
|
||||||
|
7
src/db.c
7
src/db.c
@ -2196,9 +2196,14 @@ int expireIfNeeded(redisDb *db, robj *key, int flags) {
|
|||||||
int dbExpand(const redisDb *db, uint64_t db_size, dbKeyType keyType, int try_expand) {
|
int dbExpand(const redisDb *db, uint64_t db_size, dbKeyType keyType, int try_expand) {
|
||||||
dict *d;
|
dict *d;
|
||||||
if (server.cluster_enabled) {
|
if (server.cluster_enabled) {
|
||||||
|
/* We don't know exact number of keys that would fall into each slot, but we can
|
||||||
|
* approximate it, assuming even distribution, divide it by the number of slots. */
|
||||||
|
int slots = getMyClusterSlotCount();
|
||||||
|
if (slots == 0) return C_OK;
|
||||||
|
db_size = db_size / slots;
|
||||||
|
|
||||||
for (int i = 0; i < CLUSTER_SLOTS; i++) {
|
for (int i = 0; i < CLUSTER_SLOTS; i++) {
|
||||||
if (clusterNodeCoversSlot(getMyClusterNode(), i)) {
|
if (clusterNodeCoversSlot(getMyClusterNode(), i)) {
|
||||||
/* We don't know exact number of keys that would fall into each slot, but we can approximate it, assuming even distribution. */
|
|
||||||
if (keyType == DB_MAIN) {
|
if (keyType == DB_MAIN) {
|
||||||
d = db->dict[i];
|
d = db->dict[i];
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user