diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2018-06-06 12:02:27 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2018-06-12 15:05:39 -0400 |
commit | 1cb34c79fe9e9fd84556a84fd622e5ebbe87f987 (patch) | |
tree | 74dc0ab9b2302928a6dd61b98f6ede134b64eb51 | |
parent | 0fd5d4eb2e61bbef14f6e55c8e5f9619e807260b (diff) | |
download | mongo-1cb34c79fe9e9fd84556a84fd622e5ebbe87f987.tar.gz |
SERVER-35421 Embedded options parsing can re-initialize.
(cherry picked from commit 06d98ac518613723d3e5aa80b6877941e164699f)
-rw-r--r-- | src/mongo/db/storage/storage_options.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_options.h | 26 | ||||
-rw-r--r-- | src/mongo/embedded/embedded_options.cpp | 4 | ||||
-rw-r--r-- | src/mongo/embedded/embedded_options.h | 2 | ||||
-rw-r--r-- | src/mongo/embedded/embedded_options_init.cpp | 59 | ||||
-rw-r--r-- | src/mongo/embedded/embedded_options_parser_init.cpp | 32 |
6 files changed, 94 insertions, 50 deletions
diff --git a/src/mongo/db/storage/storage_options.cpp b/src/mongo/db/storage/storage_options.cpp index de926e9b58a..dfbb7766562 100644 --- a/src/mongo/db/storage/storage_options.cpp +++ b/src/mongo/db/storage/storage_options.cpp @@ -36,6 +36,27 @@ namespace mongo { +StorageGlobalParams::StorageGlobalParams() { + reset(); +} + +void StorageGlobalParams::reset() { + engine = "wiredTiger"; + engineSetByUser = false; + dbpath = kDefaultDbPath; + upgrade = false; + repair = false; + + // The intention here is to enable the journal by default if we are running on a 64 bit system. + dur = (sizeof(void*) == 8); + + noTableScan.store(false); + directoryperdb = false; + syncdelay = 60.0; + readOnly = false; + groupCollections = false; +} + StorageGlobalParams storageGlobalParams; /** diff --git a/src/mongo/db/storage/storage_options.h b/src/mongo/db/storage/storage_options.h index ded45f1bfb6..57c58ea747a 100644 --- a/src/mongo/db/storage/storage_options.h +++ b/src/mongo/db/storage/storage_options.h @@ -44,6 +44,9 @@ namespace mongo { struct StorageGlobalParams { + StorageGlobalParams(); + void reset(); + // Default data directory for mongod when running in non-config server mode. static const char* kDefaultDbPath; @@ -53,23 +56,23 @@ struct StorageGlobalParams { // --storageEngine // storage engine for this instance of mongod. - std::string engine = "wiredTiger"; + std::string engine; // True if --storageEngine was passed on the command line, and false otherwise. - bool engineSetByUser = false; + bool engineSetByUser; // The directory where the mongod instance stores its data. - std::string dbpath = kDefaultDbPath; + std::string dbpath; // --upgrade // Upgrades the on-disk data format of the files specified by the --dbpath to the // latest version, if needed. - bool upgrade = false; + bool upgrade; // --repair // Runs a repair routine on all databases. This is equivalent to shutting down and // running the repairDatabase database command on all databases. - bool repair = false; + bool repair; // --repairpath // Specifies the root directory containing MongoDB data files to use for the --repair @@ -77,8 +80,7 @@ struct StorageGlobalParams { // Default: A _tmp directory within the path specified by the dbPath option. std::string repairpath; - // The intention here is to enable the journal by default if we are running on a 64 bit system. - bool dur = (sizeof(void*) == 8); // --dur durability (now --journal) + bool dur; // --dur durability (now --journal) // --journalCommitInterval static const int kMaxJournalCommitIntervalMs; @@ -86,13 +88,13 @@ struct StorageGlobalParams { // --notablescan // no table scans allowed - AtomicBool noTableScan{false}; + AtomicBool noTableScan; // --directoryperdb // Stores each database’s files in its own folder in the data directory. // When applied to an existing system, the directoryPerDB option alters // the storage pattern of the data directory. - bool directoryperdb = false; + bool directoryperdb; // --syncdelay // Controls how much time can pass before MongoDB flushes data to the data files @@ -100,19 +102,19 @@ struct StorageGlobalParams { // Do not set this value on production systems. // In almost every situation, you should use the default setting. static const double kMaxSyncdelaySecs; - AtomicDouble syncdelay{60.0}; // seconds between fsyncs + AtomicDouble syncdelay; // seconds between fsyncs // --queryableBackupMode // Puts MongoD into "read-only" mode. MongoD will not write any data to the underlying // filesystem. Note that read operations may require writes. For example, a sort on a large // dataset may fail if it requires spilling to disk. - bool readOnly = false; + bool readOnly; // --groupCollections // Dictate to the storage engine that it should attempt to create new MongoDB collections from // an existing underlying MongoDB database level resource if possible. This can improve // workloads that rely heavily on creating many collections within a database. - bool groupCollections = false; + bool groupCollections; }; extern StorageGlobalParams storageGlobalParams; diff --git a/src/mongo/embedded/embedded_options.cpp b/src/mongo/embedded/embedded_options.cpp index 949e31ce07b..524a751a5ee 100644 --- a/src/mongo/embedded/embedded_options.cpp +++ b/src/mongo/embedded/embedded_options.cpp @@ -151,5 +151,9 @@ Status storeOptions(const moe::Environment& params) { return Status::OK(); } +void resetOptions() { + storageGlobalParams.reset(); +} + } // namespace embedded } // namespace mongo diff --git a/src/mongo/embedded/embedded_options.h b/src/mongo/embedded/embedded_options.h index 126a4da6a25..4498dcd98ed 100644 --- a/src/mongo/embedded/embedded_options.h +++ b/src/mongo/embedded/embedded_options.h @@ -46,5 +46,7 @@ Status addOptions(optionenvironment::OptionSection* options); Status canonicalizeOptions(optionenvironment::Environment* params); Status storeOptions(const optionenvironment::Environment& params); +void resetOptions(); + } // namespace embedded } // namespace mongo diff --git a/src/mongo/embedded/embedded_options_init.cpp b/src/mongo/embedded/embedded_options_init.cpp index f9ffc50afde..e09c67e62d5 100644 --- a/src/mongo/embedded/embedded_options_init.cpp +++ b/src/mongo/embedded/embedded_options_init.cpp @@ -38,33 +38,40 @@ MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(EmbeddedOptions)(InitializerContext* cont return addOptions(&optionenvironment::startupOptions); } -MONGO_INITIALIZER_GENERAL(EmbeddedOptions, - ("BeginStartupOptionValidation", "AllFailPointsRegistered"), - ("EndStartupOptionValidation")) -(InitializerContext* context) { - // Run validation, but tell the Environment that we don't want it to be set as "valid", - // since we may be making it invalid in the canonicalization process. - Status ret = optionenvironment::startupOptionsParsed.validate(false); - if (!ret.isOK()) { - return ret; - } - ret = canonicalizeOptions(&optionenvironment::startupOptionsParsed); - if (!ret.isOK()) { - return ret; - } - ret = optionenvironment::startupOptionsParsed.validate(); - if (!ret.isOK()) { - return ret; - } - return Status::OK(); -} +GlobalInitializerRegisterer embeddedOptionsInitializer( + "EmbeddedOptions", + {"BeginStartupOptionValidation", "AllFailPointsRegistered"}, + {"EndStartupOptionValidation"}, + [](InitializerContext* context) { + // Run validation, but tell the Environment that we don't want it to be set as "valid", + // since we may be making it invalid in the canonicalization process. + Status ret = optionenvironment::startupOptionsParsed.validate(false); + if (!ret.isOK()) { + return ret; + } + ret = canonicalizeOptions(&optionenvironment::startupOptionsParsed); + if (!ret.isOK()) { + return ret; + } + ret = optionenvironment::startupOptionsParsed.validate(); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); + }, + [](DeinitializerContext* context) { return Status::OK(); }); -MONGO_INITIALIZER_GENERAL(EmbeddedOptions_Store, - ("BeginStartupOptionStorage"), - ("EndStartupOptionStorage")) -(InitializerContext* context) { - return storeOptions(optionenvironment::startupOptionsParsed); -} +GlobalInitializerRegisterer embeddedOptionsStore("EmbeddedOptions_Store", + {"BeginStartupOptionStorage"}, + {"EndStartupOptionStorage"}, + [](InitializerContext* context) { + return storeOptions( + optionenvironment::startupOptionsParsed); + }, + [](DeinitializerContext* context) { + resetOptions(); + return Status::OK(); + }); } // namespace embedded } // namespace mongo diff --git a/src/mongo/embedded/embedded_options_parser_init.cpp b/src/mongo/embedded/embedded_options_parser_init.cpp index 1416556828a..54ae228921e 100644 --- a/src/mongo/embedded/embedded_options_parser_init.cpp +++ b/src/mongo/embedded/embedded_options_parser_init.cpp @@ -40,18 +40,26 @@ namespace mongo { namespace optionenvironment { -MONGO_STARTUP_OPTIONS_PARSE(StartupOptions)(InitializerContext* context) { - // Embedded uses a YAML config passed in argv to reuse the existing interface, extract it from - // the first element otherwise use empty string. - std::string config = !context->args().empty() ? context->args()[0] : ""; - - OptionsParser parser; - Status ret = - parser.runConfigFile(startupOptions, config, context->env(), &startupOptionsParsed); - uassertStatusOKWithContext(ret, "Options parsing failed."); - - return Status::OK(); -} +GlobalInitializerRegisterer startupOptionsInitializer( + "StartupOptions", + {"BeginStartupOptionParsing"}, + {"EndStartupOptionParsing"}, + [](InitializerContext* context) { + // Embedded uses a YAML config passed in argv to reuse the existing interface, extract it + // from the first element otherwise use empty string. + std::string config = !context->args().empty() ? context->args()[0] : ""; + + OptionsParser parser; + Status ret = + parser.runConfigFile(startupOptions, config, context->env(), &startupOptionsParsed); + uassertStatusOKWithContext(ret, "Options parsing failed."); + + return Status::OK(); + }, + [](DeinitializerContext* context) { + startupOptionsParsed = Environment(); + return Status::OK(); + }); } // namespace optionenvironment } // namespace mongo |