From 725762c48d6465f65f1b5ead4126a72674ce6a83 Mon Sep 17 00:00:00 2001 From: linyi-xq Date: Tue, 23 Mar 2021 11:00:33 +0800 Subject: [PATCH] clusterState->mf_master_offset init offset change to -1 (#8651) resolve cluster failover timeout when master repl_offset is 0 --- src/cluster.c | 6 +++--- src/cluster.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 1c1f0389c..ee30cf6be 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1811,7 +1811,7 @@ int clusterProcessPacket(clusterLink *link) { nodeIsSlave(myself) && myself->slaveof == sender && hdr->mflags[0] & CLUSTERMSG_FLAG0_PAUSED && - server.cluster->mf_master_offset == 0) + server.cluster->mf_master_offset == -1) { server.cluster->mf_master_offset = sender->repl_offset; clusterDoBeforeSleep(CLUSTER_TODO_HANDLE_MANUALFAILOVER); @@ -3419,7 +3419,7 @@ void resetManualFailover(void) { server.cluster->mf_end = 0; /* No manual failover in progress. */ server.cluster->mf_can_start = 0; server.cluster->mf_slave = NULL; - server.cluster->mf_master_offset = 0; + server.cluster->mf_master_offset = -1; } /* If a manual failover timed out, abort it. */ @@ -3440,7 +3440,7 @@ void clusterHandleManualFailover(void) { * next steps are performed by clusterHandleSlaveFailover(). */ if (server.cluster->mf_can_start) return; - if (server.cluster->mf_master_offset == 0) return; /* Wait for offset... */ + if (server.cluster->mf_master_offset == -1) return; /* Wait for offset... */ if (server.cluster->mf_master_offset == replicationGetSlaveOffset()) { /* Our replication offset matches the master replication offset diff --git a/src/cluster.h b/src/cluster.h index 716c0d49c..ed1ad5c3a 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -168,7 +168,7 @@ typedef struct clusterState { clusterNode *mf_slave; /* Slave performing the manual failover. */ /* Manual failover state of slave. */ long long mf_master_offset; /* Master offset the slave needs to start MF - or zero if still not received. */ + or -1 if still not received. */ int mf_can_start; /* If non-zero signal that the manual failover can start requesting masters vote. */ /* The following fields are used by masters to take state on elections. */