Unverified Commit dedbf99a authored by Binbin's avatar Binbin Committed by GitHub
Browse files

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.
parent 58cb3025
......@@ -80,6 +80,7 @@ int clusterNodeIsMyself(clusterNode *n);
clusterNode *getMyClusterNode(void);
char *getMyClusterId(void);
int getClusterSize(void);
int getMyClusterSlotCount(void);
int handleDebugClusterCommand(client *c);
int clusterNodePending(clusterNode *node);
int clusterNodeIsMaster(clusterNode *n);
......
......@@ -5773,6 +5773,10 @@ int getClusterSize(void) {
return dictSize(server.cluster->nodes);
}
int getMyClusterSlotCount(void) {
return server.cluster->myself->numslots;
}
char **getClusterNodesList(size_t *numnodes) {
size_t count = dictSize(server.cluster->nodes);
char **ids = zmalloc((count+1)*CLUSTER_NAMELEN);
......
......@@ -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) {
dict *d;
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++) {
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) {
d = db->dict[i];
} else {
......
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