Ensure local server is always a raft peer

pull/19/head
Armon Dadgar 11 years ago
parent 21b43553bb
commit c3866c9516

@ -192,6 +192,16 @@ func (s *Server) setupRaft() error {
// Setup the peer store
s.raftPeers = raft.NewJSONPeers(path, trans)
// Ensure local host is always included
peers, err := s.raftPeers.Peers()
if err != nil {
store.Close()
return err
}
if !raft.PeerContained(peers, trans.LocalAddr()) {
s.raftPeers.SetPeers(raft.AddUniquePeer(peers, trans.LocalAddr()))
}
// Setup the Raft store
s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, store, store,
snapshots, s.raftPeers, trans)

@ -47,3 +47,20 @@ func TestStatusLeader(t *testing.T) {
t.Fatalf("no leader")
}
}
func TestStatusPeers(t *testing.T) {
dir1, s1 := testServer(t)
defer os.RemoveAll(dir1)
defer s1.Shutdown()
client := rpcClient(t, s1)
defer client.Close()
arg := struct{}{}
var peers []string
if err := client.Call("Status.Peers", arg, &peers); err != nil {
t.Fatalf("err: %v", err)
}
if len(peers) != 1 {
t.Fatalf("no peers: %v", peers)
}
}

Loading…
Cancel
Save