mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Cluster: mark cluster state as fail of majority of masters is unreachable.
This commit is contained in:
parent
abf06fd5ff
commit
299b8f76c2
@ -1451,6 +1451,7 @@ int clusterDelSlot(int slot) {
|
|||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
void clusterUpdateState(void) {
|
void clusterUpdateState(void) {
|
||||||
int j, initial_state = server.cluster->state;
|
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
|
/* Start assuming the state is OK. We'll turn it into FAIL if there
|
||||||
* are the right conditions. */
|
* are the right conditions. */
|
||||||
@ -1467,7 +1468,10 @@ void clusterUpdateState(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compute the cluster size, that is the number of master nodes
|
/* 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;
|
dictIterator *di;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
@ -1477,12 +1481,25 @@ void clusterUpdateState(void) {
|
|||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
clusterNode *node = dictGetVal(de);
|
clusterNode *node = dictGetVal(de);
|
||||||
|
|
||||||
if (node->flags & REDIS_NODE_MASTER && node->numslots)
|
if (node->flags & REDIS_NODE_MASTER && node->numslots) {
|
||||||
server.cluster->size++;
|
server.cluster->size++;
|
||||||
|
if (node->flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL))
|
||||||
|
unreachable_masters++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dictReleaseIterator(di);
|
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 */
|
/* Log a state change */
|
||||||
if (initial_state != server.cluster->state)
|
if (initial_state != server.cluster->state)
|
||||||
redisLog(REDIS_WARNING,"Cluster state changed: %s",
|
redisLog(REDIS_WARNING,"Cluster state changed: %s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user