-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
testing_knobs.go
144 lines (132 loc) · 6.44 KB
/
testing_knobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2019 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package server
import (
"net"
"time"
"github.com/cockroachdb/cockroach/pkg/blobs"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/rpc"
"github.com/cockroachdb/cockroach/pkg/server/diagnostics"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
)
// TestingKnobs groups testing knobs for the Server.
type TestingKnobs struct {
// DisableAutomaticVersionUpgrade, if set, temporarily disables the server's
// automatic version upgrade mechanism (until the channel is closed).
DisableAutomaticVersionUpgrade chan struct{}
// DefaultZoneConfigOverride, if set, overrides the default zone config
// defined in `pkg/config/zone.go`.
DefaultZoneConfigOverride *zonepb.ZoneConfig
// DefaultSystemZoneConfigOverride, if set, overrides the default system
// zone config defined in `pkg/config/zone.go`
DefaultSystemZoneConfigOverride *zonepb.ZoneConfig
// SignalAfterGettingRPCAddress, if non-nil, is closed after the server gets
// an RPC server address, and prior to waiting on PauseAfterGettingRPCAddress below.
SignalAfterGettingRPCAddress chan struct{}
// PauseAfterGettingRPCAddress, if non-nil, instructs the server to wait until
// the channel is closed after determining its RPC serving address, and after
// closing SignalAfterGettingRPCAddress.
PauseAfterGettingRPCAddress chan struct{}
// ContextTestingKnobs allows customization of the RPC context testing knobs.
ContextTestingKnobs rpc.ContextTestingKnobs
// DiagnosticsTestingKnobs allows customization of diagnostics testing knobs.
DiagnosticsTestingKnobs diagnostics.TestingKnobs
// If set, use this listener for RPC (and possibly SQL, depending on
// the SplitListenSQL setting), instead of binding a new listener.
// This is useful in tests that need an ephemeral listening port but
// must know it before the server starts.
//
// When this is used, the advertise address should also be set to
// match.
//
// The Server takes responsibility for closing this listener.
// TODO(bdarnell): That doesn't give us a good way to clean up if the
// server fails to start.
RPCListener net.Listener
// BinaryVersionOverride overrides the binary version that the CRDB server
// will end up running. This value could also influence what version the
// cluster is bootstrapped at.
//
// This value, when set, influences test cluster/server creation in two
// different ways:
//
// Case 1:
// ------
// If the test has not overridden the
// `cluster.Settings.Version.BinaryMinSupportedVersion`, then the cluster will
// be bootstrapped at `binaryMinSupportedVersion` (if this server is the one
// bootstrapping the cluster). After all the servers in the test cluster have
// been started, `SET CLUSTER SETTING version = BinaryVersionOverride` will be
// run to step through the upgrades until the specified override.
//
// TODO(adityamaru): We should force tests that set BinaryVersionOverride to
// also set BootstrapVersionKeyOverride so as to specify what image they would
// like the cluster bootstrapped at before upgrading to BinaryVersionOverride.
//
// Case 2:
// ------
// If the test has overridden the
// `cluster.Settings.Version.BinaryMinSupportedVersion` then it is not safe
// for us to bootstrap at `binaryMinSupportedVersion` as it might be less than
// the overridden minimum supported version. Furthermore, we do not have the
// initial cluster data (system tables etc.) to bootstrap at the overridden
// minimum supported version. In this case we bootstrap at
// `BinaryVersionOverride` and populate the cluster with initial data
// corresponding to the `binaryVersion`. In other words no upgrades are
// *really* run and the server only thinks that it is running at
// `BinaryVersionOverride`. Tests that fall in this category should be audited
// for correctness.
//
// The version that we bootstrap at is also used when advertising this
// server's binary version when sending out join requests.
//
// NB: When setting this, you probably also want to set
// DisableAutomaticVersionUpgrade.
BinaryVersionOverride roachpb.Version
// An (additional) callback invoked whenever a
// node is permanently removed from the cluster.
OnDecommissionedCallback func(livenesspb.Liveness)
// StickyEngineRegistry manages the lifecycle of sticky in memory engines,
// which can be enabled via base.StoreSpec.StickyInMemoryEngineID.
//
// When supplied to a TestCluster, StickyEngineIDs will be associated auto-
// matically to the StoreSpecs used.
StickyEngineRegistry StickyInMemEnginesRegistry
// WallClock is used to inject a custom clock for testing the server. It is
// typically either an hlc.HybridManualClock or hlc.ManualClock.
WallClock hlc.WallClock
// ImportTimeseriesFile, if set, is a file created via `DumpRaw` that written
// back to the KV layer upon server start.
ImportTimeseriesFile string
// ImportTimeseriesMappingFile points to a file containing a YAML map from storeID
// to nodeID, for use with ImportTimeseriesFile.
ImportTimeseriesMappingFile string
// DrainSleepFn used in testing to override the usual sleep function with
// a custom function that counts the number of times the sleep function is called.
DrainSleepFn func(time.Duration)
// BlobClientFactory supplies a BlobClientFactory for
// use by servers.
BlobClientFactory blobs.BlobClientFactory
// StubTimeNow allows tests to override the timeutil.Now() function used
// in the jobs endpoint to calculate earliest_retained_time.
StubTimeNow func() time.Time
// We use clusterversion.Key rather than a roachpb.Version because it will be used
// to get initial values to use during bootstrap.
BootstrapVersionKeyOverride clusterversion.Key
// RequireGracefulDrain, if set, causes a shutdown to fail with a log.Fatal
// if the server is not gracefully drained prior to its stopper shutting down.
RequireGracefulDrain bool
}
// ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.
func (*TestingKnobs) ModuleTestingKnobs() {}