backport of commit 776a26bce7cf3a320fc7e7f4a6bf9da2b30f3da7 (#18375)
Co-authored-by: James Rasell <jrasell@users.noreply.github.com>
This commit is contained in:
parent
ef780825d4
commit
1b2237d6a8
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
raft: remove use of deprecated Leader func
|
||||||
|
```
|
|
@ -110,7 +110,7 @@ func makeRaft(t *testing.T, dir string) (*raft.Raft, *MockFSM) {
|
||||||
|
|
||||||
timeout := time.After(10 * time.Second)
|
timeout := time.After(10 * time.Second)
|
||||||
for {
|
for {
|
||||||
if raft.Leader() != "" {
|
if leaderAddr, _ := raft.LeaderWithID(); leaderAddr != "" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,8 @@ func equalDevices(n1, n2 *structs.Node) bool {
|
||||||
|
|
||||||
// constructNodeServerInfoResponse assumes the n.srv.peerLock is held for reading.
|
// constructNodeServerInfoResponse assumes the n.srv.peerLock is held for reading.
|
||||||
func (n *Node) constructNodeServerInfoResponse(nodeID string, snap *state.StateSnapshot, reply *structs.NodeUpdateResponse) error {
|
func (n *Node) constructNodeServerInfoResponse(nodeID string, snap *state.StateSnapshot, reply *structs.NodeUpdateResponse) error {
|
||||||
reply.LeaderRPCAddr = string(n.srv.raft.Leader())
|
leaderAddr, _ := n.srv.raft.LeaderWithID()
|
||||||
|
reply.LeaderRPCAddr = string(leaderAddr)
|
||||||
|
|
||||||
// Reply with config information required for future RPC requests
|
// Reply with config information required for future RPC requests
|
||||||
reply.Servers = make([]*structs.NodeServerInfo, 0, len(n.srv.localPeers))
|
reply.Servers = make([]*structs.NodeServerInfo, 0, len(n.srv.localPeers))
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (op *Operator) RaftGetConfiguration(args *structs.GenericRequest, reply *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill out the reply.
|
// Fill out the reply.
|
||||||
leader := op.srv.raft.Leader()
|
leader, _ := op.srv.raft.LeaderWithID()
|
||||||
reply.Index = future.Index()
|
reply.Index = future.Index()
|
||||||
for _, server := range future.Configuration().Servers {
|
for _, server := range future.Configuration().Servers {
|
||||||
node := "(unknown)"
|
node := "(unknown)"
|
||||||
|
|
|
@ -625,7 +625,7 @@ func (s *Server) getLeader() (bool, *serverParts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the leader
|
// Get the leader
|
||||||
leader := s.raft.Leader()
|
leader, _ := s.raft.LeaderWithID()
|
||||||
if leader == "" {
|
if leader == "" {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -793,7 +793,8 @@ func (r *rpcHandler) setQueryMeta(m *structs.QueryMeta) {
|
||||||
m.KnownLeader = true
|
m.KnownLeader = true
|
||||||
} else {
|
} else {
|
||||||
m.LastContact = time.Since(r.raft.LastContact())
|
m.LastContact = time.Since(r.raft.LastContact())
|
||||||
m.KnownLeader = (r.raft.Leader() != "")
|
leaderAddr, _ := r.raft.LeaderWithID()
|
||||||
|
m.KnownLeader = (leaderAddr != "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -923,7 +923,7 @@ func (s *Server) setupBootstrapHandler() error {
|
||||||
// correct number of servers required for quorum are present).
|
// correct number of servers required for quorum are present).
|
||||||
bootstrapFn := func() error {
|
bootstrapFn := func() error {
|
||||||
// If there is a raft leader, do nothing
|
// If there is a raft leader, do nothing
|
||||||
if s.raft.Leader() != "" {
|
if leader, _ := s.raft.LeaderWithID(); leader != "" {
|
||||||
peersTimeout.Reset(maxStaleLeadership)
|
peersTimeout.Reset(maxStaleLeadership)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1948,11 +1948,12 @@ func (s *Server) Stats() map[string]map[string]string {
|
||||||
toString := func(v uint64) string {
|
toString := func(v uint64) string {
|
||||||
return strconv.FormatUint(v, 10)
|
return strconv.FormatUint(v, 10)
|
||||||
}
|
}
|
||||||
|
leader, _ := s.raft.LeaderWithID()
|
||||||
stats := map[string]map[string]string{
|
stats := map[string]map[string]string{
|
||||||
"nomad": {
|
"nomad": {
|
||||||
"server": "true",
|
"server": "true",
|
||||||
"leader": fmt.Sprintf("%v", s.IsLeader()),
|
"leader": fmt.Sprintf("%v", s.IsLeader()),
|
||||||
"leader_addr": string(s.raft.Leader()),
|
"leader_addr": string(leader),
|
||||||
"bootstrap": fmt.Sprintf("%v", s.isSingleServerCluster()),
|
"bootstrap": fmt.Sprintf("%v", s.isSingleServerCluster()),
|
||||||
"known_regions": toString(uint64(len(s.peers))),
|
"known_regions": toString(uint64(len(s.peers))),
|
||||||
},
|
},
|
||||||
|
|
|
@ -47,9 +47,9 @@ func (s *Status) Leader(args *structs.GenericRequest, reply *string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
leader := string(s.srv.raft.Leader())
|
leader, _ := s.srv.raft.LeaderWithID()
|
||||||
if leader != "" {
|
if leader != "" {
|
||||||
*reply = leader
|
*reply = string(leader)
|
||||||
} else {
|
} else {
|
||||||
*reply = ""
|
*reply = ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue