@@ -78,6 +78,8 @@ const (
78
78
// By default, we allocate 20% of available memory to the test server.
79
79
const defaultStoreMemSize = 0.2
80
80
81
+ const defaultCacheSize = 0.1
82
+
81
83
const defaultInitTimeout = 60
82
84
const defaultPollListenURLTimeout = 60
83
85
const defaultListenAddrHost = "localhost"
@@ -224,7 +226,8 @@ type testServerArgs struct {
224
226
secure bool
225
227
rootPW string // if nonempty, set as pw for root
226
228
storeOnDisk bool // to save database in disk
227
- storeMemSize float64 // the proportion of available memory allocated to test server
229
+ storeMemSize float64 // the proportion of available memory allocated to test server in-memory store
230
+ cacheSize float64 // the proportion of available memory allocated to cache
228
231
httpPorts []int
229
232
listenAddrPorts []int
230
233
listenAddrHost string
@@ -287,6 +290,18 @@ func SetStoreMemSizeOpt(memSize float64) TestServerOpt {
287
290
}
288
291
}
289
292
293
+ // CacheSizeOpt sets the proportion of available memory that is allocated
294
+ // to the CockroachDB cache.
295
+ func CacheSizeOpt (cacheSize float64 ) TestServerOpt {
296
+ return func (args * testServerArgs ) {
297
+ if cacheSize > 0 {
298
+ args .cacheSize = cacheSize
299
+ } else {
300
+ args .cacheSize = defaultCacheSize
301
+ }
302
+ }
303
+ }
304
+
290
305
// RootPasswordOpt is a TestServer option that, when passed to NewTestServer,
291
306
// sets the given password for the root user (and returns a URL using it from
292
307
// PGURL(). This avoids having to use client certs.
@@ -436,6 +451,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {
436
451
437
452
serverArgs := & testServerArgs {numNodes : 1 }
438
453
serverArgs .storeMemSize = defaultStoreMemSize
454
+ serverArgs .cacheSize = defaultCacheSize
439
455
serverArgs .initTimeoutSeconds = defaultInitTimeout
440
456
serverArgs .pollListenURLTimeoutSeconds = defaultPollListenURLTimeout
441
457
serverArgs .listenAddrHost = defaultListenAddrHost
@@ -604,6 +620,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {
604
620
"--port=" + strconv .Itoa (serverArgs .listenAddrPorts [0 ]),
605
621
"--http-port=" + strconv .Itoa (serverArgs .httpPorts [0 ]),
606
622
storeArg ,
623
+ "--cache=" + strconv .FormatFloat (serverArgs .cacheSize , 'f' , 4 , 64 ),
607
624
"--listening-url-file=" + nodes [i ].listeningURLFile ,
608
625
"--external-io-dir=" + serverArgs .externalIODir ,
609
626
}
0 commit comments