diff --git a/pkg/kv/kvserver/store_rebalancer.go b/pkg/kv/kvserver/store_rebalancer.go index 89986323708c..bf828c384fbf 100644 --- a/pkg/kv/kvserver/store_rebalancer.go +++ b/pkg/kv/kvserver/store_rebalancer.go @@ -149,6 +149,7 @@ type StoreRebalancer struct { processTimeoutFn func(replica CandidateReplica) time.Duration objectiveProvider RebalanceObjectiveProvider subscribedToSpanConfigs func() bool + disabled func() bool } // NewStoreRebalancer creates a StoreRebalancer to work in tandem with the @@ -191,6 +192,10 @@ func NewStoreRebalancer( } return !rq.store.cfg.SpanConfigSubscriber.LastUpdated().IsEmpty() }, + disabled: func() bool { + return LoadBasedRebalancingMode.Get(&st.SV) == LBRebalancingOff || + rq.store.cfg.TestingKnobs.DisableStoreRebalancer + }, } sr.AddLogTag("store-rebalancer", nil) rq.store.metrics.registry.AddMetricStruct(&sr.metrics) @@ -308,15 +313,13 @@ func (sr *StoreRebalancer) Start(ctx context.Context, stopper *stop.Stopper) { timer.Read = true timer.Reset(jitteredInterval(allocator.LoadBasedRebalanceInterval.Get(&sr.st.SV))) } - + if sr.disabled() { + continue + } // Once the rebalance mode and rebalance objective are defined for // this loop, they are immutable and do not change. This avoids // inconsistency where the rebalance objective changes and very // different or contradicting actions are then taken. - mode := sr.RebalanceMode() - if mode == LBRebalancingOff { - continue - } if !sr.subscribedToSpanConfigs() { continue } @@ -326,7 +329,7 @@ func (sr *StoreRebalancer) Start(ctx context.Context, stopper *stop.Stopper) { hottestRanges := sr.replicaRankings.TopLoad(objective.ToDimension()) options := sr.scorerOptions(ctx, objective.ToDimension()) - rctx := sr.NewRebalanceContext(ctx, options, hottestRanges, mode) + rctx := sr.NewRebalanceContext(ctx, options, hottestRanges, sr.RebalanceMode()) sr.rebalanceStore(ctx, rctx) } }) diff --git a/pkg/kv/kvserver/testing_knobs.go b/pkg/kv/kvserver/testing_knobs.go index 7f1379f758f8..7e2d38e30dc5 100644 --- a/pkg/kv/kvserver/testing_knobs.go +++ b/pkg/kv/kvserver/testing_knobs.go @@ -176,6 +176,9 @@ type StoreTestingKnobs struct { DisableReplicaGCQueue bool // DisableReplicateQueue disables the replication queue. DisableReplicateQueue bool + // DisableStoreRebalancer turns off the store rebalancer which moves replicas + // and leases. + DisableStoreRebalancer bool // DisableLoadBasedSplitting turns off LBS so no splits happen because of load. DisableLoadBasedSplitting bool // LoadBasedSplittingOverrideKey returns a key which should be used for load diff --git a/pkg/testutils/testcluster/testcluster.go b/pkg/testutils/testcluster/testcluster.go index ac49505dcfc9..cb88ed0a88ba 100644 --- a/pkg/testutils/testcluster/testcluster.go +++ b/pkg/testutils/testcluster/testcluster.go @@ -581,6 +581,7 @@ func (tc *TestCluster) AddServer( stkCopy.DisableSplitQueue = true stkCopy.DisableMergeQueue = true stkCopy.DisableReplicateQueue = true + stkCopy.DisableStoreRebalancer = true serverArgs.Knobs.Store = &stkCopy }