From dbc9eeb8a74f3857335a877e520df6d75be436fc Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 9 Dec 2013 15:29:01 -0800 Subject: [PATCH] consul: store the peerstore --- consul/server.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/consul/server.go b/consul/server.go index 1323e3772d..7a70d14faa 100644 --- a/consul/server.go +++ b/consul/server.go @@ -46,6 +46,7 @@ type Server struct { // DC to protect operations that require strong consistency raft *raft.Raft raftLayer *RaftLayer + raftPeers raft.PeerStore raftStore *raft.SQLiteStore raftTransport *raft.NetworkTransport @@ -104,6 +105,12 @@ func NewServer(config *Config) (*Server, error) { return nil, fmt.Errorf("Failed to start RPC layer: %v", err) } + // Initialize the Raft server + if err := s.setupRaft(); err != nil { + s.Shutdown() + return nil, fmt.Errorf("Failed to start Raft: %v", err) + } + // Start the Serf listeners to prevent a deadlock go s.lanEventHandler() go s.wanEventHandler() @@ -125,12 +132,6 @@ func NewServer(config *Config) (*Server, error) { return nil, fmt.Errorf("Failed to start wan serf: %v", err) } - // Initialize the Raft server - if err := s.setupRaft(); err != nil { - s.Shutdown() - return nil, fmt.Errorf("Failed to start Raft: %v", err) - } - return s, nil } @@ -183,14 +184,14 @@ func (s *Server) setupRaft() error { s.raftTransport = trans // Setup the peer store - peers := raft.NewJSONPeers(path, trans) + s.raftPeers = raft.NewJSONPeers(path, trans) // Create the FSM s.fsm = &consulFSM{server: s} // Setup the Raft store - s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, store, store, snapshots, - peers, trans) + s.raft, err = raft.NewRaft(s.config.RaftConfig, s.fsm, store, store, + snapshots, s.raftPeers, trans) if err != nil { store.Close() trans.Close() @@ -202,6 +203,7 @@ func (s *Server) setupRaft() error { // setupRPC is used to setup the RPC listener func (s *Server) setupRPC() error { // Register the handlers + s.rpcServer.Register(&Status{server: s}) s.rpcServer.Register(&Raft{server: s}) list, err := net.Listen("tcp", s.config.RPCAddr)