Skip to content

Commit

Permalink
discover nodes in memberlist for raft join config
Browse files Browse the repository at this point in the history
  • Loading branch information
moogacs committed Apr 26, 2024
1 parent 8c1d9d6 commit c63f37f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions adapters/handlers/rest/configure_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ func MakeAppState(ctx context.Context, options *swag.CommandLineOptionsGroup) *s
schemaTxPersistence := txstore.NewStore(
appState.ServerConfig.Config.Persistence.DataPath, appState.Logger)

/// TODO-RAFT START
//
server2port, err := parseNode2Port(appState)
server2port, err := discoverNodes2Port(appState)
if len(server2port) == 0 || err != nil {
appState.Logger.
WithField("action", "startup").
Expand Down Expand Up @@ -426,8 +424,13 @@ func MakeAppState(ctx context.Context, options *swag.CommandLineOptionsGroup) *s
return appState
}

func parseNode2Port(appState *state.State) (m map[string]int, err error) {
m = make(map[string]int, len(appState.ServerConfig.Config.Raft.Join))
// discoverNodes2Port it will collect nodes info from configrued RAFT_JOIN, RAFT_PORT
// and will get nodes from memberlist if weren't configured and assign them with
// default RAFT port
func discoverNodes2Port(appState *state.State) (m map[string]int, err error) {
m = make(map[string]int, len(appState.Cluster.AllNames()))

// parse RAFT_JOIN config
for _, raftNamePort := range appState.ServerConfig.Config.Raft.Join {
np := strings.Split(raftNamePort, ":")
if np[0] == appState.Cluster.LocalName() {
Expand All @@ -439,6 +442,16 @@ func parseNode2Port(appState *state.State) (m map[string]int, err error) {
}
}

// memberlist doesn't match raft join
if len(appState.ServerConfig.Config.Raft.Join) != len(appState.Cluster.AllNames()) {
for _, n := range appState.Cluster.AllNames() {
if n == appState.Cluster.LocalName() {
continue
}
m[n] = config.DefaultRaftInternalPort
}
}

return m, nil
}

Expand Down

0 comments on commit c63f37f

Please sign in to comment.