diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-05-28 12:15:47 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-05-28 12:15:47 -0400 |
commit | 610fab503c216c163c568065a861c2ef95513b3d (patch) | |
tree | d187b31340a843b2e1df849a81ff9ddbc9fb7236 /src/mongo/db/service_context_d.cpp | |
parent | 3bec3c4ec50342ecf3bec7f0581b8479ab27aa04 (diff) | |
download | mongo-610fab503c216c163c568065a861c2ef95513b3d.tar.gz |
SERVER-17861 Change the default storage engine to wiredTiger.
WiredTiger is used as the default storage engine if the dbpath does
not contain any data files. Otherwise, the storage engine specified
in the storage.bson metadata file is used when the --storageEngine
flag is omitted from the command line invocation.
Diffstat (limited to 'src/mongo/db/service_context_d.cpp')
-rw-r--r-- | src/mongo/db/service_context_d.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index 83427b0cef2..eaef2f6f639 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -32,6 +32,8 @@ #include "mongo/db/service_context_d.h" +#include <boost/optional.hpp> + #include "mongo/base/init.h" #include "mongo/base/initializer.h" #include "mongo/db/client.h" @@ -45,6 +47,7 @@ #include "mongo/scripting/engine.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" +#include "mongo/util/map_util.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/scopeguard.h" @@ -72,21 +75,52 @@ namespace mongo { extern bool _supportsDocLocking; - void ServiceContextMongoD::setGlobalStorageEngine(const std::string& name) { + void ServiceContextMongoD::initializeGlobalStorageEngine() { // This should be set once. invariant(!_storageEngine); - const StorageEngine::Factory* factory = _storageFactories[name]; + const std::string dbpath = storageGlobalParams.dbpath; + if (auto existingStorageEngine = StorageEngineMetadata::getStorageEngineForPath(dbpath)) { + if (storageGlobalParams.engineSetByUser) { + // Verify that the name of the user-supplied storage engine matches the contents of + // the metadata file. + const StorageEngine::Factory* factory = mapFindWithDefault( + _storageFactories, + storageGlobalParams.engine, + static_cast<const StorageEngine::Factory*>(nullptr)); + + if (factory) { + uassert(28662, str::stream() + << "Cannot start server. Detected data files in " << dbpath << " created by" + << " the '" << *existingStorageEngine << "' storage engine, but the" + << " specified storage engine was '" << factory->getCanonicalName() << "'.", + factory->getCanonicalName() == *existingStorageEngine); + } + } + else { + // Otherwise set the active storage engine as the contents of the metadata file. + log() << "Detected data files in " << dbpath << " created by the '" + << *existingStorageEngine << "' storage engine, so setting the active" + << " storage engine to '" << *existingStorageEngine << "'."; + storageGlobalParams.engine = *existingStorageEngine; + } + } + else if (!storageGlobalParams.engineSetByUser) { + // Ensure the default storage engine is available with this build of mongod. + uassert(28663, str::stream() + << "Cannot start server. The default storage engine '" << storageGlobalParams.engine + << "' is not available with this build of mongod. Please specify a different" + << " storage engine explicitly, e.g. --storageEngine=mmapv1.", + isRegisteredStorageEngine(storageGlobalParams.engine)); + } + + const StorageEngine::Factory* factory = _storageFactories[storageGlobalParams.engine]; uassert(18656, str::stream() - << "Cannot start server with an unknown storage engine: " << name, + << "Cannot start server with an unknown storage engine: " << storageGlobalParams.engine, factory); - std::string canonicalName = factory->getCanonicalName().toString(); - - // Do not proceed if data directory has been used by a different storage engine previously. - std::auto_ptr<StorageEngineMetadata> metadata = - StorageEngineMetadata::validate(storageGlobalParams.dbpath, canonicalName); + std::unique_ptr<StorageEngineMetadata> metadata = StorageEngineMetadata::forPath(dbpath); // Validate options in metadata against current startup options. if (metadata.get()) { @@ -116,7 +150,7 @@ namespace mongo { // Write a new metadata file if it is not present. if (!metadata.get()) { metadata.reset(new StorageEngineMetadata(storageGlobalParams.dbpath)); - metadata->setStorageEngine(canonicalName); + metadata->setStorageEngine(factory->getCanonicalName().toString()); metadata->setStorageEngineOptions(factory->createMetadataOptions(storageGlobalParams)); uassertStatusOK(metadata->write()); } |