Skip to content

Commit

Permalink
testutils,kvserver: disable store rebalancer when replication manual
Browse files Browse the repository at this point in the history
`ReplicationManual` can be specified in tests which use a test cluster
to prevent lease/replica movements.

This proves vital if the test is asserting exactly on the placement of a
range, or its leaseholder.

Also disable the store rebalancer, which could move both leases and
replicas under `ReplicationManual` before.

Informs: #132310
Informs: #132272
Release note: None
  • Loading branch information
kvoli committed Oct 14, 2024
1 parent a0f39e7 commit 55a4719
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/kv/kvserver/store_rebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
})
Expand Down
3 changes: 3 additions & 0 deletions pkg/kv/kvserver/testing_knobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/testutils/testcluster/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ func (tc *TestCluster) AddServer(
stkCopy.DisableSplitQueue = true
stkCopy.DisableMergeQueue = true
stkCopy.DisableReplicateQueue = true
stkCopy.DisableStoreRebalancer = true
serverArgs.Knobs.Store = &stkCopy
}

Expand Down

0 comments on commit 55a4719

Please sign in to comment.