consul: updating for Raft API changes

This commit is contained in:
Armon Dadgar 2015-05-08 11:35:12 -07:00
parent e2230fb62e
commit 2ca41b15df
5 changed files with 21 additions and 24 deletions

View File

@ -521,7 +521,7 @@ func (s *Server) joinConsulServer(m serf.Member, parts *serverParts) error {
// Attempt to add as a peer // Attempt to add as a peer
var addr net.Addr = &net.TCPAddr{IP: m.Addr, Port: parts.Port} 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 { if err := future.Error(); err != nil && err != raft.ErrKnownPeer {
s.logger.Printf("[ERR] consul: failed to add raft peer: %v", err) s.logger.Printf("[ERR] consul: failed to add raft peer: %v", err)
return 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 { func (s *Server) removeConsulServer(m serf.Member, port int) error {
// Attempt to remove as peer // Attempt to remove as peer
peer := &net.TCPAddr{IP: m.Addr, Port: port} 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 { if err := future.Error(); err != nil && err != raft.ErrUnknownPeer {
s.logger.Printf("[ERR] consul: failed to remove raft peer '%v': %v", s.logger.Printf("[ERR] consul: failed to remove raft peer '%v': %v",
peer, err) peer, err)

View File

@ -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 { func (s *Server) forwardLeader(method string, args interface{}, reply interface{}) error {
// Get the leader // Get the leader
leader := s.raft.Leader() leader := s.raft.Leader()
if leader == nil { if leader == "" {
return structs.ErrNoLeader return structs.ErrNoLeader
} }
// Lookup the server // Lookup the server
s.localLock.RLock() s.localLock.RLock()
server := s.localConsuls[leader.String()] server := s.localConsuls[leader]
s.localLock.RUnlock() s.localLock.RUnlock()
// Handle a missing server // Handle a missing server
@ -386,7 +386,7 @@ func (s *Server) setQueryMeta(m *structs.QueryMeta) {
m.KnownLeader = true m.KnownLeader = true
} else { } else {
m.LastContact = time.Now().Sub(s.raft.LastContact()) m.LastContact = time.Now().Sub(s.raft.LastContact())
m.KnownLeader = (s.raft.Leader() != nil) m.KnownLeader = (s.raft.Leader() != "")
} }
} }

View File

@ -202,7 +202,7 @@ func (s *Server) maybeBootstrap() {
// Scan for all the known servers // Scan for all the known servers
members := s.serfLAN.Members() members := s.serfLAN.Members()
addrs := make([]net.Addr, 0) addrs := make([]string, 0)
for _, member := range members { for _, member := range members {
valid, p := isConsulServer(member) valid, p := isConsulServer(member)
if !valid { if !valid {
@ -220,7 +220,8 @@ func (s *Server) maybeBootstrap() {
s.logger.Printf("[ERR] consul: Member %v has bootstrap mode. Expect disabled.", member) s.logger.Printf("[ERR] consul: Member %v has bootstrap mode. Expect disabled.", member)
return 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 // Skip if we haven't met the minimum expect count

View File

@ -332,8 +332,8 @@ func TestServer_LeaveLeader(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p1 []net.Addr var p1 []string
var p2 []net.Addr var p2 []string
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p1, _ = s1.raftPeers.Peers() p1, _ = s1.raftPeers.Peers()
@ -387,8 +387,8 @@ func TestServer_Leave(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p1 []net.Addr var p1 []string
var p2 []net.Addr var p2 []string
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p1, _ = s1.raftPeers.Peers() p1, _ = s1.raftPeers.Peers()
@ -515,8 +515,8 @@ func TestServer_Expect(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p1 []net.Addr var p1 []string
var p2 []net.Addr var p2 []string
// should have no peers yet // should have no peers yet
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
@ -538,7 +538,7 @@ func TestServer_Expect(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p3 []net.Addr var p3 []string
// should now have all three peers // should now have all three peers
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
@ -589,8 +589,8 @@ func TestServer_BadExpect(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p1 []net.Addr var p1 []string
var p2 []net.Addr var p2 []string
// should have no peers yet // should have no peers yet
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
@ -612,7 +612,7 @@ func TestServer_BadExpect(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
var p3 []net.Addr var p3 []string
// should still have no peers (because s2 is in expect=2 mode) // should still have no peers (because s2 is in expect=2 mode)
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {

View File

@ -13,8 +13,8 @@ func (s *Status) Ping(args struct{}, reply *struct{}) error {
// Leader is used to get the address of the leader // Leader is used to get the address of the leader
func (s *Status) Leader(args struct{}, reply *string) error { func (s *Status) Leader(args struct{}, reply *string) error {
leader := s.server.raft.Leader() leader := s.server.raft.Leader()
if leader != nil { if leader != "" {
*reply = leader.String() *reply = leader
} else { } else {
*reply = "" *reply = ""
} }
@ -28,10 +28,6 @@ func (s *Status) Peers(args struct{}, reply *[]string) error {
return err return err
} }
var peerStrings []string *reply = peers
for _, p := range peers {
peerStrings = append(peerStrings, p.String())
}
*reply = peerStrings
return nil return nil
} }