Skip to content

Commit f428b69

Browse files
enjoy-binbinzuiderkwast
authored andcommitted
Save config file and brocast the PONG when configEpoch changed (#1813)
This is somehow related with #974 and #1777. When the epoch changes, we should save the configuration file and broadcast a PONG as much as possible. For example, if a primary down after bumping the epoch, its replicas may initiate a failover, but the other primaries may refuse to vote because the epoch of the replica has not been updated. Or for example, for some reasons we bump the epoch, if the epoch is not updated in time in the cluster, it may affect the judgment of message staleness. These broadcasts are expensive in large clusters, but none of these seem high frequency so it should be fine. --------- Signed-off-by: Binbin <[email protected]>
1 parent 5ac885a commit f428b69

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/cluster_legacy.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ int clusterBumpConfigEpochWithoutConsensus(void) {
19381938
if (myself->configEpoch == 0 || myself->configEpoch != maxEpoch) {
19391939
server.cluster->currentEpoch++;
19401940
myself->configEpoch = server.cluster->currentEpoch;
1941-
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG);
1941+
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG | CLUSTER_TODO_BROADCAST_ALL);
19421942
serverLog(LL_NOTICE, "New configEpoch set to %llu", (unsigned long long)myself->configEpoch);
19431943
return C_OK;
19441944
} else {
@@ -2001,7 +2001,7 @@ void clusterHandleConfigEpochCollision(clusterNode *sender) {
20012001
/* Get the next ID available at the best of this node knowledge. */
20022002
server.cluster->currentEpoch++;
20032003
myself->configEpoch = server.cluster->currentEpoch;
2004-
clusterSaveConfigOrDie(1);
2004+
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG | CLUSTER_TODO_BROADCAST_ALL);
20052005
serverLog(LL_NOTICE, "configEpoch collision with node %.40s (%s). configEpoch set to %llu", sender->name,
20062006
sender->human_nodename, (unsigned long long)myself->configEpoch);
20072007
}
@@ -4774,13 +4774,13 @@ void clusterFailoverReplaceYourPrimary(void) {
47744774
}
47754775
}
47764776

4777-
/* 3) Update state and save config. */
4777+
/* 3) Update state, note that we do not use CLUSTER_TODO_UPDATE_STATE since we want the node
4778+
* to update the cluster state ASAP after failover. */
47784779
clusterUpdateState();
4779-
clusterSaveConfigOrDie(1);
47804780

4781-
/* 4) Pong all the other nodes so that they can update the state
4781+
/* 4) Save and fsync the config, and pong all the other nodes so that they can update the state
47824782
* accordingly and detect that we switched to primary role. */
4783-
clusterDoBeforeSleep(CLUSTER_TODO_BROADCAST_ALL);
4783+
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG | CLUSTER_TODO_BROADCAST_ALL);
47844784

47854785
/* 5) If there was a manual failover in progress, clear the state. */
47864786
resetManualFailover();
@@ -4963,6 +4963,7 @@ void clusterHandleReplicaFailover(void) {
49634963
/* Update my configEpoch to the epoch of the election. */
49644964
if (myself->configEpoch < server.cluster->failover_auth_epoch) {
49654965
myself->configEpoch = server.cluster->failover_auth_epoch;
4966+
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG | CLUSTER_TODO_BROADCAST_ALL);
49664967
serverLog(LL_NOTICE, "configEpoch set to %llu after successful failover",
49674968
(unsigned long long)myself->configEpoch);
49684969
}

0 commit comments

Comments
 (0)