mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
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.
This commit is contained in:
parent
a2566d6618
commit
4521115b17
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user