-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
test_server_args.go
177 lines (152 loc) · 6.54 KB
/
test_server_args.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2016 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package base
import (
"context"
"time"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/mon"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/stop"
)
// TestServerArgs contains the parameters one can set when creating a test
// server. Notably, TestServerArgs are passed to serverutils.StartServer().
// They're defined in base because they need to be shared between
// testutils/serverutils (test code) and server.TestServer (non-test code).
//
// The zero value is suitable for most tests.
type TestServerArgs struct {
// Knobs for the test server.
Knobs TestingKnobs
*cluster.Settings
RaftConfig
// LeaseManagerConfig holds configuration values specific to the LeaseManager.
LeaseManagerConfig *LeaseManagerConfig
// PartOfCluster must be set if the TestServer is joining others in a cluster.
// If not set (and hence the server is the only one in the cluster), the
// default zone config will be overridden to disable all replication - so that
// tests don't get log spam about ranges not being replicated enough. This
// is always set to true when the server is started via a TestCluster.
PartOfCluster bool
// Addr (if nonempty) is the address to use for the test server.
Addr string
// HTTPAddr (if nonempty) is the HTTP address to use for the test server.
HTTPAddr string
// JoinAddr is the address of a node we are joining.
//
// If left empty and the TestServer is being added to a nonempty cluster, this
// will be set to the the address of the cluster's first node.
JoinAddr string
// StoreSpecs define the stores for this server. If you want more than
// one store per node, populate this array with StoreSpecs each
// representing a store. If no StoreSpecs are provided then a single
// DefaultTestStoreSpec will be used.
StoreSpecs []StoreSpec
// Locality is optional and will set the server's locality.
Locality roachpb.Locality
// TempStorageConfig defines parameters for the temp storage used as
// working memory for distributed operations and CSV importing.
// If not initialized, will default to DefaultTestTempStorageConfig.
TempStorageConfig TempStorageConfig
// ExternalIODir is used to initialize field in cluster.Settings.
ExternalIODir string
// Fields copied to the server.Config.
Insecure bool
RetryOptions retry.Options
SocketFile string
ScanInterval time.Duration
ScanMinIdleTime time.Duration
ScanMaxIdleTime time.Duration
SSLCertsDir string
TimeSeriesQueryWorkerMax int
TimeSeriesQueryMemoryBudget int64
SQLMemoryPoolSize int64
// If set, this will be appended to the Postgres URL by functions that
// automatically open a connection to the server. That's equivalent to running
// SET DATABASE=foo, which works even if the database doesn't (yet) exist.
UseDatabase string
// Stopper can be used to stop the server. If not set, a stopper will be
// constructed and it can be gotten through TestServerInterface.Stopper().
Stopper *stop.Stopper
// If set, the recording of events to the event log tables is disabled.
DisableEventLog bool
// If set, web session authentication will be disabled, even if the server
// is running in secure mode.
DisableWebSessionAuthentication bool
}
// TestClusterArgs contains the parameters one can set when creating a test
// cluster. It contains a TestServerArgs instance which will be copied over to
// every server.
//
// The zero value means "ReplicationAuto".
type TestClusterArgs struct {
// ServerArgs will be copied and potentially adjusted according to the
// ReplicationMode for each constituent TestServer. Used for all the servers
// not overridden in ServerArgsPerNode.
ServerArgs TestServerArgs
// ReplicationMode controls how replication is to be done in the cluster.
ReplicationMode TestClusterReplicationMode
// ServerArgsPerNode override the default ServerArgs with the value in this
// map. The map's key is an index within TestCluster.Servers. If there is
// no entry in the map for a particular server, the default ServerArgs are
// used.
//
// A copy of an entry from this map will be copied to each individual server
// and potentially adjusted according to ReplicationMode.
ServerArgsPerNode map[int]TestServerArgs
}
var (
// DefaultTestStoreSpec is just a single in memory store of 100 MiB
// with no special attributes.
DefaultTestStoreSpec = StoreSpec{
InMemory: true,
}
)
// DefaultTestTempStorageConfig is the associated temp storage for
// DefaultTestStoreSpec that is in-memory.
// It has a maximum size of 100MiB.
func DefaultTestTempStorageConfig(st *cluster.Settings) TempStorageConfig {
var maxSizeBytes int64 = DefaultInMemTempStorageMaxSizeBytes
monitor := mon.MakeMonitor(
"in-mem temp storage",
mon.MemoryResource,
nil, /* curCount */
nil, /* maxHist */
1024*1024, /* increment */
maxSizeBytes/10, /* noteworthy */
st,
)
monitor.Start(context.Background(), nil /* pool */, mon.MakeStandaloneBudget(maxSizeBytes))
return TempStorageConfig{
InMemory: true,
Mon: &monitor,
}
}
// TestClusterReplicationMode represents the replication settings for a TestCluster.
type TestClusterReplicationMode int
//go:generate stringer -type=TestClusterReplicationMode
const (
// ReplicationAuto means that ranges are replicated according to the
// production default zone config. Replication is performed as in
// production, by the replication queue.
// If ReplicationAuto is used, StartTestCluster() blocks until the initial
// ranges are fully replicated.
ReplicationAuto TestClusterReplicationMode = iota
// ReplicationManual means that the split and replication queues of all
// servers are stopped, and the test must manually control splitting and
// replication through the TestServer.
// Note that the server starts with a number of system ranges.
ReplicationManual
)