From 88a9bf8a40b669b57affe286dd73310c2a5f3c92 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Mon, 1 May 2017 10:17:13 +0800 Subject: [PATCH] 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. --- mgo.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mgo.go b/mgo.go index 5a0885d..9e0dd94 100644 --- a/mgo.go +++ b/mgo.go @@ -45,18 +45,31 @@ var ( // regular expression to match output of mongod waitingForConnectionsRe = regexp.MustCompile(".*waiting for connections.*") + mongo32 = version.Number{Major: 3, Minor: 2} + // After version 3.2 we shouldn't use --nojournal - it makes the // WiredTiger storage engine much slower. // https://jira.mongodb.org/browse/SERVER-21198 - useJournalMongoVersion = version.Number{Major: 3, Minor: 2} - installedMongod mongodCache + useJournalMongoVersion = mongo32 + + // From mongo 3.2 onwards, we can specify a storage engine. + storageEngineMongoVersion = mongo32 + + installedMongod mongodCache ) const ( // Maximum number of times to attempt starting mongod. maxStartMongodAttempts = 5 + // The default password to use when connecting to the mongo database. DefaultMongoPassword = "conn-from-name-secret" + + // defaultMongoStorageEngine is the default storage engine to use + // in Mongo 3.2 onwards for tests. We default to mmapv1 (vs. the + // mongo default of wiredTiger) for the best performance in tests, + // but make it configurable. + defaultMongoStorageEngine = "mmapv1" ) // Certs holds the certificates and keys required to make a secure @@ -248,6 +261,13 @@ func (inst *MgoInstance) run() error { if version.Compare(useJournalMongoVersion) == -1 { mgoargs = append(mgoargs, "--nojournal") } + if version.Compare(storageEngineMongoVersion) >= 0 { + storageEngine := os.Getenv("JUJU_MONGO_STORAGE_ENGINE") + if storageEngine == "" { + storageEngine = defaultMongoStorageEngine + } + mgoargs = append(mgoargs, "--storageEngine", storageEngine) + } if inst.Params != nil { mgoargs = append(mgoargs, inst.Params...)