Skip to content

Commit fb90c8d

Browse files
committed
asim: use cluster setting LBRebalancingMode directly
Previously, LBRebalancingMode existed both as a simulation setting and a cluster setting, which was confusing especially now that we're plumbing the cluster setting through. This commit removes the simulation specific setting and makes the simulator use the cluster setting directly instead. Note that default behavior is leases mode and replicas=2 remains unchanged for both. Epic: none Release note: none
1 parent ec83247 commit fb90c8d

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
lines changed

pkg/kv/kvserver/asim/config/settings.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const (
2727
defaultSplitQPSThreshold = 2500
2828
defaultSplitStatRetention = 10 * time.Minute
2929
defaultSeed = 42
30-
defaultLBRebalancingMode = 2 // Leases and replicas.
3130
defaultLBRebalancingInterval = time.Minute
3231
defaultLBRebalanceQPSThreshold = 0.1
3332
defaultLBRebalancingObjective = 0 // QPS
@@ -96,9 +95,6 @@ type SimulationSettings struct {
9695
// SplitStatRetention is the duration which recorded load will be retained
9796
// and factored into load based splitting decisions.
9897
SplitStatRetention time.Duration
99-
// LBRebalancingMode controls if and when we do store-level rebalancing
100-
// based on load. It maps to kvserver.LBRebalancingMode.
101-
LBRebalancingMode int64
10298
// LBRebalancingObjective is the load objective to balance.
10399
LBRebalancingObjective int64
104100
// LBRebalancingInterval controls how often the store rebalancer will
@@ -136,7 +132,6 @@ func DefaultSimulationSettings() *SimulationSettings {
136132
StateExchangeDelay: defaultStateExchangeDelay,
137133
SplitQPSThreshold: defaultSplitQPSThreshold,
138134
SplitStatRetention: defaultSplitStatRetention,
139-
LBRebalancingMode: defaultLBRebalancingMode,
140135
LBRebalancingObjective: defaultLBRebalancingObjective,
141136
LBRebalancingInterval: defaultLBRebalancingInterval,
142137
ReplicateQueueEnabled: true,

pkg/kv/kvserver/asim/event/mutation_event.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ type SetNodeLocalityEvent struct {
5454
// SetSimulationSettingsEvent represents a mutation event responsible for
5555
// changing a simulation setting during the simulation.
5656
type SetSimulationSettingsEvent struct {
57-
Key string
58-
Value interface{}
57+
IsClusterSetting bool
58+
Key string
59+
Value interface{}
5960
}
6061

6162
var _ Event = &SetSpanConfigEvent{}
@@ -140,7 +141,11 @@ func (sne SetNodeLocalityEvent) String() string {
140141

141142
func (se SetSimulationSettingsEvent) Func() EventFunc {
142143
return MutationFunc(func(ctx context.Context, s state.State) {
143-
s.SetSimulationSettings(se.Key, se.Value)
144+
if se.IsClusterSetting {
145+
s.SetClusterSetting(se.Key, se.Value)
146+
} else {
147+
s.SetSimulationSettings(se.Key, se.Value)
148+
}
144149
})
145150
}
146151

pkg/kv/kvserver/asim/mmaintegration/mma_store_rebalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (msr *MMAStoreRebalancer) Tick(ctx context.Context, tick time.Time, s state
9797
return
9898
}
9999

100-
if msr.settings.LBRebalancingMode != int64(kvserver.LBRebalancingMultiMetric) {
100+
if kvserver.LoadBasedRebalancingMode.Get(&msr.settings.ST.SV) != kvserver.LBRebalancingMultiMetric {
101101
// When the store rebalancer isn't set to use the multi-metric mode, the
102102
// legacy store rebalancer is used.
103103
return

pkg/kv/kvserver/asim/state/impl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,15 @@ func (s *state) RegisterConfigChangeListener(listener ConfigChangeListener) {
13931393
s.configChangeListeners = append(s.configChangeListeners, listener)
13941394
}
13951395

1396+
func (s *state) SetClusterSetting(Key string, Value interface{}) {
1397+
switch Key {
1398+
case "LBRebalancingMode":
1399+
kvserver.LoadBasedRebalancingMode.Override(context.Background(), &s.settings.ST.SV, kvserver.LBRebalancingMode(Value.(int64)))
1400+
default:
1401+
panic("other cluster settings not supported")
1402+
}
1403+
}
1404+
13961405
// SetSimulationSettings sets the simulation setting for the given key to the
13971406
// given value.
13981407
func (s *state) SetSimulationSettings(Key string, Value interface{}) {

pkg/kv/kvserver/asim/state/state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ type State interface {
202202
RegisterConfigChangeListener(ConfigChangeListener)
203203
// SetSimulationSettings sets the simulation settings for the state.
204204
SetSimulationSettings(Key string, Value interface{})
205+
// SetClusterSetting sets the cluster setting for the state.
206+
SetClusterSetting(Key string, Value interface{})
205207
// NodeCapacity returns the capacity of the node with ID NodeID.
206208
NodeCapacity(NodeID) roachpb.NodeCapacity
207209
// SetNodeCPURateCapacity sets the CPU rate capacity for the node with ID

pkg/kv/kvserver/asim/storerebalancer/store_rebalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (src *storeRebalancerControl) phasePrologue(
190190
s, src.storeID,
191191
kvserver.LBRebalancingObjective(src.settings.LBRebalancingObjective).ToDimension(),
192192
),
193-
kvserver.LBRebalancingMode(src.settings.LBRebalancingMode),
193+
kvserver.LoadBasedRebalancingMode.Get(&src.settings.ST.SV),
194194
)
195195

196196
if !src.sr.ShouldRebalanceStore(ctx, rctx) {

pkg/kv/kvserver/asim/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ go_test(
3838
data = glob(["testdata/**"]),
3939
embed = [":tests"],
4040
deps = [
41+
"//pkg/kv/kvserver",
4142
"//pkg/kv/kvserver/allocator/allocatorimpl",
4243
"//pkg/kv/kvserver/asim/assertion",
4344
"//pkg/kv/kvserver/asim/config",

pkg/kv/kvserver/asim/tests/datadriven_simulation_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
1617
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/allocatorimpl"
1718
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/assertion"
1819
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config"
@@ -509,25 +510,29 @@ func TestDataDriven(t *testing.T) {
509510
}
510511
return ""
511512
case "setting":
513+
scanIfExists(t, d, "replicate_queue_enabled", &settingsGen.Settings.ReplicateQueueEnabled)
514+
scanIfExists(t, d, "lease_queue_enabled", &settingsGen.Settings.LeaseQueueEnabled)
515+
scanIfExists(t, d, "split_queue_enabled", &settingsGen.Settings.SplitQueueEnabled)
516+
scanIfExists(t, d, "rebalance_interval", &settingsGen.Settings.LBRebalancingInterval)
517+
scanIfExists(t, d, "split_qps_threshold", &settingsGen.Settings.SplitQPSThreshold)
518+
scanIfExists(t, d, "rebalance_range_threshold", &settingsGen.Settings.RangeRebalanceThreshold)
519+
scanIfExists(t, d, "gossip_delay", &settingsGen.Settings.StateExchangeDelay)
520+
scanIfExists(t, d, "range_size_split_threshold", &settingsGen.Settings.RangeSizeSplitThreshold)
521+
scanIfExists(t, d, "rebalance_objective", &settingsGen.Settings.LBRebalancingObjective)
512522
var delay time.Duration
513523
if isDelayed := scanIfExists(t, d, "delay", &delay); isDelayed {
514524
var rebalanceMode int64
515525
scanIfExists(t, d, "rebalance_mode", &rebalanceMode)
516526
eventGen.ScheduleEvent(settingsGen.Settings.StartTime, delay, event.SetSimulationSettingsEvent{
517-
Key: "LBRebalancingMode",
518-
Value: rebalanceMode,
527+
IsClusterSetting: true,
528+
Key: "LBRebalancingMode",
529+
Value: rebalanceMode,
519530
})
520531
} else {
521-
scanIfExists(t, d, "replicate_queue_enabled", &settingsGen.Settings.ReplicateQueueEnabled)
522-
scanIfExists(t, d, "lease_queue_enabled", &settingsGen.Settings.LeaseQueueEnabled)
523-
scanIfExists(t, d, "split_queue_enabled", &settingsGen.Settings.SplitQueueEnabled)
524-
scanIfExists(t, d, "rebalance_mode", &settingsGen.Settings.LBRebalancingMode)
525-
scanIfExists(t, d, "rebalance_interval", &settingsGen.Settings.LBRebalancingInterval)
526-
scanIfExists(t, d, "split_qps_threshold", &settingsGen.Settings.SplitQPSThreshold)
527-
scanIfExists(t, d, "rebalance_range_threshold", &settingsGen.Settings.RangeRebalanceThreshold)
528-
scanIfExists(t, d, "gossip_delay", &settingsGen.Settings.StateExchangeDelay)
529-
scanIfExists(t, d, "range_size_split_threshold", &settingsGen.Settings.RangeSizeSplitThreshold)
530-
scanIfExists(t, d, "rebalance_objective", &settingsGen.Settings.LBRebalancingObjective)
532+
var rebalanceMode int64
533+
if exists := scanIfExists(t, d, "rebalance_mode", &rebalanceMode); exists {
534+
kvserver.LoadBasedRebalancingMode.Override(ctx, &settingsGen.Settings.ST.SV, kvserver.LBRebalancingMode(rebalanceMode))
535+
}
531536
}
532537
return ""
533538
case "print":

0 commit comments

Comments
 (0)