Skip to content

Commit 5dd32a1

Browse files
craig[bot]wenyihu6rafisstbg
committed
155033: asim: use kvserver.LoadBasedRebalancingObjective r=wenyihu6 a=wenyihu6 Previously, LBRebalancingObjective was part of the simulation settings, using QPS as the load rebalance objective. However, the cluster setting kvserver.LoadBasedRebalancingObjective defaults to CPU rebalancing instead. This commit updates asim to rely on the cluster setting, adopting the default cluster setting configuration. Epic: CRDB-55052 Release note: none Resolves: #154512 156876: rttanalysis: deflake BenchmarkJobs r=rafiss a=rafiss The benchmark started failing since the code doesn't handle a nil table descriptor. The fix is to create a dummy descriptor in the job payload details. fixes #151302 Release note: None 156942: server: make mma Allocator calls more visible r=wenyihu6 a=tbg They were kind of hidden before, and it has been tripping me up every now and then for a while. The problem was that NewAllocatorState returns a private struct directly, so a bunch of the calls later in the method do not show up when you look at the call hierarchy for the Allocator interface. This is now fixed. Epic: CRDB-55052. Co-authored-by: wenyihu6 <[email protected]> Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Tobias Grieger <[email protected]>
4 parents 7189668 + 10ce3e9 + 60804c6 + d2cfdda commit 5dd32a1

18 files changed

+106
-112
lines changed

pkg/bench/rttanalysis/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ go_test(
6565
"//pkg/security/username",
6666
"//pkg/server",
6767
"//pkg/server/serverpb",
68+
"//pkg/sql/catalog/descpb",
6869
"//pkg/testutils/pgurlutils",
6970
"//pkg/testutils/serverutils",
7071
"//pkg/testutils/skip",

pkg/bench/rttanalysis/jobs_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/security/username"
1515
"github.com/cockroachdb/cockroach/pkg/server"
1616
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
17+
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
1718
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
1819
)
1920

