diff options
author | Gabriel Russell <gabriel.russell@mongodb.com> | 2020-07-16 11:50:30 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-18 18:19:32 +0000 |
commit | 87c0656852be4f4ed6a14f08cd75a6000dc4ee74 (patch) | |
tree | 4706b5badd6dcb33f77715d4480bf822c01541d7 /src/mongo/embedded | |
parent | b58968562034c206cd041c083d1ac3cc5e749ec1 (diff) | |
download | mongo-87c0656852be4f4ed6a14f08cd75a6000dc4ee74.tar.gz |
SERVER-47922 move embedded config from argv[0] to a StaticImmortal
Diffstat (limited to 'src/mongo/embedded')
5 files changed, 68 insertions, 8 deletions
diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp index e7a4ef87453..8866654cefb 100644 --- a/src/mongo/embedded/embedded.cpp +++ b/src/mongo/embedded/embedded.cpp @@ -61,6 +61,7 @@ #include "mongo/db/storage/encryption_hooks.h" #include "mongo/db/storage/storage_engine_init.h" #include "mongo/db/ttl.h" +#include "mongo/embedded/embedded_options_parser_init.h" #include "mongo/embedded/index_builds_coordinator_embedded.h" #include "mongo/embedded/periodic_runner_embedded.h" #include "mongo/embedded/read_write_concern_defaults_cache_lookup_embedded.h" @@ -190,10 +191,10 @@ void shutdown(ServiceContext* srvContext) { ServiceContext* initialize(const char* yaml_config) { srand(static_cast<unsigned>(curTimeMicros64())); - std::vector<std::string> argv; if (yaml_config) - argv.push_back(yaml_config); - Status status = mongo::runGlobalInitializers(argv); + embedded::EmbeddedOptionsConfig::instance().set(yaml_config); + + Status status = mongo::runGlobalInitializers(std::vector<std::string>{}); uassertStatusOKWithContext(status, "Global initilization failed"); auto giGuard = makeGuard([] { mongo::runGlobalDeinitializers().ignore(); }); setGlobalServiceContext(ServiceContext::make()); diff --git a/src/mongo/embedded/embedded_options_parser_init.cpp b/src/mongo/embedded/embedded_options_parser_init.cpp index 1599668cf73..31a5593a3e0 100644 --- a/src/mongo/embedded/embedded_options_parser_init.cpp +++ b/src/mongo/embedded/embedded_options_parser_init.cpp @@ -31,6 +31,7 @@ #include <iostream> +#include "mongo/embedded/embedded_options_parser_init.h" #include "mongo/util/exit_code.h" #include "mongo/util/options_parser/option_description.h" #include "mongo/util/options_parser/option_section.h" @@ -44,9 +45,7 @@ namespace optionenvironment { GlobalInitializerRegisterer startupOptionsInitializer( "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] : ""; + std::string config = embedded::EmbeddedOptionsConfig::instance().get(); OptionsParser parser; Status ret = parser.runConfigFile(startupOptions, config, &startupOptionsParsed); diff --git a/src/mongo/embedded/embedded_options_parser_init.h b/src/mongo/embedded/embedded_options_parser_init.h new file mode 100644 index 00000000000..658aadc89da --- /dev/null +++ b/src/mongo/embedded/embedded_options_parser_init.h @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/embedded/embedded_options.h" + +#include "mongo/util/options_parser/startup_option_init.h" +#include "mongo/util/options_parser/startup_options.h" +#include "mongo/util/static_immortal.h" + +#include <string> +#include <utility> + +namespace mongo::embedded { + +class EmbeddedOptionsConfig { +public: + void set(std::string config) { + _config = std::move(config); + } + const std::string& get() const { + return _config; + } + static EmbeddedOptionsConfig& instance() { + static StaticImmortal<EmbeddedOptionsConfig> embeddedOptionsConfig{}; + return embeddedOptionsConfig.value(); + } + +private: + std::string _config; +}; + +} // namespace mongo::embedded diff --git a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp index 683c3edfb96..6ab5108ae51 100644 --- a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp +++ b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp @@ -697,7 +697,7 @@ int main(const int argc, const char* const* const argv) { // The reason this works is that the unittest system relies on other systems being initialized // through global init and deinitialize just deinitializes systems that explicitly supports // deinit leaving the systems unittest needs initialized. - ret = mongo::runGlobalInitializers(std::vector<std::string>{}); + ret = mongo::runGlobalInitializers(std::vector<std::string>{argv, argv + argc}); if (!ret.isOK()) { std::cerr << "Global initilization failed"; return EXIT_FAILURE; diff --git a/src/mongo/embedded/stitch_support/stitch_support_test.cpp b/src/mongo/embedded/stitch_support/stitch_support_test.cpp index 75db9287db1..d8984f43367 100644 --- a/src/mongo/embedded/stitch_support/stitch_support_test.cpp +++ b/src/mongo/embedded/stitch_support/stitch_support_test.cpp @@ -635,7 +635,7 @@ TEST_F(StitchSupportTest, TestUpsertProducesProperStatus) { // the Stitch Support Library intializer function that gets tested here. int main(const int argc, const char* const* const argv) { // See comment by the same code block in mongo_embedded_test.cpp - auto ret = mongo::runGlobalInitializers(std::vector<std::string>{}); + auto ret = mongo::runGlobalInitializers(std::vector<std::string>{argv, argv + argc}); if (!ret.isOK()) { std::cerr << "Global initilization failed"; return EXIT_FAILURE; |