github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/base/test_server_args.go (about) 1 // Copyright 2016 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package base 12 13 import ( 14 "context" 15 "time" 16 17 "github.com/cockroachdb/cockroach/pkg/roachpb" 18 "github.com/cockroachdb/cockroach/pkg/settings/cluster" 19 "github.com/cockroachdb/cockroach/pkg/util/mon" 20 "github.com/cockroachdb/cockroach/pkg/util/retry" 21 "github.com/cockroachdb/cockroach/pkg/util/stop" 22 ) 23 24 // TestServerArgs contains the parameters one can set when creating a test 25 // server. Notably, TestServerArgs are passed to serverutils.StartServer(). 26 // They're defined in base because they need to be shared between 27 // testutils/serverutils (test code) and server.TestServer (non-test code). 28 // 29 // The zero value is suitable for most tests. 30 type TestServerArgs struct { 31 // Knobs for the test server. 32 Knobs TestingKnobs 33 34 *cluster.Settings 35 RaftConfig 36 37 // LeaseManagerConfig holds configuration values specific to the LeaseManager. 38 LeaseManagerConfig *LeaseManagerConfig 39 40 // PartOfCluster must be set if the TestServer is joining others in a cluster. 41 // If not set (and hence the server is the only one in the cluster), the 42 // default zone config will be overridden to disable all replication - so that 43 // tests don't get log spam about ranges not being replicated enough. This 44 // is always set to true when the server is started via a TestCluster. 45 PartOfCluster bool 46 47 // Addr (if nonempty) is the RPC address to use for the test server. 48 Addr string 49 // SQLAddr (if nonempty) is the SQL address to use for the test server. 50 SQLAddr string 51 // HTTPAddr (if nonempty) is the HTTP address to use for the test server. 52 HTTPAddr string 53 // DisableTLSForHTTP if set, disables TLS for the HTTP interface. 54 DisableTLSForHTTP bool 55 56 // JoinAddr is the address of a node we are joining. 57 // 58 // If left empty and the TestServer is being added to a nonempty cluster, this 59 // will be set to the the address of the cluster's first node. 60 JoinAddr string 61 62 // StoreSpecs define the stores for this server. If you want more than 63 // one store per node, populate this array with StoreSpecs each 64 // representing a store. If no StoreSpecs are provided then a single 65 // DefaultTestStoreSpec will be used. 66 StoreSpecs []StoreSpec 67 68 // Locality is optional and will set the server's locality. 69 Locality roachpb.Locality 70 71 // TempStorageConfig defines parameters for the temp storage used as 72 // working memory for distributed operations and CSV importing. 73 // If not initialized, will default to DefaultTestTempStorageConfig. 74 TempStorageConfig TempStorageConfig 75 76 // ExternalIODir is used to initialize field in cluster.Settings. 77 ExternalIODir string 78 79 // Fields copied to the server.Config. 80 Insecure bool 81 RetryOptions retry.Options // TODO(tbg): make testing knob. 82 SocketFile string 83 ScanInterval time.Duration 84 ScanMinIdleTime time.Duration 85 ScanMaxIdleTime time.Duration 86 SSLCertsDir string 87 TimeSeriesQueryWorkerMax int 88 TimeSeriesQueryMemoryBudget int64 89 SQLMemoryPoolSize int64 90 CacheSize int64 91 92 // If set, this will be appended to the Postgres URL by functions that 93 // automatically open a connection to the server. That's equivalent to running 94 // SET DATABASE=foo, which works even if the database doesn't (yet) exist. 95 UseDatabase string 96 97 // If set, this will be configured in the test server to check connections 98 // from other test servers and to report in the SQL introspection. 99 ClusterName string 100 101 // Stopper can be used to stop the server. If not set, a stopper will be 102 // constructed and it can be gotten through TestServerInterface.Stopper(). 103 Stopper *stop.Stopper 104 105 // If set, the recording of events to the event log tables is disabled. 106 DisableEventLog bool 107 108 // If set, web session authentication will be disabled, even if the server 109 // is running in secure mode. 110 DisableWebSessionAuthentication bool 111 } 112 113 // TestClusterArgs contains the parameters one can set when creating a test 114 // cluster. It contains a TestServerArgs instance which will be copied over to 115 // every server. 116 // 117 // The zero value means "ReplicationAuto". 118 type TestClusterArgs struct { 119 // ServerArgs will be copied and potentially adjusted according to the 120 // ReplicationMode for each constituent TestServer. Used for all the servers 121 // not overridden in ServerArgsPerNode. 122 ServerArgs TestServerArgs 123 // ReplicationMode controls how replication is to be done in the cluster. 124 ReplicationMode TestClusterReplicationMode 125 // If true, nodes will be started in parallel. This is useful in 126 // testing certain recovery scenarios, although it makes store/node 127 // IDs unpredictable. Even in ParallelStart mode, StartTestCluster 128 // waits for all nodes to start before returning. 129 ParallelStart bool 130 131 // ServerArgsPerNode override the default ServerArgs with the value in this 132 // map. The map's key is an index within TestCluster.Servers. If there is 133 // no entry in the map for a particular server, the default ServerArgs are 134 // used. 135 // 136 // A copy of an entry from this map will be copied to each individual server 137 // and potentially adjusted according to ReplicationMode. 138 ServerArgsPerNode map[int]TestServerArgs 139 } 140 141 var ( 142 // DefaultTestStoreSpec is just a single in memory store of 100 MiB 143 // with no special attributes. 144 DefaultTestStoreSpec = StoreSpec{ 145 InMemory: true, 146 } 147 ) 148 149 // DefaultTestTempStorageConfig is the associated temp storage for 150 // DefaultTestStoreSpec that is in-memory. 151 // It has a maximum size of 100MiB. 152 func DefaultTestTempStorageConfig(st *cluster.Settings) TempStorageConfig { 153 return DefaultTestTempStorageConfigWithSize(st, DefaultInMemTempStorageMaxSizeBytes) 154 } 155 156 // DefaultTestTempStorageConfigWithSize is the associated temp storage for 157 // DefaultTestStoreSpec that is in-memory with the customized maximum size. 158 func DefaultTestTempStorageConfigWithSize( 159 st *cluster.Settings, maxSizeBytes int64, 160 ) TempStorageConfig { 161 monitor := mon.MakeMonitor( 162 "in-mem temp storage", 163 mon.DiskResource, 164 nil, /* curCount */ 165 nil, /* maxHist */ 166 1024*1024, /* increment */ 167 maxSizeBytes/10, /* noteworthy */ 168 st, 169 ) 170 monitor.Start(context.Background(), nil /* pool */, mon.MakeStandaloneBudget(maxSizeBytes)) 171 return TempStorageConfig{ 172 InMemory: true, 173 Mon: &monitor, 174 } 175 } 176 177 // TestClusterReplicationMode represents the replication settings for a TestCluster. 178 type TestClusterReplicationMode int 179 180 //go:generate stringer -type=TestClusterReplicationMode 181 182 const ( 183 // ReplicationAuto means that ranges are replicated according to the 184 // production default zone config. Replication is performed as in 185 // production, by the replication queue. 186 // If ReplicationAuto is used, StartTestCluster() blocks until the initial 187 // ranges are fully replicated. 188 ReplicationAuto TestClusterReplicationMode = iota 189 // ReplicationManual means that the split and replication queues of all 190 // servers are stopped, and the test must manually control splitting and 191 // replication through the TestServer. 192 // Note that the server starts with a number of system ranges, 193 // all with a single replica on node 1. 194 ReplicationManual 195 ) 196 197 // TestTenantArgs are the arguments used when creating a tenant from a 198 // TestServer. 199 type TestTenantArgs struct { 200 TenantID roachpb.TenantID 201 // AllowSettingClusterSettings, if true, allows the tenant to set in-memory 202 // cluster settings. 203 AllowSettingClusterSettings bool 204 }