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
e28e61e8
Commit
e28e61e8
authored
Mar 15, 2013
by
antirez
Browse files
Cluster: when failing over claim master slots.
parent
b8127e33
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
e28e61e8
...
@@ -1389,6 +1389,7 @@ void clusterHandleSlaveFailover(void) {
...
@@ -1389,6 +1389,7 @@ void clusterHandleSlaveFailover(void) {
time_t data_age = server.unixtime - server.repl_down_since;
time_t data_age = server.unixtime - server.repl_down_since;
time_t auth_age = server.unixtime - server.cluster->failover_auth_time;
time_t auth_age = server.unixtime - server.cluster->failover_auth_time;
int needed_quorum = (server.cluster->size / 2) + 1;
int needed_quorum = (server.cluster->size / 2) + 1;
int j;
/* Check if our data is recent enough. For now we just use a fixed
/* Check if our data is recent enough. For now we just use a fixed
* constant of ten times the node timeout since the cluster should
* constant of ten times the node timeout since the cluster should
...
@@ -1411,6 +1412,8 @@ void clusterHandleSlaveFailover(void) {
...
@@ -1411,6 +1412,8 @@ void clusterHandleSlaveFailover(void) {
/* Check if we reached the quorum. */
/* Check if we reached the quorum. */
if (server.cluster->failover_auth_count >= needed_quorum) {
if (server.cluster->failover_auth_count >= needed_quorum) {
clusterNode *oldmaster = server.cluster->myself->slaveof;
redisLog(REDIS_WARNING,
redisLog(REDIS_WARNING,
"Masters quorum reached: failing over my (failing) master.");
"Masters quorum reached: failing over my (failing) master.");
/* We have the quorum, perform all the steps to correctly promote
/* We have the quorum, perform all the steps to correctly promote
...
@@ -1424,9 +1427,21 @@ void clusterHandleSlaveFailover(void) {
...
@@ -1424,9 +1427,21 @@ void clusterHandleSlaveFailover(void) {
server.cluster->myself->slaveof = NULL;
server.cluster->myself->slaveof = NULL;
replicationUnsetMaster();
replicationUnsetMaster();
/* 2) Ping all the other nodes so that they can update the state
/* 2) Claim all the slots assigned to our master. */
for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
if (clusterNodeGetSlotBit(oldmaster,j)) {
clusterDelSlot(j);
clusterAddSlot(server.cluster->myself,j);
}
}
/* 3) Ping all the other nodes so that they can update the state
* accordingly and detect that we switched to master role. */
* accordingly and detect that we switched to master role. */
clusterBroadcastPing();
clusterBroadcastPing();
/* 4) Update state and save config. */
clusterUpdateState();
clusterSaveConfigOrDie();
}
}
}
}
...
...
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