raft
raft copied to clipboard
Nodes try to self connect when given predefined config
Hi there and thanks for sharing this project. I'm keen to introduce Raft into one of my projects in which there is a predefined cluster. During boot I'm getting the follower error on 2 of the three nodes:
panic: raft.membership: attempted to send msg to local member; should never happen
Here is the relevant code
func raftInit() {
raftgrpc.Register(
raftgrpc.WithDialOptions(grpc.WithInsecure()),
)
fsm = newstateMachine()
node = raft.NewNode(fsm, transport.GRPC)
raftServer = grpc.NewServer()
raftgrpc.RegisterHandler(raftServer, node.Handler())
m1 := raft.RawMember{ID: 1, Address: "host1:8081"}
m2 := raft.RawMember{ID: 2, Address: "host2:8081"}
m3 := raft.RawMember{ID: 3, Address: "host3:8081"}
go func() {
lis, err := net.Listen("tcp", ":8081")
if err != nil {
log.Fatal(err)
}
err = raftServer.Serve(lis)
if err != nil {
log.Fatal(err)
}
}()
go func() {
err := node.Start(raft.WithInitCluster(), raft.WithMembers(m1, m2, m3) )
if err != nil {
log.Fatal(err)
}
}()
}
Not sure if this is misconfigured on my side or if there's an issue here. Would greatly appreciate you assistance.
@alexanderturner Unable to reproduce the issue from the given code, do you use the same WithMembers configuration with all hosts?
Docs:
WithMembers add the given members to the raft node.
WithMembers safe to be used with initiate cluster kind options, ("WithForceNewCluster", "WithRestore", "WithInitCluster") Otherwise, it may conflicts with other options like WithJoin.
As long as only one url member, WithMembers will only set the current node, then it will be safe to be composed with other options even "WithJoin".
WithMembers and WithInitCluster must be applied to all cluster nodes when they are composed, Otherwise, the quorum will be lost and the cluster become unavailable.
Node A:
n.Start(WithInitCluster(), WithMembers(<node A>, <node B>))
Node B:
n.Start(WithInitCluster(), WithMembers(<node B>, <node A>))
Note: the first member will be assigned to the current node.