Make emergency leadership only available in a cluster with two nodes

This commit is contained in:
Ingo Oppermann
2023-06-30 16:59:11 +02:00
parent c3b604cda2
commit c4d9d8afcb
2 changed files with 11 additions and 4 deletions

View File

@@ -1697,6 +1697,11 @@ func (c *cluster) sentinel() {
"num_peers": stats.NumPeers,
}).Log("Stats")
if stats.NumPeers > 1 {
// Enable emergency leadership only in a configuration with two nodes.
break
}
if stats.LastContact > c.emergencyLeaderTimeout && !isEmergencyLeader {
c.logger.Warn().Log("Force leadership due to lost contact to leader")
c.raftEmergencyNotifyCh <- true

View File

@@ -348,10 +348,7 @@ func (c *cluster) synchronizeAndRebalance(ctx context.Context, interval time.Dur
}
c.doSynchronize(emergency)
if !emergency {
c.doRebalance(emergency)
}
c.doRebalance(emergency)
} else {
c.doSynchronize(emergency)
}
@@ -588,6 +585,11 @@ func (c *cluster) doSynchronize(emergency bool) {
}
func (c *cluster) doRebalance(emergency bool) {
if emergency {
// Don't rebalance in emergency mode
return
}
have := c.proxy.ListProxyProcesses()
nodes := c.proxy.ListNodes()