Commit 4521115b authored by antirez's avatar antirez
Browse files

Cluster: new field in cluster node structure, "numslots".

Before a relatively slow popcount() operation was needed every time we
needed to get the number of slots served by a given cluster node.
Now we just need to check an integer that is taken in sync with the
bitmap.
parent a2566d66
......@@ -330,6 +330,7 @@ clusterNode *createClusterNode(char *nodename, int flags) {
getRandomHexChars(node->name, REDIS_CLUSTER_NAMELEN);
node->flags = flags;
memset(node->slots,0,sizeof(node->slots));
node->numslots = 0;
node->numslaves = 0;
node->slaves = NULL;
node->slaveof = NULL;
......@@ -884,6 +885,8 @@ int clusterProcessPacket(clusterLink *link) {
}
}
}
sender->numslots =
popcount(sender->slots,sizeof(sender->slots));
}
}
......@@ -1332,6 +1335,7 @@ int clusterNodeSetSlotBit(clusterNode *n, int slot) {
int bit = slot&7;
int old = (n->slots[byte] & (1<<bit)) != 0;
n->slots[byte] |= 1<<bit;
if (!old) n->numslots++;
return old;
}
......@@ -1341,6 +1345,7 @@ int clusterNodeClearSlotBit(clusterNode *n, int slot) {
int bit = slot&7;
int old = (n->slots[byte] & (1<<bit)) != 0;
n->slots[byte] &= ~(1<<bit);
if (old) n->numslots--;
return old;
}
......
......@@ -553,6 +553,7 @@ struct clusterNode {
char name[REDIS_CLUSTER_NAMELEN]; /* Node name, hex string, sha1-size */
int flags; /* REDIS_NODE_... */
unsigned char slots[REDIS_CLUSTER_SLOTS/8]; /* slots handled by this node */
int numslots; /* Number of slots handled by this node */
int numslaves; /* Number of slave nodes, if this is a master */
struct clusterNode **slaves; /* pointers to slave nodes */
struct clusterNode *slaveof; /* pointer to the master node */
......
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