diff --git a/.changelog/18352.txt b/.changelog/18352.txt new file mode 100644 index 00000000000..4a98d40587f --- /dev/null +++ b/.changelog/18352.txt @@ -0,0 +1,3 @@ +```release-note:improvement +raft: remove use of deprecated Leader func +``` diff --git a/helper/snapshot/snapshot_test.go b/helper/snapshot/snapshot_test.go index 98dc6c14a66..d8b8fcbbc24 100644 --- a/helper/snapshot/snapshot_test.go +++ b/helper/snapshot/snapshot_test.go @@ -107,7 +107,7 @@ func makeRaft(t *testing.T, dir string) (*raft.Raft, *MockFSM) { timeout := time.After(10 * time.Second) for { - if raft.Leader() != "" { + if leaderAddr, _ := raft.LeaderWithID(); leaderAddr != "" { break } diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index a089186bbd8..9f32e735fac 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -285,7 +285,8 @@ func equalDevices(n1, n2 *structs.Node) bool { // constructNodeServerInfoResponse assumes the n.srv.peerLock is held for reading. 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.Servers = make([]*structs.NodeServerInfo, 0, len(n.srv.localPeers)) diff --git a/nomad/operator_endpoint.go b/nomad/operator_endpoint.go index 0aa66b2981b..648acc19e0c 100644 --- a/nomad/operator_endpoint.go +++ b/nomad/operator_endpoint.go @@ -72,7 +72,7 @@ func (op *Operator) RaftGetConfiguration(args *structs.GenericRequest, reply *st } // Fill out the reply. - leader := op.srv.raft.Leader() + leader, _ := op.srv.raft.LeaderWithID() reply.Index = future.Index() for _, server := range future.Configuration().Servers { node := "(unknown)" diff --git a/nomad/rpc.go b/nomad/rpc.go index 500c4d72ba5..26088fd8492 100644 --- a/nomad/rpc.go +++ b/nomad/rpc.go @@ -622,7 +622,7 @@ func (s *Server) getLeader() (bool, *serverParts) { } // Get the leader - leader := s.raft.Leader() + leader, _ := s.raft.LeaderWithID() if leader == "" { return false, nil } @@ -790,7 +790,8 @@ func (r *rpcHandler) setQueryMeta(m *structs.QueryMeta) { m.KnownLeader = true } else { m.LastContact = time.Since(r.raft.LastContact()) - m.KnownLeader = (r.raft.Leader() != "") + leaderAddr, _ := r.raft.LeaderWithID() + m.KnownLeader = (leaderAddr != "") } } diff --git a/nomad/server.go b/nomad/server.go index 862f852f276..8ef835108b1 100644 --- a/nomad/server.go +++ b/nomad/server.go @@ -912,7 +912,7 @@ func (s *Server) setupBootstrapHandler() error { // correct number of servers required for quorum are present). bootstrapFn := func() error { // If there is a raft leader, do nothing - if s.raft.Leader() != "" { + if leader, _ := s.raft.LeaderWithID(); leader != "" { peersTimeout.Reset(maxStaleLeadership) return nil } @@ -1935,11 +1935,12 @@ func (s *Server) Stats() map[string]map[string]string { toString := func(v uint64) string { return strconv.FormatUint(v, 10) } + leader, _ := s.raft.LeaderWithID() stats := map[string]map[string]string{ "nomad": { "server": "true", "leader": fmt.Sprintf("%v", s.IsLeader()), - "leader_addr": string(s.raft.Leader()), + "leader_addr": string(leader), "bootstrap": fmt.Sprintf("%v", s.isSingleServerCluster()), "known_regions": toString(uint64(len(s.peers))), }, diff --git a/nomad/status_endpoint.go b/nomad/status_endpoint.go index f5b53a5c99c..a2d402d1289 100644 --- a/nomad/status_endpoint.go +++ b/nomad/status_endpoint.go @@ -44,9 +44,9 @@ func (s *Status) Leader(args *structs.GenericRequest, reply *string) error { return err } - leader := string(s.srv.raft.Leader()) + leader, _ := s.srv.raft.LeaderWithID() if leader != "" { - *reply = leader + *reply = string(leader) } else { *reply = "" }