mirror of
https://github.com/fluencelabs/redis
synced 2025-03-21 01:50:50 +00:00
Cluster: fix logic to detect we are among a minority.
In the cluster evaluation function we are supposed to set the cluster state as "fail" if we are among a minority, however the code was not detecting to be into a minority partition if exactly half the masters were reachable, which is a minority.
This commit is contained in:
parent
908be1dbeb
commit
36e34a656a
@ -3235,7 +3235,7 @@ void clusterCloseAllSlots(void) {
|
|||||||
|
|
||||||
void clusterUpdateState(void) {
|
void clusterUpdateState(void) {
|
||||||
int j, new_state;
|
int j, new_state;
|
||||||
int unreachable_masters = 0;
|
int reachable_masters = 0;
|
||||||
static mstime_t among_minority_time;
|
static mstime_t among_minority_time;
|
||||||
static mstime_t first_call_time = 0;
|
static mstime_t first_call_time = 0;
|
||||||
|
|
||||||
@ -3271,8 +3271,8 @@ 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 the same time count the number of reachable masters having
|
||||||
* at least one node. */
|
* at least one slot. */
|
||||||
{
|
{
|
||||||
dictIterator *di;
|
dictIterator *di;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
@ -3284,20 +3284,19 @@ void clusterUpdateState(void) {
|
|||||||
|
|
||||||
if (nodeIsMaster(node) && node->numslots) {
|
if (nodeIsMaster(node) && node->numslots) {
|
||||||
server.cluster->size++;
|
server.cluster->size++;
|
||||||
if (node->flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL))
|
if ((node->flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL)) == 0)
|
||||||
unreachable_masters++;
|
reachable_masters++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we can't reach at least half the masters, change the cluster state
|
/* If we are in a minority partition, change the cluster state
|
||||||
* to FAIL, as we are not even able to mark nodes as FAIL in this side
|
* to FAIL. */
|
||||||
* of the netsplit because of lack of majority. */
|
|
||||||
{
|
{
|
||||||
int needed_quorum = (server.cluster->size / 2) + 1;
|
int needed_quorum = (server.cluster->size / 2) + 1;
|
||||||
|
|
||||||
if (unreachable_masters >= needed_quorum) {
|
if (reachable_masters < needed_quorum) {
|
||||||
new_state = REDIS_CLUSTER_FAIL;
|
new_state = REDIS_CLUSTER_FAIL;
|
||||||
among_minority_time = mstime();
|
among_minority_time = mstime();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user