mirror of https://github.com/status-im/consul.git
consul: updating for Raft API changes
This commit is contained in:
parent
774e8d135a
commit
b4531164e9
|
@ -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)
|
||||
|
|
|
@ -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() != "")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue