@@ -78,6 +78,8 @@ const (
7878// By default, we allocate 20% of available memory to the test server.
7979const defaultStoreMemSize = 0.2
8080
81+ const defaultCacheSize = 0.1
82+
8183const defaultInitTimeout = 60
8284const defaultPollListenURLTimeout = 60
8385const defaultListenAddrHost = "localhost"
@@ -224,7 +226,8 @@ type testServerArgs struct {
224226 secure bool
225227 rootPW string // if nonempty, set as pw for root
226228 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
228231 httpPorts []int
229232 listenAddrPorts []int
230233 listenAddrHost string
@@ -287,6 +290,18 @@ func SetStoreMemSizeOpt(memSize float64) TestServerOpt {
287290 }
288291}
289292
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+
290305// RootPasswordOpt is a TestServer option that, when passed to NewTestServer,
291306// sets the given password for the root user (and returns a URL using it from
292307// PGURL(). This avoids having to use client certs.
@@ -436,6 +451,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {
436451
437452 serverArgs := & testServerArgs {numNodes : 1 }
438453 serverArgs .storeMemSize = defaultStoreMemSize
454+ serverArgs .cacheSize = defaultCacheSize
439455 serverArgs .initTimeoutSeconds = defaultInitTimeout
440456 serverArgs .pollListenURLTimeoutSeconds = defaultPollListenURLTimeout
441457 serverArgs .listenAddrHost = defaultListenAddrHost
@@ -604,6 +620,7 @@ func NewTestServer(opts ...TestServerOpt) (TestServer, error) {
604620 "--port=" + strconv .Itoa (serverArgs .listenAddrPorts [0 ]),
605621 "--http-port=" + strconv .Itoa (serverArgs .httpPorts [0 ]),
606622 storeArg ,
623+ "--cache=" + strconv .FormatFloat (serverArgs .cacheSize , 'f' , 4 , 64 ),
607624 "--listening-url-file=" + nodes [i ].listeningURLFile ,
608625 "--external-io-dir=" + serverArgs .externalIODir ,
609626 }
0 commit comments