Unverified Commit 8e11f84d authored by zhaozhao.zz's avatar zhaozhao.zz Committed by GitHub
Browse files

Fix replica node cannot expand dicts when loading legacy RDB (#12839)

When loading RDB on cluster nodes, it is necessary to consider the
scenario where a node is a replica.

For example, during a rolling upgrade, new version instances are often
mounted as replicas on old version instances. In this case, the full
synchronization legacy RDB does not contain slot information, and the
new version instance, acting as a replica, should be able to handle the
legacy RDB correctly for `dbExpand`.

Additionally, renaming `getMyClusterSlotCount` to `getMyShardSlotCount`
would be appropriate.

Introduced in #11695
parent e2a3f309
...@@ -80,7 +80,7 @@ int clusterNodeIsMyself(clusterNode *n); ...@@ -80,7 +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 getMyShardSlotCount(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);
......
...@@ -5781,8 +5781,14 @@ int getClusterSize(void) { ...@@ -5781,8 +5781,14 @@ int getClusterSize(void) {
return dictSize(server.cluster->nodes); return dictSize(server.cluster->nodes);
} }
int getMyClusterSlotCount(void) { int getMyShardSlotCount(void) {
return server.cluster->myself->numslots; if (!nodeIsSlave(server.cluster->myself)) {
return server.cluster->myself->numslots;
} else if (server.cluster->myself->slaveof) {
return server.cluster->myself->slaveof->numslots;
} else {
return 0;
}
} }
char **getClusterNodesList(size_t *numnodes) { char **getClusterNodesList(size_t *numnodes) {
......
...@@ -2215,7 +2215,7 @@ int dbExpand(const redisDb *db, uint64_t db_size, dbKeyType keyType, int try_exp ...@@ -2215,7 +2215,7 @@ int dbExpand(const redisDb *db, uint64_t db_size, dbKeyType keyType, int try_exp
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 /* 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. */ * approximate it, assuming even distribution, divide it by the number of slots. */
int slots = getMyClusterSlotCount(); int slots = getMyShardSlotCount();
if (slots == 0) return C_OK; if (slots == 0) return C_OK;
db_size = db_size / slots; db_size = db_size / slots;
......
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