Skip to content

Commit

Permalink
adjust bootstrapExpect to match RAFT_JOIN adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
moogacs committed May 1, 2024
1 parent c221fb1 commit 2165de3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions adapters/handlers/rest/configure_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ func MakeAppState(ctx context.Context, options *swag.CommandLineOptionsGroup) *s
Fatal("parsing raft-join")
}

adjustBootStrapExpect(appState, server2port)

nodeName := appState.Cluster.LocalName()
nodeAddr, _ := appState.Cluster.NodeHostname(nodeName)
addrs := strings.Split(nodeAddr, ":")
Expand Down Expand Up @@ -435,7 +437,7 @@ func MakeAppState(ctx context.Context, options *swag.CommandLineOptionsGroup) *s

// discoverNodes2Port it will collect nodes info from configured RAFT_JOIN, RAFT_PORT
// and will get nodes from memberlist if weren't configured and assign them with
// default RAFT port if RAFT_JOIN config we one or less node
// default RAFT port incase RAFT_JOIN was 1 or less.
func discoverNodes2Port(appState *state.State) (m map[string]int, err error) {
exMemeberList := appState.Cluster.AllNames()
configuredRAFTJoin := appState.ServerConfig.Config.Raft.Join
Expand All @@ -455,19 +457,44 @@ func discoverNodes2Port(appState *state.State) (m map[string]int, err error) {
}

// memberlist doesn't match raft join and

if len(configuredRAFTJoin) <= 1 && len(configuredRAFTJoin) != len(exMemeberList) {
for _, n := range exMemeberList {
if n == appState.Cluster.LocalName() {
continue
}
m[n] = config.DefaultRaftInternalPort
appState.ServerConfig.Config.Raft.Join = append(appState.ServerConfig.Config.Raft.Join, n)
appState.Logger.WithFields(logrus.Fields{
"node_name": n,
"port": config.DefaultRaftInternalPort,
}).Warn("adjust raft join config")
}
}

return m, nil
}

// adjustBootStrapExpect it will also updates BootstrapExpect with the following number of voters
// 1-2 nodes -> 1 voter
// 3-9 nodes -> 3 voters
// 10- nodes -> 5 voters
func adjustBootStrapExpect(appState *state.State, nodesToPort map[string]int) {
adjustedBootstrapExpect := appState.ServerConfig.Config.Raft.BootstrapExpect
switch l := len(nodesToPort); {
case l <= 2:
adjustedBootstrapExpect = 1
case l > 2 && l < 10:
adjustedBootstrapExpect = 3
case l >= 10:
adjustedBootstrapExpect = 5

}
if appState.ServerConfig.Config.Raft.BootstrapExpect != adjustedBootstrapExpect {
appState.Logger.WithField("bootstrap_excpect", adjustedBootstrapExpect).Warn("adjust bootstrap excpect config")
}
appState.ServerConfig.Config.Raft.BootstrapExpect = adjustedBootstrapExpect
}

// parseVotersNames parses names of all voters.
// If we reach this point, we assume that the configuration is valid
func parseVotersNames(cfg config.Raft) (m map[string]struct{}) {
Expand Down

0 comments on commit 2165de3

Please sign in to comment.