diff --git a/consul/leader.go b/consul/leader.go index f8083fe046..5c2a85ef08 100644 --- a/consul/leader.go +++ b/consul/leader.go @@ -521,7 +521,7 @@ func (s *Server) joinConsulServer(m serf.Member, parts *serverParts) error { // Attempt to add as a peer var addr net.Addr = &net.TCPAddr{IP: m.Addr, Port: parts.Port} - future := s.raft.AddPeer(addr) + future := s.raft.AddPeer(addr.String()) if err := future.Error(); err != nil && err != raft.ErrKnownPeer { s.logger.Printf("[ERR] consul: failed to add raft peer: %v", err) return err @@ -533,7 +533,7 @@ func (s *Server) joinConsulServer(m serf.Member, parts *serverParts) error { func (s *Server) removeConsulServer(m serf.Member, port int) error { // Attempt to remove as peer peer := &net.TCPAddr{IP: m.Addr, Port: port} - future := s.raft.RemovePeer(peer) + future := s.raft.RemovePeer(peer.String()) if err := future.Error(); err != nil && err != raft.ErrUnknownPeer { s.logger.Printf("[ERR] consul: failed to remove raft peer '%v': %v", peer, err) diff --git a/consul/rpc.go b/consul/rpc.go index e0303e6efc..412c627de7 100644 --- a/consul/rpc.go +++ b/consul/rpc.go @@ -195,13 +195,13 @@ func (s *Server) forward(method string, info structs.RPCInfo, args interface{}, func (s *Server) forwardLeader(method string, args interface{}, reply interface{}) error { // Get the leader leader := s.raft.Leader() - if leader == nil { + if leader == "" { return structs.ErrNoLeader } // Lookup the server s.localLock.RLock() - server := s.localConsuls[leader.String()] + server := s.localConsuls[leader] s.localLock.RUnlock() // Handle a missing server @@ -386,7 +386,7 @@ func (s *Server) setQueryMeta(m *structs.QueryMeta) { m.KnownLeader = true } else { m.LastContact = time.Now().Sub(s.raft.LastContact()) - m.KnownLeader = (s.raft.Leader() != nil) + m.KnownLeader = (s.raft.Leader() != "") } } diff --git a/consul/serf.go b/consul/serf.go index ae1dacc33e..e18f15cc6e 100644 --- a/consul/serf.go +++ b/consul/serf.go @@ -202,7 +202,7 @@ func (s *Server) maybeBootstrap() { // Scan for all the known servers members := s.serfLAN.Members() - addrs := make([]net.Addr, 0) + addrs := make([]string, 0) for _, member := range members { valid, p := isConsulServer(member) if !valid { @@ -220,7 +220,8 @@ func (s *Server) maybeBootstrap() { s.logger.Printf("[ERR] consul: Member %v has bootstrap mode. Expect disabled.", member) return } - addrs = append(addrs, &net.TCPAddr{IP: member.Addr, Port: p.Port}) + addr := &net.TCPAddr{IP: member.Addr, Port: p.Port} + addrs = append(addrs, addr.String()) } // Skip if we haven't met the minimum expect count diff --git a/consul/server_test.go b/consul/server_test.go index 2029e42345..c86c83f355 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -332,8 +332,8 @@ func TestServer_LeaveLeader(t *testing.T) { t.Fatalf("err: %v", err) } - var p1 []net.Addr - var p2 []net.Addr + var p1 []string + var p2 []string testutil.WaitForResult(func() (bool, error) { p1, _ = s1.raftPeers.Peers() @@ -387,8 +387,8 @@ func TestServer_Leave(t *testing.T) { t.Fatalf("err: %v", err) } - var p1 []net.Addr - var p2 []net.Addr + var p1 []string + var p2 []string testutil.WaitForResult(func() (bool, error) { p1, _ = s1.raftPeers.Peers() @@ -515,8 +515,8 @@ func TestServer_Expect(t *testing.T) { t.Fatalf("err: %v", err) } - var p1 []net.Addr - var p2 []net.Addr + var p1 []string + var p2 []string // should have no peers yet testutil.WaitForResult(func() (bool, error) { @@ -538,7 +538,7 @@ func TestServer_Expect(t *testing.T) { t.Fatalf("err: %v", err) } - var p3 []net.Addr + var p3 []string // should now have all three peers testutil.WaitForResult(func() (bool, error) { @@ -589,8 +589,8 @@ func TestServer_BadExpect(t *testing.T) { t.Fatalf("err: %v", err) } - var p1 []net.Addr - var p2 []net.Addr + var p1 []string + var p2 []string // should have no peers yet testutil.WaitForResult(func() (bool, error) { @@ -612,7 +612,7 @@ func TestServer_BadExpect(t *testing.T) { t.Fatalf("err: %v", err) } - var p3 []net.Addr + var p3 []string // should still have no peers (because s2 is in expect=2 mode) testutil.WaitForResult(func() (bool, error) { diff --git a/consul/status_endpoint.go b/consul/status_endpoint.go index 2908c18d6d..ddcbed440e 100644 --- a/consul/status_endpoint.go +++ b/consul/status_endpoint.go @@ -13,8 +13,8 @@ func (s *Status) Ping(args struct{}, reply *struct{}) error { // Leader is used to get the address of the leader func (s *Status) Leader(args struct{}, reply *string) error { leader := s.server.raft.Leader() - if leader != nil { - *reply = leader.String() + if leader != "" { + *reply = leader } else { *reply = "" } @@ -28,10 +28,6 @@ func (s *Status) Peers(args struct{}, reply *[]string) error { return err } - var peerStrings []string - for _, p := range peers { - peerStrings = append(peerStrings, p.String()) - } - *reply = peerStrings + *reply = peers return nil }