From 6ed91486435892122ba1fb9f1bc64cc339f160c3 Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Wed, 23 Nov 2022 19:19:37 -0500 Subject: [PATCH] liveness: move IsLiveMap type We'll depend on just this directly in a future commit, without wanting to depend on the much larger liveness package. Instead of introducing a standalone package for it, we'll just re-use the thin livenesspb package instead. Release note: None --- pkg/kv/kvserver/liveness/liveness.go | 16 ++---- .../kvserver/liveness/livenesspb/BUILD.bazel | 1 + .../kvserver/liveness/livenesspb/liveness.go | 11 ++++ pkg/kv/kvserver/node_liveness_test.go | 4 +- pkg/kv/kvserver/replica_circuit_breaker.go | 6 +-- .../kvserver/replica_circuit_breaker_test.go | 6 +-- pkg/kv/kvserver/replica_metrics.go | 16 +++--- pkg/kv/kvserver/replica_metrics_test.go | 54 +++++++++---------- pkg/kv/kvserver/replica_proposal_buf.go | 4 +- pkg/kv/kvserver/replica_raft.go | 10 ++-- pkg/kv/kvserver/replica_raft_quiesce.go | 11 ++-- pkg/kv/kvserver/replica_test.go | 43 ++++++++------- pkg/kv/kvserver/store.go | 3 +- pkg/kv/kvserver/store_raft.go | 3 +- pkg/server/problem_ranges.go | 6 +-- 15 files changed, 97 insertions(+), 97 deletions(-) diff --git a/pkg/kv/kvserver/liveness/liveness.go b/pkg/kv/kvserver/liveness/liveness.go index d2e92628c4db..b32728e453e1 100644 --- a/pkg/kv/kvserver/liveness/liveness.go +++ b/pkg/kv/kvserver/liveness/liveness.go @@ -1025,21 +1025,11 @@ func (nl *NodeLiveness) SelfEx() (_ Record, ok bool) { return nl.getLivenessLocked(nl.gossip.NodeID.Get()) } -// IsLiveMapEntry encapsulates data about current liveness for a -// node. -type IsLiveMapEntry struct { - livenesspb.Liveness - IsLive bool -} - -// IsLiveMap is a type alias for a map from NodeID to IsLiveMapEntry. -type IsLiveMap map[roachpb.NodeID]IsLiveMapEntry - // GetIsLiveMap returns a map of nodeID to boolean liveness status of // each node. This excludes nodes that were removed completely (dead + // decommissioning). -func (nl *NodeLiveness) GetIsLiveMap() IsLiveMap { - lMap := IsLiveMap{} +func (nl *NodeLiveness) GetIsLiveMap() livenesspb.IsLiveMap { + lMap := livenesspb.IsLiveMap{} nl.mu.RLock() defer nl.mu.RUnlock() now := nl.clock.Now().GoTime() @@ -1049,7 +1039,7 @@ func (nl *NodeLiveness) GetIsLiveMap() IsLiveMap { // This is a node that was completely removed. Skip over it. continue } - lMap[nID] = IsLiveMapEntry{ + lMap[nID] = livenesspb.IsLiveMapEntry{ Liveness: l.Liveness, IsLive: isLive, } diff --git a/pkg/kv/kvserver/liveness/livenesspb/BUILD.bazel b/pkg/kv/kvserver/liveness/livenesspb/BUILD.bazel index a056795590e9..edaaaa99f792 100644 --- a/pkg/kv/kvserver/liveness/livenesspb/BUILD.bazel +++ b/pkg/kv/kvserver/liveness/livenesspb/BUILD.bazel @@ -10,6 +10,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb", visibility = ["//visibility:public"], deps = [ + "//pkg/roachpb", "//pkg/util/timeutil", "@org_golang_google_grpc//codes", "@org_golang_google_grpc//status", diff --git a/pkg/kv/kvserver/liveness/livenesspb/liveness.go b/pkg/kv/kvserver/liveness/livenesspb/liveness.go index 9f8c61c1a0f9..d6184c1d56de 100644 --- a/pkg/kv/kvserver/liveness/livenesspb/liveness.go +++ b/pkg/kv/kvserver/liveness/livenesspb/liveness.go @@ -14,6 +14,7 @@ import ( "fmt" "time" + "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/timeutil" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -132,3 +133,13 @@ func ValidateTransition(old, new Liveness) error { return nil } + +// IsLiveMapEntry encapsulates data about current liveness for a +// node. +type IsLiveMapEntry struct { + Liveness + IsLive bool +} + +// IsLiveMap is a type alias for a map from NodeID to IsLiveMapEntry. +type IsLiveMap map[roachpb.NodeID]IsLiveMapEntry diff --git a/pkg/kv/kvserver/node_liveness_test.go b/pkg/kv/kvserver/node_liveness_test.go index 33ff87970de5..f98f3f84a850 100644 --- a/pkg/kv/kvserver/node_liveness_test.go +++ b/pkg/kv/kvserver/node_liveness_test.go @@ -669,7 +669,7 @@ func TestNodeLivenessGetIsLiveMap(t *testing.T) { l1, _ := nl.GetLiveness(1) l2, _ := nl.GetLiveness(2) l3, _ := nl.GetLiveness(3) - expectedLMap := liveness.IsLiveMap{ + expectedLMap := livenesspb.IsLiveMap{ 1: {Liveness: l1.Liveness, IsLive: true}, 2: {Liveness: l2.Liveness, IsLive: true}, 3: {Liveness: l3.Liveness, IsLive: true}, @@ -705,7 +705,7 @@ func TestNodeLivenessGetIsLiveMap(t *testing.T) { l1, _ = nl.GetLiveness(1) l2, _ = nl.GetLiveness(2) l3, _ = nl.GetLiveness(3) - expectedLMap = liveness.IsLiveMap{ + expectedLMap = livenesspb.IsLiveMap{ 1: {Liveness: l1.Liveness, IsLive: true}, 2: {Liveness: l2.Liveness, IsLive: false}, 3: {Liveness: l3.Liveness, IsLive: false}, diff --git a/pkg/kv/kvserver/replica_circuit_breaker.go b/pkg/kv/kvserver/replica_circuit_breaker.go index 8a5ccd897b81..f71169e40eb3 100644 --- a/pkg/kv/kvserver/replica_circuit_breaker.go +++ b/pkg/kv/kvserver/replica_circuit_breaker.go @@ -15,7 +15,7 @@ import ( "time" "github.com/cockroachdb/cockroach/pkg/base" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings" @@ -239,7 +239,7 @@ func replicaUnavailableError( err error, desc *roachpb.RangeDescriptor, replDesc roachpb.ReplicaDescriptor, - lm liveness.IsLiveMap, + lm livenesspb.IsLiveMap, rs *raft.Status, closedTS hlc.Timestamp, ) error { @@ -280,7 +280,7 @@ func (r *Replica) replicaUnavailableError(err error) error { desc := r.Desc() replDesc, _ := desc.GetReplicaDescriptor(r.store.StoreID()) - isLiveMap, _ := r.store.livenessMap.Load().(liveness.IsLiveMap) + isLiveMap, _ := r.store.livenessMap.Load().(livenesspb.IsLiveMap) ct := r.GetCurrentClosedTimestamp(context.Background()) return replicaUnavailableError(err, desc, replDesc, isLiveMap, r.RaftStatus(), ct) } diff --git a/pkg/kv/kvserver/replica_circuit_breaker_test.go b/pkg/kv/kvserver/replica_circuit_breaker_test.go index 5125be4c95bc..bcbe5d723f5d 100644 --- a/pkg/kv/kvserver/replica_circuit_breaker_test.go +++ b/pkg/kv/kvserver/replica_circuit_breaker_test.go @@ -15,7 +15,7 @@ import ( "testing" "time" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/echotest" @@ -36,8 +36,8 @@ func TestReplicaUnavailableError(t *testing.T) { repls.AddReplica(roachpb.ReplicaDescriptor{NodeID: 1, StoreID: 10, ReplicaID: 100}) repls.AddReplica(roachpb.ReplicaDescriptor{NodeID: 2, StoreID: 20, ReplicaID: 200}) desc := roachpb.NewRangeDescriptor(10, roachpb.RKey("a"), roachpb.RKey("z"), repls) - lm := liveness.IsLiveMap{ - 1: liveness.IsLiveMapEntry{IsLive: true}, + lm := livenesspb.IsLiveMap{ + 1: livenesspb.IsLiveMapEntry{IsLive: true}, } ts, err := time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05") require.NoError(t, err) diff --git a/pkg/kv/kvserver/replica_metrics.go b/pkg/kv/kvserver/replica_metrics.go index 563620e1f173..1cae44da5804 100644 --- a/pkg/kv/kvserver/replica_metrics.go +++ b/pkg/kv/kvserver/replica_metrics.go @@ -19,7 +19,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/allocatorimpl" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/hlc" "go.etcd.io/etcd/raft/v3" @@ -60,7 +60,7 @@ type ReplicaMetrics struct { // Metrics returns the current metrics for the replica. func (r *Replica) Metrics( - ctx context.Context, now hlc.ClockTimestamp, livenessMap liveness.IsLiveMap, clusterNodes int, + ctx context.Context, now hlc.ClockTimestamp, livenessMap livenesspb.IsLiveMap, clusterNodes int, ) ReplicaMetrics { r.store.unquiescedReplicas.Lock() _, ticking := r.store.unquiescedReplicas.m[r.RangeID] @@ -107,7 +107,7 @@ func (r *Replica) Metrics( type calcReplicaMetricsInput struct { raftCfg *base.RaftConfig conf roachpb.SpanConfig - livenessMap liveness.IsLiveMap + livenessMap livenesspb.IsLiveMap clusterNodes int desc *roachpb.RangeDescriptor raftStatus *raft.Status @@ -194,7 +194,7 @@ func calcRangeCounter( storeID roachpb.StoreID, desc *roachpb.RangeDescriptor, leaseStatus kvserverpb.LeaseStatus, - livenessMap liveness.IsLiveMap, + livenessMap livenesspb.IsLiveMap, numVoters, numReplicas int32, clusterNodes int, ) (rangeCounter, unavailable, underreplicated, overreplicated bool) { @@ -240,17 +240,17 @@ func calcRangeCounter( // replica is determined by checking its node in the provided liveness map. This // method is used when indicating under-replication so only voter replicas are // considered. -func calcLiveVoterReplicas(desc *roachpb.RangeDescriptor, livenessMap liveness.IsLiveMap) int { +func calcLiveVoterReplicas(desc *roachpb.RangeDescriptor, livenessMap livenesspb.IsLiveMap) int { return calcLiveReplicas(desc.Replicas().VoterDescriptors(), livenessMap) } // calcLiveNonVoterReplicas returns a count of the live non-voter replicas; a live // replica is determined by checking its node in the provided liveness map. -func calcLiveNonVoterReplicas(desc *roachpb.RangeDescriptor, livenessMap liveness.IsLiveMap) int { +func calcLiveNonVoterReplicas(desc *roachpb.RangeDescriptor, livenessMap livenesspb.IsLiveMap) int { return calcLiveReplicas(desc.Replicas().NonVoterDescriptors(), livenessMap) } -func calcLiveReplicas(repls []roachpb.ReplicaDescriptor, livenessMap liveness.IsLiveMap) int { +func calcLiveReplicas(repls []roachpb.ReplicaDescriptor, livenessMap livenesspb.IsLiveMap) int { var live int for _, rd := range repls { if livenessMap[rd.NodeID].IsLive { @@ -263,7 +263,7 @@ func calcLiveReplicas(repls []roachpb.ReplicaDescriptor, livenessMap liveness.Is // 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 liveness.IsLiveMap, + raftStatus *raft.Status, desc *roachpb.RangeDescriptor, livenessMap livenesspb.IsLiveMap, ) int64 { var behindCount int64 for _, rd := range desc.Replicas().Descriptors() { diff --git a/pkg/kv/kvserver/replica_metrics_test.go b/pkg/kv/kvserver/replica_metrics_test.go index 045020410bdc..8c270bc609bf 100644 --- a/pkg/kv/kvserver/replica_metrics_test.go +++ b/pkg/kv/kvserver/replica_metrics_test.go @@ -14,7 +14,7 @@ import ( "testing" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -55,8 +55,8 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { })) { - ctr, down, under, over := calcRangeCounter(1100, threeVotersAndSingleNonVoter, leaseStatus, liveness.IsLiveMap{ - 1000: liveness.IsLiveMapEntry{IsLive: true}, // by NodeID + ctr, down, under, over := calcRangeCounter(1100, threeVotersAndSingleNonVoter, leaseStatus, livenesspb.IsLiveMap{ + 1000: livenesspb.IsLiveMapEntry{IsLive: true}, // by NodeID }, 3 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) require.True(t, ctr) @@ -66,8 +66,8 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { } { - ctr, down, under, over := calcRangeCounter(1000, threeVotersAndSingleNonVoter, leaseStatus, liveness.IsLiveMap{ - 1000: liveness.IsLiveMapEntry{IsLive: false}, + ctr, down, under, over := calcRangeCounter(1000, threeVotersAndSingleNonVoter, leaseStatus, livenesspb.IsLiveMap{ + 1000: livenesspb.IsLiveMapEntry{IsLive: false}, }, 3 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) // Does not confuse a non-live entry for a live one. In other words, @@ -79,11 +79,11 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { } { - ctr, down, under, over := calcRangeCounter(11, threeVotersAndSingleNonVoter, leaseStatus, liveness.IsLiveMap{ - 10: liveness.IsLiveMapEntry{IsLive: true}, - 100: liveness.IsLiveMapEntry{IsLive: true}, - 1000: liveness.IsLiveMapEntry{IsLive: true}, - 2000: liveness.IsLiveMapEntry{IsLive: true}, + ctr, down, under, over := calcRangeCounter(11, threeVotersAndSingleNonVoter, leaseStatus, livenesspb.IsLiveMap{ + 10: livenesspb.IsLiveMapEntry{IsLive: true}, + 100: livenesspb.IsLiveMapEntry{IsLive: true}, + 1000: livenesspb.IsLiveMapEntry{IsLive: true}, + 2000: livenesspb.IsLiveMapEntry{IsLive: true}, }, 3 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) require.True(t, ctr) @@ -94,11 +94,11 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { { // Single non-voter dead - ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, liveness.IsLiveMap{ - 10: liveness.IsLiveMapEntry{IsLive: true}, - 100: liveness.IsLiveMapEntry{IsLive: true}, - 1000: liveness.IsLiveMapEntry{IsLive: false}, - 2000: liveness.IsLiveMapEntry{IsLive: true}, + ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, livenesspb.IsLiveMap{ + 10: livenesspb.IsLiveMapEntry{IsLive: true}, + 100: livenesspb.IsLiveMapEntry{IsLive: true}, + 1000: livenesspb.IsLiveMapEntry{IsLive: false}, + 2000: livenesspb.IsLiveMapEntry{IsLive: true}, }, 1 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) require.True(t, ctr) @@ -109,11 +109,11 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { { // All non-voters are dead, but range is not unavailable - ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, liveness.IsLiveMap{ - 10: liveness.IsLiveMapEntry{IsLive: true}, - 100: liveness.IsLiveMapEntry{IsLive: false}, - 1000: liveness.IsLiveMapEntry{IsLive: false}, - 2000: liveness.IsLiveMapEntry{IsLive: false}, + ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, livenesspb.IsLiveMap{ + 10: livenesspb.IsLiveMapEntry{IsLive: true}, + 100: livenesspb.IsLiveMapEntry{IsLive: false}, + 1000: livenesspb.IsLiveMapEntry{IsLive: false}, + 2000: livenesspb.IsLiveMapEntry{IsLive: false}, }, 1 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) require.True(t, ctr) @@ -124,11 +124,11 @@ func TestCalcRangeCounterIsLiveMap(t *testing.T) { { // More non-voters than needed - ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, liveness.IsLiveMap{ - 10: liveness.IsLiveMapEntry{IsLive: true}, - 100: liveness.IsLiveMapEntry{IsLive: true}, - 1000: liveness.IsLiveMapEntry{IsLive: true}, - 2000: liveness.IsLiveMapEntry{IsLive: true}, + ctr, down, under, over := calcRangeCounter(11, oneVoterAndThreeNonVoters, leaseStatus, livenesspb.IsLiveMap{ + 10: livenesspb.IsLiveMapEntry{IsLive: true}, + 100: livenesspb.IsLiveMapEntry{IsLive: true}, + 1000: livenesspb.IsLiveMapEntry{IsLive: true}, + 2000: livenesspb.IsLiveMapEntry{IsLive: true}, }, 1 /* numVoters */, 3 /* numReplicas */, 4 /* clusterNodes */) require.True(t, ctr) @@ -238,9 +238,9 @@ func TestCalcRangeCounterLeaseHolder(t *testing.T) { for _, tc := range testcases { t.Run(tc.desc, func(t *testing.T) { - livenessMap := liveness.IsLiveMap{} + livenessMap := livenesspb.IsLiveMap{} for _, nodeID := range tc.liveNodes { - livenessMap[nodeID] = liveness.IsLiveMapEntry{IsLive: true} + livenessMap[nodeID] = livenesspb.IsLiveMapEntry{IsLive: true} } ctr, _, _, _ := calcRangeCounter(tc.storeID, rangeDesc, tc.leaseStatus, livenessMap, 3 /* numVoters */, 4 /* numReplicas */, 4 /* clusterNodes */) diff --git a/pkg/kv/kvserver/replica_proposal_buf.go b/pkg/kv/kvserver/replica_proposal_buf.go index fbdb52cd319c..28fe399a6036 100644 --- a/pkg/kv/kvserver/replica_proposal_buf.go +++ b/pkg/kv/kvserver/replica_proposal_buf.go @@ -17,7 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/tracker" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/raftutil" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/settings/cluster" @@ -1239,7 +1239,7 @@ func (rp *replicaProposer) ownsValidLease(ctx context.Context, now hlc.ClockTime func (rp *replicaProposer) shouldCampaignOnRedirect(raftGroup proposerRaft) bool { r := (*Replica)(rp) - livenessMap, _ := r.store.livenessMap.Load().(liveness.IsLiveMap) + livenessMap, _ := r.store.livenessMap.Load().(livenesspb.IsLiveMap) return shouldCampaignOnLeaseRequestRedirect( raftGroup.BasicStatus(), livenessMap, diff --git a/pkg/kv/kvserver/replica_raft.go b/pkg/kv/kvserver/replica_raft.go index 7d077dc231ed..1aefdcb21728 100644 --- a/pkg/kv/kvserver/replica_raft.go +++ b/pkg/kv/kvserver/replica_raft.go @@ -24,7 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvadmission" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/logstore" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/stateloader" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/uncertainty" @@ -1093,7 +1093,7 @@ func maybeFatalOnRaftReadyErr(ctx context.Context, err error) (removed bool) { // tick the Raft group, returning true if the raft group exists and should // be queued for Ready processing; false otherwise. func (r *Replica) tick( - ctx context.Context, livenessMap liveness.IsLiveMap, ioThresholdMap *ioThresholdMap, + ctx context.Context, livenessMap livenesspb.IsLiveMap, ioThresholdMap *ioThresholdMap, ) (bool, error) { r.unreachablesMu.Lock() remotes := r.unreachablesMu.remotes @@ -1804,7 +1804,7 @@ func shouldCampaignOnWake( leaseStatus kvserverpb.LeaseStatus, storeID roachpb.StoreID, raftStatus raft.BasicStatus, - livenessMap liveness.IsLiveMap, + livenessMap livenesspb.IsLiveMap, desc *roachpb.RangeDescriptor, requiresExpiringLease bool, ) bool { @@ -1863,7 +1863,7 @@ func (r *Replica) maybeCampaignOnWakeLocked(ctx context.Context) { leaseStatus := r.leaseStatusAtRLocked(ctx, r.store.Clock().NowAsClockTimestamp()) raftStatus := r.mu.internalRaftGroup.BasicStatus() - livenessMap, _ := r.store.livenessMap.Load().(liveness.IsLiveMap) + livenessMap, _ := r.store.livenessMap.Load().(livenesspb.IsLiveMap) if shouldCampaignOnWake(leaseStatus, r.store.StoreID(), raftStatus, livenessMap, r.descRLocked(), r.requiresExpiringLeaseRLocked()) { r.campaignLocked(ctx) } @@ -1887,7 +1887,7 @@ func (r *Replica) maybeCampaignOnWakeLocked(ctx context.Context) { // become leader and can proceed with a future attempt to acquire the lease. func shouldCampaignOnLeaseRequestRedirect( raftStatus raft.BasicStatus, - livenessMap liveness.IsLiveMap, + livenessMap livenesspb.IsLiveMap, desc *roachpb.RangeDescriptor, requiresExpiringLease bool, now hlc.Timestamp, diff --git a/pkg/kv/kvserver/replica_raft_quiesce.go b/pkg/kv/kvserver/replica_raft_quiesce.go index 40157633ed45..06414ebc9b53 100644 --- a/pkg/kv/kvserver/replica_raft_quiesce.go +++ b/pkg/kv/kvserver/replica_raft_quiesce.go @@ -15,7 +15,6 @@ import ( "sort" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/hlc" @@ -180,7 +179,7 @@ func (r *Replica) canUnquiesceRLocked() bool { // elections which will cause throughput hiccups to the range, but not // correctness issues. func (r *Replica) maybeQuiesceRaftMuLockedReplicaMuLocked( - ctx context.Context, now hlc.ClockTimestamp, livenessMap liveness.IsLiveMap, + ctx context.Context, now hlc.ClockTimestamp, livenessMap livenesspb.IsLiveMap, ) bool { status, lagging, ok := shouldReplicaQuiesce(ctx, r, now, livenessMap, r.mu.pausedFollowers) if !ok { @@ -224,7 +223,7 @@ func (s laggingReplicaSet) MemberStale(l livenesspb.Liveness) bool { // AnyMemberStale returns whether any liveness information in the set is older // than liveness information contained in the IsLiveMap. -func (s laggingReplicaSet) AnyMemberStale(livenessMap liveness.IsLiveMap) bool { +func (s laggingReplicaSet) AnyMemberStale(livenessMap livenesspb.IsLiveMap) bool { for _, laggingL := range s { if l, ok := livenessMap[laggingL.NodeID]; ok { if laggingL.Compare(l.Liveness) < 0 { @@ -270,7 +269,7 @@ func shouldReplicaQuiesce( ctx context.Context, q quiescer, now hlc.ClockTimestamp, - livenessMap liveness.IsLiveMap, + livenessMap livenesspb.IsLiveMap, pausedFollowers map[roachpb.ReplicaID]struct{}, ) (*raft.Status, laggingReplicaSet, bool) { if testingDisableQuiescence { @@ -476,7 +475,7 @@ func shouldFollowerQuiesceOnNotify( q quiescer, msg raftpb.Message, lagging laggingReplicaSet, - livenessMap liveness.IsLiveMap, + livenessMap livenesspb.IsLiveMap, ) bool { // If another replica tells us to quiesce, we verify that according to // it, we are fully caught up, and that we believe it to be the leader. @@ -559,7 +558,7 @@ func (r *Replica) maybeQuiesceOnNotify( // NOTE: it is important that we grab the livenessMap under lock so // that we properly synchronize with Store.nodeIsLiveCallback, which // updates the map and then tries to unquiesce. - livenessMap, _ := r.store.livenessMap.Load().(liveness.IsLiveMap) + livenessMap, _ := r.store.livenessMap.Load().(livenesspb.IsLiveMap) if !shouldFollowerQuiesceOnNotify(ctx, r, msg, lagging, livenessMap) { return false } diff --git a/pkg/kv/kvserver/replica_test.go b/pkg/kv/kvserver/replica_test.go index 17e6df7121e5..f8097d3e3455 100644 --- a/pkg/kv/kvserver/replica_test.go +++ b/pkg/kv/kvserver/replica_test.go @@ -40,7 +40,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/intentresolver" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/rditer" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset" @@ -9035,10 +9034,10 @@ func TestReplicaMetrics(t *testing.T) { } return d } - live := func(ids ...roachpb.NodeID) liveness.IsLiveMap { - m := liveness.IsLiveMap{} + live := func(ids ...roachpb.NodeID) livenesspb.IsLiveMap { + m := livenesspb.IsLiveMap{} for _, id := range ids { - m[id] = liveness.IsLiveMapEntry{IsLive: true} + m[id] = livenesspb.IsLiveMapEntry{IsLive: true} } return m } @@ -9055,7 +9054,7 @@ func TestReplicaMetrics(t *testing.T) { storeID roachpb.StoreID desc roachpb.RangeDescriptor raftStatus *raft.Status - liveness liveness.IsLiveMap + liveness livenesspb.IsLiveMap raftLogSize int64 expected ReplicaMetrics }{ @@ -9986,7 +9985,7 @@ type testQuiescer struct { isDestroyed bool // Not used to implement quiescer, but used by tests. - livenessMap liveness.IsLiveMap + livenessMap livenesspb.IsLiveMap paused map[roachpb.ReplicaID]struct{} } @@ -10073,7 +10072,7 @@ func TestShouldReplicaQuiesce(t *testing.T) { lastIndex: logIndex, raftReady: false, ownsValidLease: true, - livenessMap: liveness.IsLiveMap{ + livenessMap: livenesspb.IsLiveMap{ 1: {IsLive: true}, 2: {IsLive: true}, 3: {IsLive: true}, @@ -10179,7 +10178,7 @@ func TestShouldReplicaQuiesce(t *testing.T) { for _, i := range []uint64{1, 2, 3} { test(true, func(q *testQuiescer) *testQuiescer { nodeID := roachpb.NodeID(i) - q.livenessMap[nodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[nodeID] = livenesspb.IsLiveMapEntry{ Liveness: livenesspb.Liveness{NodeID: nodeID}, IsLive: false, } @@ -10236,7 +10235,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { }, }, }, - livenessMap: liveness.IsLiveMap{ + livenessMap: livenesspb.IsLiveMap{ 1: {IsLive: true}, 2: {IsLive: true}, 3: {IsLive: true}, @@ -10287,7 +10286,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { Epoch: 7, Expiration: hlc.LegacyTimestamp{WallTime: 8}, } - q.livenessMap[l.NodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[l.NodeID] = livenesspb.IsLiveMapEntry{ Liveness: l, IsLive: false, } @@ -10301,7 +10300,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { Epoch: 7, Expiration: hlc.LegacyTimestamp{WallTime: 8}, } - q.livenessMap[l.NodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[l.NodeID] = livenesspb.IsLiveMapEntry{ Liveness: l, IsLive: false, } @@ -10316,7 +10315,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { Epoch: 7, Expiration: hlc.LegacyTimestamp{WallTime: 8}, } - q.livenessMap[l.NodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[l.NodeID] = livenesspb.IsLiveMapEntry{ Liveness: l, IsLive: false, } @@ -10332,7 +10331,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { Epoch: 7, Expiration: hlc.LegacyTimestamp{WallTime: 8}, } - q.livenessMap[l.NodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[l.NodeID] = livenesspb.IsLiveMapEntry{ Liveness: l, IsLive: false, } @@ -10347,7 +10346,7 @@ func TestFollowerQuiesceOnNotify(t *testing.T) { Epoch: 7, Expiration: hlc.LegacyTimestamp{WallTime: 8}, } - q.livenessMap[l.NodeID] = liveness.IsLiveMapEntry{ + q.livenessMap[l.NodeID] = livenesspb.IsLiveMapEntry{ Liveness: l, IsLive: false, } @@ -11446,10 +11445,10 @@ func TestReplicaShouldCampaignOnWake(t *testing.T) { }, NextReplicaID: 4, } - livenessMap := liveness.IsLiveMap{ - 1: liveness.IsLiveMapEntry{IsLive: true}, - 2: liveness.IsLiveMapEntry{IsLive: false}, - 4: liveness.IsLiveMapEntry{IsLive: false}, + livenessMap := livenesspb.IsLiveMap{ + 1: livenesspb.IsLiveMapEntry{IsLive: true}, + 2: livenesspb.IsLiveMapEntry{IsLive: false}, + 4: livenesspb.IsLiveMapEntry{IsLive: false}, } myLease := roachpb.Lease{ @@ -11515,7 +11514,7 @@ func TestReplicaShouldCampaignOnWake(t *testing.T) { tests := []struct { leaseStatus kvserverpb.LeaseStatus raftStatus raft.BasicStatus - livenessMap liveness.IsLiveMap + livenessMap livenesspb.IsLiveMap desc *roachpb.RangeDescriptor requiresExpiringLease bool exp bool @@ -11584,12 +11583,12 @@ func TestReplicaShouldCampaignOnLeaseRequestRedirect(t *testing.T) { } now := hlc.Timestamp{WallTime: 100} - livenessMap := liveness.IsLiveMap{ - 1: liveness.IsLiveMapEntry{ + livenessMap := livenesspb.IsLiveMap{ + 1: livenesspb.IsLiveMapEntry{ IsLive: true, Liveness: livenesspb.Liveness{Expiration: now.Add(1, 0).ToLegacyTimestamp()}, }, - 2: liveness.IsLiveMapEntry{ + 2: livenesspb.IsLiveMapEntry{ // NOTE: we purposefully set IsLive to true in disagreement with the // Liveness expiration to ensure that we're only looking at node liveness // in shouldCampaignOnLeaseRequestRedirect and not at whether this node is diff --git a/pkg/kv/kvserver/store.go b/pkg/kv/kvserver/store.go index 1afc9e40ee6b..4899a27128ed 100644 --- a/pkg/kv/kvserver/store.go +++ b/pkg/kv/kvserver/store.go @@ -44,6 +44,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/multiqueue" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/raftentry" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed" @@ -3228,7 +3229,7 @@ func (s *Store) updateReplicationGauges(ctx context.Context) error { ) now := s.cfg.Clock.NowAsClockTimestamp() - var livenessMap liveness.IsLiveMap + var livenessMap livenesspb.IsLiveMap if s.cfg.NodeLiveness != nil { livenessMap = s.cfg.NodeLiveness.GetIsLiveMap() } diff --git a/pkg/kv/kvserver/store_raft.go b/pkg/kv/kvserver/store_raft.go index 3eccf9c7a897..51acf460fc74 100644 --- a/pkg/kv/kvserver/store_raft.go +++ b/pkg/kv/kvserver/store_raft.go @@ -17,7 +17,6 @@ import ( "unsafe" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" @@ -651,7 +650,7 @@ func (s *Store) processTick(_ context.Context, rangeID roachpb.RangeID) bool { if !ok { return false } - livenessMap, _ := s.livenessMap.Load().(liveness.IsLiveMap) + livenessMap, _ := s.livenessMap.Load().(livenesspb.IsLiveMap) ioThresholds := s.ioThresholds.Current() start := timeutil.Now() diff --git a/pkg/server/problem_ranges.go b/pkg/server/problem_ranges.go index 12fb4649ed6f..c95e04a30ddc 100644 --- a/pkg/server/problem_ranges.go +++ b/pkg/server/problem_ranges.go @@ -14,7 +14,7 @@ import ( "context" "sort" - "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "google.golang.org/grpc/codes" @@ -43,8 +43,8 @@ func (s *statusServer) ProblemRanges( if err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) } - isLiveMap = liveness.IsLiveMap{ - requestedNodeID: liveness.IsLiveMapEntry{IsLive: true}, + isLiveMap = livenesspb.IsLiveMap{ + requestedNodeID: livenesspb.IsLiveMapEntry{IsLive: true}, } }