提交 d218a4e2 编写于 作者: A antirez

Cluster: new state information, cluster size.

The definition of cluster size is: the number of known nodes in the
cluster that are masters and serving at least an hash slot.
上级 5c55ed93
...@@ -217,6 +217,7 @@ void clusterInit(void) { ...@@ -217,6 +217,7 @@ void clusterInit(void) {
server.cluster = zmalloc(sizeof(clusterState)); server.cluster = zmalloc(sizeof(clusterState));
server.cluster->myself = NULL; server.cluster->myself = NULL;
server.cluster->state = REDIS_CLUSTER_FAIL; server.cluster->state = REDIS_CLUSTER_FAIL;
server.cluster->size = 1;
server.cluster->nodes = dictCreate(&clusterNodesDictType,NULL); server.cluster->nodes = dictCreate(&clusterNodesDictType,NULL);
server.cluster->node_timeout = 15; server.cluster->node_timeout = 15;
memset(server.cluster->migrating_slots_to,0, memset(server.cluster->migrating_slots_to,0,
...@@ -1254,6 +1255,24 @@ void clusterUpdateState(void) { ...@@ -1254,6 +1255,24 @@ void clusterUpdateState(void) {
} else { } else {
server.cluster->state = REDIS_CLUSTER_FAIL; server.cluster->state = REDIS_CLUSTER_FAIL;
} }
/* Compute the cluster size, that is the number of master nodes
* serving at least a single slot. */
{
dictIterator *di;
dictEntry *de;
server.cluster->size = 0;
di = dictGetIterator(server.cluster->nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);
if (node->flags & REDIS_NODE_MASTER &&
popcount(node->slots,sizeof(node->slots)))
server.cluster->size++;
}
dictReleaseIterator(di);
}
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
......
...@@ -570,6 +570,7 @@ typedef struct clusterNode clusterNode; ...@@ -570,6 +570,7 @@ typedef struct clusterNode clusterNode;
typedef struct { typedef struct {
clusterNode *myself; /* This node */ clusterNode *myself; /* This node */
int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */ int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */
int size; /* Num of master nodes with at least one slot */
int node_timeout; int node_timeout;
dict *nodes; /* Hash table of name -> clusterNode structures */ dict *nodes; /* Hash table of name -> clusterNode structures */
clusterNode *migrating_slots_to[REDIS_CLUSTER_SLOTS]; clusterNode *migrating_slots_to[REDIS_CLUSTER_SLOTS];
...@@ -960,6 +961,7 @@ long long mstime(void); ...@@ -960,6 +961,7 @@ long long mstime(void);
void getRandomHexChars(char *p, unsigned int len); void getRandomHexChars(char *p, unsigned int len);
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
void exitFromChild(int retcode); void exitFromChild(int retcode);
long popcount(void *s, long count);
/* networking.c -- Networking and Client related operations */ /* networking.c -- Networking and Client related operations */
redisClient *createClient(int fd); redisClient *createClient(int fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册