Skip to content

Commit 243aa8f

Browse files
wenyihu6tbg
authored andcommitted
asim: integrate cluster setting properly
Previously, new cluster settings were created ad hoc throughout asim, making it hard to change cluster settings. In addition, it was also hard to distinguish between simulation and cluster settings. This commit adds a cluster settings field to the simulation settings struct, initializing it once and passing it throughout. Note that many simulation settings that should be cluster settings still remain; a TODO is left to clean this up in the future. Epic: none Release note: none
1 parent 81ea4fa commit 243aa8f

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go_library(
55
srcs = ["settings.go"],
66
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config",
77
visibility = ["//visibility:public"],
8+
deps = ["//pkg/settings/cluster"],
89
)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
package config
77

8-
import "time"
8+
import (
9+
"time"
10+
11+
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
12+
)
913

1014
const (
1115
defaultTickInteval = 500 * time.Millisecond
@@ -114,6 +118,11 @@ type SimulationSettings struct {
114118
LeaseQueueEnabled bool
115119
// SplitQueueEnabled controls whether the split queue is enabled.
116120
SplitQueueEnabled bool
121+
// st is used to update cockroach cluster settings.
122+
//
123+
// TODO(wenyihu6): Remove any non-simulation settings from this struct and
124+
// instead override the settings below.
125+
ST *cluster.Settings
117126
}
118127

119128
// DefaultSimulationSettings returns a set of default settings for simulation.
@@ -143,6 +152,7 @@ func DefaultSimulationSettings() *SimulationSettings {
143152
ReplicateQueueEnabled: true,
144153
LeaseQueueEnabled: true,
145154
SplitQueueEnabled: true,
155+
ST: cluster.MakeClusterSettings(),
146156
}
147157
}
148158

pkg/kv/kvserver/asim/gossip/gossip.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ type storeGossiper struct {
5050
}
5151

5252
func newStoreGossiper(
53-
descriptorGetter func(cached bool) roachpb.StoreDescriptor, clock timeutil.TimeSource,
53+
descriptorGetter func(cached bool) roachpb.StoreDescriptor,
54+
clock timeutil.TimeSource,
55+
st *cluster.Settings,
5456
) *storeGossiper {
5557
sg := &storeGossiper{
5658
lastIntervalGossip: time.Time{},
@@ -59,7 +61,7 @@ func newStoreGossiper(
5961

6062
desc := sg.descriptorGetter(false /* cached */)
6163
knobs := kvserver.StoreGossipTestingKnobs{AsyncDisabled: true}
62-
sg.local = kvserver.NewStoreGossip(sg, sg, knobs, &cluster.MakeTestingClusterSettings().SV, clock)
64+
sg.local = kvserver.NewStoreGossip(sg, sg, knobs, &st.SV, clock)
6365
sg.local.Ident = roachpb.StoreIdent{StoreID: desc.StoreID, NodeID: desc.Node.NodeID}
6466

6567
return sg
@@ -122,7 +124,7 @@ func (g *gossip) addStoreToGossip(s state.State, storeID state.StoreID) {
122124
g.storeGossip[storeID] = &storeGossiper{addingStore: true}
123125
g.storeGossip[storeID] = newStoreGossiper(func(cached bool) roachpb.StoreDescriptor {
124126
return s.StoreDescriptors(cached, storeID)[0]
125-
}, s.Clock())
127+
}, s.Clock(), g.settings.ST)
126128
}
127129

128130
// Tick checks for completed gossip updates and triggers new gossip

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ func testingResetLoad(s State, rangeID RangeID) {
5959
// NewStorePool returns a store pool with no gossip instance and default values
6060
// for configuration.
6161
func NewStorePool(
62-
nodeCountFn storepool.NodeCountFunc, nodeLivenessFn storepool.NodeLivenessFunc, hlc *hlc.Clock,
62+
nodeCountFn storepool.NodeCountFunc,
63+
nodeLivenessFn storepool.NodeLivenessFunc,
64+
hlc *hlc.Clock,
65+
st *cluster.Settings,
6366
) (*storepool.StorePool, *cluster.Settings) {
6467
stopper := stop.NewStopper()
6568
defer stopper.Stop(context.Background())
6669

67-
st := cluster.MakeTestingClusterSettings()
6870
ambientCtx := log.MakeTestingAmbientContext(stopper.Tracer())
6971

7072
// Never gossip, pass in nil values.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func (s *state) AddStore(nodeID NodeID) (Store, bool) {
518518
node := s.nodes[nodeID]
519519
s.storeSeqGen++
520520
storeID := s.storeSeqGen
521-
sp, st := NewStorePool(s.NodeCountFn(), s.NodeLivenessFn(), hlc.NewClockForTesting(s.clock))
521+
sp, st := NewStorePool(s.NodeCountFn(), s.NodeLivenessFn(), hlc.NewClockForTesting(s.clock), s.settings.ST)
522522
store := &store{
523523
storeID: storeID,
524524
nodeID: nodeID,
@@ -1279,7 +1279,7 @@ func (s *state) Scan(
12791279
func (s *state) Report() roachpb.SpanConfigConformanceReport {
12801280
reporter := spanconfigreporter.New(
12811281
s.nodeLiveness, s, s, s,
1282-
cluster.MakeClusterSettings(), &spanconfig.TestingKnobs{})
1282+
s.settings.ST, &spanconfig.TestingKnobs{})
12831283
report, err := reporter.SpanConfigConformance(context.Background(), []roachpb.Span{{}})
12841284
if err != nil {
12851285
panic(fmt.Sprintf("programming error: error getting span config report %s", err.Error()))

0 commit comments

Comments
 (0)