From f16d13213ca13f79f91a105d8dfd6c55b3841f62 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 27 May 2014 15:23:25 -0700 Subject: [PATCH] consul: remove explicit leave, use reconciliation --- consul/endpoints.md | 8 -------- consul/raft_endpoint.go | 25 ------------------------ consul/server.go | 42 ----------------------------------------- 3 files changed, 75 deletions(-) delete mode 100644 consul/raft_endpoint.go diff --git a/consul/endpoints.md b/consul/endpoints.md index c109afaeba..e7a463e57a 100644 --- a/consul/endpoints.md +++ b/consul/endpoints.md @@ -3,18 +3,10 @@ Consul provides a few high-level services, each of which exposes methods. The services exposed are: -* Raft : Used to manipulate Raft from non-leader nodes * Status : Used to query status information * Catalog: Used to register, deregister, and query service information * Health: Used to notify of health checks and changes to health -## Raft Service - -The Raft service is used to manipulate the Raft controls on the Leader -node. It is only for internal use. It exposes the following methods: - -* RemovePeer: Used to remove a peer from the group - ## Status Service The status service is used to query for various status information diff --git a/consul/raft_endpoint.go b/consul/raft_endpoint.go deleted file mode 100644 index 97b7adf746..0000000000 --- a/consul/raft_endpoint.go +++ /dev/null @@ -1,25 +0,0 @@ -package consul - -import ( - "net" -) - -// Raft endpoint is used to manipulate the Raft subsystem -type Raft struct { - server *Server -} - -func (r *Raft) RemovePeer(args string, reply *struct{}) error { - peer, err := net.ResolveTCPAddr("tcp", args) - if err != nil { - r.server.logger.Printf("[ERR] consul.raft: failed to parse peer: %v", err) - return err - } - future := r.server.raft.RemovePeer(peer) - return future.Error() -} - -func (r *Raft) Snapshot(args struct{}, reply *struct{}) error { - future := r.server.raft.Snapshot() - return future.Error() -} diff --git a/consul/server.go b/consul/server.go index 9cc808f05a..ba2976192a 100644 --- a/consul/server.go +++ b/consul/server.go @@ -113,7 +113,6 @@ type Server struct { type endpoints struct { Catalog *Catalog Health *Health - Raft *Raft Status *Status KVS *KVS Session *Session @@ -322,7 +321,6 @@ func (s *Server) setupRaft() error { func (s *Server) setupRPC(tlsConfig *tls.Config) error { // Create endpoints s.endpoints.Status = &Status{s} - s.endpoints.Raft = &Raft{s} s.endpoints.Catalog = &Catalog{s} s.endpoints.Health = &Health{s} s.endpoints.KVS = &KVS{s} @@ -331,7 +329,6 @@ func (s *Server) setupRPC(tlsConfig *tls.Config) error { // Register the handlers s.rpcServer.Register(s.endpoints.Status) - s.rpcServer.Register(s.endpoints.Raft) s.rpcServer.Register(s.endpoints.Catalog) s.rpcServer.Register(s.endpoints.Health) s.rpcServer.Register(s.endpoints.KVS) @@ -437,45 +434,6 @@ func (s *Server) Leave() error { s.logger.Printf("[ERR] consul: failed to leave LAN Serf cluster: %v", err) } } - - // Leave the Raft cluster - if s.raft != nil { - // Check if we have other raft nodes - peers, _ := s.raftPeers.Peers() - if len(peers) <= 1 { - s.logger.Printf("[WARN] consul: not leaving Raft cluster, no peers") - goto AFTER_LEAVE - } - - // Get the leader - leader := s.raft.Leader() - if leader == nil { - s.logger.Printf("[ERR] consul: failed to leave Raft cluster: no leader") - goto AFTER_LEAVE - } - - // Request that we are removed - ch := make(chan error, 1) - go func() { - var out struct{} - peer := s.raftTransport.LocalAddr().String() - // TODO: Correct version - err := s.connPool.RPC(leader, 1, "Raft.RemovePeer", peer, &out) - ch <- err - }() - - // Wait for the commit - select { - case err := <-ch: - // Ignore if we have already been deregistered by the leader - if err != nil && err.Error() != raft.ErrUnknownPeer.Error() { - s.logger.Printf("[ERR] consul: failed to leave Raft cluster: %v", err) - } - case <-time.After(3 * time.Second): - s.logger.Printf("[ERR] consul: timed out leaving Raft cluster") - } - } -AFTER_LEAVE: return nil }