diff --git a/pkg/kv/kvserver/replica_metrics.go b/pkg/kv/kvserver/replica_metrics.go index 1de0acc97de7..b846b55e7a7f 100644 --- a/pkg/kv/kvserver/replica_metrics.go +++ b/pkg/kv/kvserver/replica_metrics.go @@ -84,7 +84,7 @@ func (r *Replica) Metrics( livenessMap: livenessMap, clusterNodes: clusterNodes, desc: r.mu.state.Desc, - raftStatus: r.raftStatusRLocked(), + raftStatus: r.raftSparseStatusRLocked(), leaseStatus: r.leaseStatusAtRLocked(ctx, now), storeID: r.store.StoreID(), quiescent: r.mu.quiescent, @@ -110,7 +110,7 @@ type calcReplicaMetricsInput struct { livenessMap livenesspb.IsLiveMap clusterNodes int desc *roachpb.RangeDescriptor - raftStatus *raft.Status + raftStatus *raftSparseStatus leaseStatus kvserverpb.LeaseStatus storeID roachpb.StoreID quiescent bool @@ -138,7 +138,7 @@ func calcReplicaMetrics(d calcReplicaMetricsInput) ReplicaMetrics { // The raft leader computes the number of raft entries that replicas are // behind. - leader := isRaftLeader(d.raftStatus) + leader := d.raftStatus != nil && d.raftStatus.RaftState == raft.StateLeader var leaderBehindCount, leaderPausedFollowerCount int64 if leader { leaderBehindCount = calcBehindCount(d.raftStatus, d.desc, d.livenessMap) @@ -263,7 +263,7 @@ func calcLiveReplicas(repls []roachpb.ReplicaDescriptor, livenessMap livenesspb. // calcBehindCount returns a total count of log entries that follower replicas // are behind. This can only be computed on the raft leader. func calcBehindCount( - raftStatus *raft.Status, desc *roachpb.RangeDescriptor, livenessMap livenesspb.IsLiveMap, + raftStatus *raftSparseStatus, desc *roachpb.RangeDescriptor, livenessMap livenesspb.IsLiveMap, ) int64 { var behindCount int64 for _, rd := range desc.Replicas().Descriptors() { diff --git a/pkg/kv/kvserver/replica_raft.go b/pkg/kv/kvserver/replica_raft.go index a4061107aabf..e6f8b4369a93 100644 --- a/pkg/kv/kvserver/replica_raft.go +++ b/pkg/kv/kvserver/replica_raft.go @@ -1707,10 +1707,6 @@ func (r *Replica) hasOutstandingSnapshotInFlightToStore(storeID roachpb.StoreID) return r.getSnapshotLogTruncationConstraints(storeID) > 0 } -func isRaftLeader(raftStatus *raft.Status) bool { - return raftStatus != nil && raftStatus.SoftState.RaftState == raft.StateLeader -} - // HasRaftLeader returns true if the raft group has a raft leader currently. func HasRaftLeader(raftStatus *raft.Status) bool { return raftStatus != nil && raftStatus.SoftState.Lead != 0 diff --git a/pkg/kv/kvserver/replica_test.go b/pkg/kv/kvserver/replica_test.go index 93a40767456e..831a4c473847 100644 --- a/pkg/kv/kvserver/replica_test.go +++ b/pkg/kv/kvserver/replica_test.go @@ -9010,8 +9010,8 @@ func TestReplicaMetrics(t *testing.T) { } return m } - status := func(lead uint64, progress map[uint64]tracker.Progress) *raft.Status { - status := &raft.Status{ + status := func(lead uint64, progress map[uint64]tracker.Progress) *raftSparseStatus { + status := &raftSparseStatus{ Progress: progress, } // The commit index is set so that a progress.Match value of 1 is behind @@ -9055,7 +9055,7 @@ func TestReplicaMetrics(t *testing.T) { replicas int32 storeID roachpb.StoreID desc roachpb.RangeDescriptor - raftStatus *raft.Status + raftStatus *raftSparseStatus liveness livenesspb.IsLiveMap raftLogSize int64 expected ReplicaMetrics