2021
func BenchmarkJobs(b *testing.B) { reg.Run(b) }
2122
func init() {
23+
// Create a minimal table descriptor for the import job.
24+
tableDesc := &descpb.TableDescriptor{
25+
ID: 100,
26+
ParentID: 1,
27+
Name: "benchmark_table",
28+
FormatVersion: descpb.InterleavedFormatVersion,
29+
Version: 1,
30+
}
31+
2232
payloadBytes, err := protoutil.Marshal(&jobspb.Payload{
23-
Details: jobspb.WrapPayloadDetails(jobspb.ImportDetails{}),
33+
Details: jobspb.WrapPayloadDetails(jobspb.ImportDetails{
34+
Table: jobspb.ImportDetails_Table{
35+
Desc: tableDesc,
36+
},
37+
}),
2438
UsernameProto: username.RootUserName().EncodeProto(),
2539
})
2640
if err != nil {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const (
2929
defaultSplitStatRetention = 10 * time.Minute
3030
defaultSeed = 42
3131
defaultLBRebalancingInterval = time.Minute
32-
defaultLBRebalanceQPSThreshold = 0.1
33-
defaultLBRebalancingObjective = 0 // QPS
3432
)
3533

3634
const DefaultNodeCPURateCapacityNanos = 8 * 1e9 // 8 vcpus
@@ -101,8 +99,6 @@ type SimulationSettings struct {
10199
// SplitStatRetention is the duration which recorded load will be retained
102100
// and factored into load based splitting decisions.
103101
SplitStatRetention time.Duration
104-
// LBRebalancingObjective is the load objective to balance.
105-
LBRebalancingObjective int64
106102
// LBRebalancingInterval controls how often the store rebalancer will
107103
// consider opportunities for rebalancing.
108104
LBRebalancingInterval time.Duration
@@ -141,7 +137,6 @@ func DefaultSimulationSettings() *SimulationSettings {
141137
StateExchangeDelay: defaultStateExchangeDelay,
142138
SplitQPSThreshold: defaultSplitQPSThreshold,
143139
SplitStatRetention: defaultSplitStatRetention,
144-
LBRebalancingObjective: defaultLBRebalancingObjective,
145140
LBRebalancingInterval: defaultLBRebalancingInterval,
146141
ReplicateQueueEnabled: true,
147142
LeaseQueueEnabled: true,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,8 @@ func (s *state) SetClusterSetting(Key string, Value interface{}) {
14021402
switch Key {
14031403
case "LBRebalancingMode":
14041404
kvserverbase.LoadBasedRebalancingMode.Override(context.Background(), &s.settings.ST.SV, kvserverbase.LBRebalancingMode(Value.(int64)))
1405+
case "LBRebalancingObjective":
1406+
kvserver.LoadBasedRebalancingObjective.Override(context.Background(), &s.settings.ST.SV, kvserver.LBRebalancingObjective(Value.(int64)))
14051407
default:
14061408
panic("other cluster settings not supported")
14071409
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ type simRebalanceObjectiveProvider struct {
126126

127127
// Objective returns the current rebalance objective.
128128
func (s simRebalanceObjectiveProvider) Objective() kvserver.LBRebalancingObjective {
129-
return kvserver.LBRebalancingObjective(s.settings.LBRebalancingObjective)
129+
return kvserver.LoadBasedRebalancingObjective.Get(&s.settings.ST.SV)
130130
}
131131

132132
func (src *storeRebalancerControl) scorerOptions() *allocatorimpl.LoadScorerOptions {
133-
dim := kvserver.LBRebalancingObjective(src.settings.LBRebalancingObjective).ToDimension()
133+
dim := kvserver.LoadBasedRebalancingObjective.Get(&src.settings.ST.SV).ToDimension()
134134
return &allocatorimpl.LoadScorerOptions{
135135
BaseScorerOptions: allocatorimpl.BaseScorerOptions{
136136
IOOverload: src.allocator.IOOverloadOptions(),
@@ -191,7 +191,7 @@ func (src *storeRebalancerControl) phasePrologue(
191191
ctx, src.scorerOptions(),
192192
hottestRanges(
193193
s, src.storeID,
194-
kvserver.LBRebalancingObjective(src.settings.LBRebalancingObjective).ToDimension(),
194+
kvserver.LoadBasedRebalancingObjective.Get(&src.settings.ST.SV).ToDimension(),
195195
),
196196
kvserverbase.LoadBasedRebalancingMode.Get(&src.settings.ST.SV),
197197
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
1314
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config"
1415
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/gossip"
1516
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/op"
@@ -36,6 +37,8 @@ func TestStoreRebalancer(t *testing.T) {
3637
start := testSettings.StartTime
3738
testSettings.ReplicaChangeBaseDelay = 5 * time.Second
3839
testSettings.StateExchangeDelay = 0
40+
ctx := context.Background()
41+
kvserver.LoadBasedRebalancingObjective.Override(ctx, &testSettings.ST.SV, kvserver.LBRebalancingQueries)
3942

4043
clusterInfo := state.ClusterInfoWithStoreCount(6, 1 /* storesPerNode */)
4144

@@ -195,6 +198,8 @@ func TestStoreRebalancerBalances(t *testing.T) {
195198
testSettings.ReplicaChangeBaseDelay = 1 * time.Second
196199
testSettings.StateExchangeInterval = 1 * time.Second
197200
testSettings.StateExchangeDelay = 0
201+
ctx := context.Background()
202+
kvserver.LoadBasedRebalancingObjective.Override(ctx, &testSettings.ST.SV, kvserver.LBRebalancingQueries)
198203

199204
distributeQPS := func(s state.State, qpsCounts map[state.StoreID]float64) {
200205
dist := make([]float64, len(qpsCounts))

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ func TestDataDriven(t *testing.T) {
724724
dns = scanIfExists(t, d, "rebalance_range_threshold", &settingsGen.Settings.RangeRebalanceThreshold) || dns
725725
dns = scanIfExists(t, d, "gossip_delay", &settingsGen.Settings.StateExchangeDelay) || dns
726726
dns = scanIfExists(t, d, "range_size_split_threshold", &settingsGen.Settings.RangeSizeSplitThreshold) || dns
727-
dns = scanIfExists(t, d, "rebalance_objective", &settingsGen.Settings.LBRebalancingObjective) || dns
728727
var snapshotRateMiB int
729728
dns = scanIfExists(t, d, "rebalancing_snapshot_rate_mib", &snapshotRateMiB) || dns
730729
if snapshotRateMiB != 0 {
@@ -746,6 +745,17 @@ func TestDataDriven(t *testing.T) {
746745
Value: rebalanceMode,
747746
}})
748747
}
748+
749+
var rebalanceObjective int64
750+
if scanIfExists(t, d, "rebalance_objective", &rebalanceObjective) {
751+
events = append(events, scheduled.ScheduledEvent{
752+
At: settingsGen.Settings.StartTime.Add(delay),
753+
TargetEvent: event.SetSimulationSettingsEvent{
754+
IsClusterSetting: true,
755+
Key: "LBRebalancingObjective",
756+
Value: rebalanceObjective,
757+
}})
758+
}
749759
return ""
750760
default:
751761
return fmt.Sprintf("unknown command: %s", d.Cmd)

pkg/kv/kvserver/asim/tests/testdata/generated/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Except this specific directory (relative to .gitignore)
77
# Note that this intentionally does not include subdirectories (such as traces)
88
# which are not deterministic.
9-
!sma/rebalancing/**
9+
!sma/rebalancing_qps/**
1010
**/traces
1111
# And the readme file.
1212
!README.md

0 commit comments

Comments
 (0)