Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
299b8f76
Commit
299b8f76
authored
Mar 07, 2013
by
antirez
Browse files
Cluster: mark cluster state as fail of majority of masters is unreachable.
parent
abf06fd5
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
299b8f76
...
...
@@ -1451,6 +1451,7 @@ int clusterDelSlot(int slot) {
* -------------------------------------------------------------------------- */
void clusterUpdateState(void) {
int j, initial_state = server.cluster->state;
int unreachable_masters = 0;
/* Start assuming the state is OK. We'll turn it into FAIL if there
* are the right conditions. */
...
...
@@ -1467,7 +1468,10 @@ void clusterUpdateState(void) {
}
/* Compute the cluster size, that is the number of master nodes
* serving at least a single slot. */
* serving at least a single slot.
*
* At the same time count the number of unreachable masters with
* at least one node. */
{
dictIterator *di;
dictEntry *de;
...
...
@@ -1477,12 +1481,25 @@ void clusterUpdateState(void) {
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);
if (node->flags & REDIS_NODE_MASTER && node->numslots)
if (node->flags & REDIS_NODE_MASTER && node->numslots)
{
server.cluster->size++;
if (node->flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL))
unreachable_masters++;
}
}
dictReleaseIterator(di);
}
/* If we can't reach at least half the masters, change the cluster state
* as FAIL, as we are not even able to mark nodes as FAIL in this side
* of the netsplit because of lack of majority. */
{
int needed_quorum = (server.cluster->size / 2) + 1;
if (unreachable_masters >= needed_quorum)
server.cluster->state = REDIS_CLUSTER_FAIL;
}
/* Log a state change */
if (initial_state != server.cluster->state)
redisLog(REDIS_WARNING,"Cluster state changed: %s",
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment