Skip to content

Commit 999b802

Browse files
authored
Merge pull request #126 from axw/mgoinstance-storagebackend
Default mongo storage backend to mmapv1 This makes the Juju tests significantly faster. Make the storage engine configurable via the $JUJU_MONGO_STORAGE_ENGINE environment variable.
2 parents 7d312c4 + 88a9bf8 commit 999b802

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

mgo.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,31 @@ var (
4545
// regular expression to match output of mongod
4646
waitingForConnectionsRe = regexp.MustCompile(".*waiting for connections.*")
4747

48+
mongo32 = version.Number{Major: 3, Minor: 2}
49+
4850
// After version 3.2 we shouldn't use --nojournal - it makes the
4951
// WiredTiger storage engine much slower.
5052
// https://jira.mongodb.org/browse/SERVER-21198
51-
useJournalMongoVersion = version.Number{Major: 3, Minor: 2}
52-
installedMongod mongodCache
53+
useJournalMongoVersion = mongo32
54+
55+
// From mongo 3.2 onwards, we can specify a storage engine.
56+
storageEngineMongoVersion = mongo32
57+
58+
installedMongod mongodCache
5359
)
5460

5561
const (
5662
// Maximum number of times to attempt starting mongod.
5763
maxStartMongodAttempts = 5
64+
5865
// The default password to use when connecting to the mongo database.
5966
DefaultMongoPassword = "conn-from-name-secret"
67+
68+
// defaultMongoStorageEngine is the default storage engine to use
69+
// in Mongo 3.2 onwards for tests. We default to mmapv1 (vs. the
70+
// mongo default of wiredTiger) for the best performance in tests,
71+
// but make it configurable.
72+
defaultMongoStorageEngine = "mmapv1"
6073
)
6174

6275
// Certs holds the certificates and keys required to make a secure
@@ -248,6 +261,13 @@ func (inst *MgoInstance) run() error {
248261
if version.Compare(useJournalMongoVersion) == -1 {
249262
mgoargs = append(mgoargs, "--nojournal")
250263
}
264+
if version.Compare(storageEngineMongoVersion) >= 0 {
265+
storageEngine := os.Getenv("JUJU_MONGO_STORAGE_ENGINE")
266+
if storageEngine == "" {
267+
storageEngine = defaultMongoStorageEngine
268+
}
269+
mgoargs = append(mgoargs, "--storageEngine", storageEngine)
270+
}
251271

252272
if inst.Params != nil {
253273
mgoargs = append(mgoargs, inst.Params...)

0 commit comments

Comments
 (0)