summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildscripts/idl/idl/generator.py30
-rw-r--r--src/mongo/SConscript4
-rw-r--r--src/mongo/base/SConscript2
-rw-r--r--src/mongo/base/deinitializer_context.h50
-rw-r--r--src/mongo/base/dependency_graph.cpp (renamed from src/mongo/base/initializer_dependency_graph.cpp)119
-rw-r--r--src/mongo/base/dependency_graph.h99
-rw-r--r--src/mongo/base/dependency_graph_test.cpp279
-rw-r--r--src/mongo/base/error_extra_info.h10
-rw-r--r--src/mongo/base/global_initializer.cpp51
-rw-r--r--src/mongo/base/global_initializer.h43
-rw-r--r--src/mongo/base/global_initializer_registerer.cpp68
-rw-r--r--src/mongo/base/global_initializer_registerer.h100
-rw-r--r--src/mongo/base/init.cpp32
-rw-r--r--src/mongo/base/init.h141
-rw-r--r--src/mongo/base/initializer.cpp217
-rw-r--r--src/mongo/base/initializer.h113
-rw-r--r--src/mongo/base/initializer_context.h56
-rw-r--r--src/mongo/base/initializer_dependency_graph.h167
-rw-r--r--src/mongo/base/initializer_dependency_graph_test.cpp405
-rw-r--r--src/mongo/base/initializer_function.h58
-rw-r--r--src/mongo/base/initializer_test.cpp601
-rw-r--r--src/mongo/base/secure_allocator.cpp4
-rw-r--r--src/mongo/base/validate_locale.cpp14
-rw-r--r--src/mongo/bson/oid.cpp3
-rw-r--r--src/mongo/client/connpool.cpp1
-rw-r--r--src/mongo/client/cyrus_sasl_client_session.cpp8
-rw-r--r--src/mongo/client/dbclient_rs_test.cpp1
-rw-r--r--src/mongo/client/global_conn_pool.cpp2
-rw-r--r--src/mongo/client/native_sasl_client_session.cpp1
-rw-r--r--src/mongo/client/sasl_client_authenticate_impl.cpp1
-rw-r--r--src/mongo/client/sasl_sspi.cpp16
-rw-r--r--src/mongo/client/sasl_sspi_options.cpp2
-rw-r--r--src/mongo/crypto/symmetric_crypto.cpp4
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp4
-rw-r--r--src/mongo/db/auth/builtin_roles.cpp2
-rw-r--r--src/mongo/db/auth/sasl_commands.cpp2
-rw-r--r--src/mongo/db/auth/sasl_options.cpp1
-rw-r--r--src/mongo/db/auth/sasl_options_init.cpp4
-rw-r--r--src/mongo/db/commands.h24
-rw-r--r--src/mongo/db/commands/fsync.cpp1
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp4
-rw-r--r--src/mongo/db/commands/isself.cpp1
-rw-r--r--src/mongo/db/commands/oplog_note.cpp1
-rw-r--r--src/mongo/db/commands/test_commands.cpp1
-rw-r--r--src/mongo/db/commands/top_command.cpp2
-rw-r--r--src/mongo/db/exec/sbe/stages/exchange.cpp2
-rw-r--r--src/mongo/db/free_mon/free_mon_controller_test.cpp1
-rw-r--r--src/mongo/db/free_mon/free_mon_options.cpp5
-rw-r--r--src/mongo/db/ftdc/ftdc_commands.cpp2
-rw-r--r--src/mongo/db/fts/fts_index_format.cpp1
-rw-r--r--src/mongo/db/fts/stop_words.cpp1
-rw-r--r--src/mongo/db/geo/r2_region_coverer_test.cpp1
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp35
-rw-r--r--src/mongo/db/logical_time_validator.cpp1
-rw-r--r--src/mongo/db/matcher/expression_parser.cpp2
-rw-r--r--src/mongo/db/mongod_main.cpp5
-rw-r--r--src/mongo/db/mongod_options.cpp1
-rw-r--r--src/mongo/db/mongod_options_init.cpp24
-rw-r--r--src/mongo/db/pipeline/accumulation_statement.h2
-rw-r--r--src/mongo/db/pipeline/document_source.h4
-rw-r--r--src/mongo/db/pipeline/expression.cpp1
-rw-r--r--src/mongo/db/pipeline/expression.h3
-rw-r--r--src/mongo/db/pipeline/granularity_rounder.h1
-rw-r--r--src/mongo/db/profile_filter_impl.cpp1
-rw-r--r--src/mongo/db/query/collation/collator_factory_icu_decoration.cpp3
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_impl.cpp5
-rw-r--r--src/mongo/db/repl/isself.cpp1
-rw-r--r--src/mongo/db/s/balancer/core_options_stub.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_control_balancer_command.cpp2
-rw-r--r--src/mongo/db/server_options_init.cpp2
-rw-r--r--src/mongo/db/server_options_test.cpp1
-rw-r--r--src/mongo/db/service_context.cpp24
-rw-r--r--src/mongo/db/service_context.h1
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_kv_engine_test.cpp1
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp3
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit_test.cpp1
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_sorted_impl_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp1
-rw-r--r--src/mongo/db/system_index.cpp2
-rw-r--r--src/mongo/db/traffic_recorder.cpp10
-rw-r--r--src/mongo/db/update/modifier_table.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp1
-rw-r--r--src/mongo/dbtests/framework_options_init.cpp15
-rw-r--r--src/mongo/dbtests/mock/mock_conn_registry.cpp2
-rw-r--r--src/mongo/embedded/embedded.cpp7
-rw-r--r--src/mongo/embedded/embedded_options_init.cpp2
-rw-r--r--src/mongo/executor/network_interface_thread_pool_test.cpp1
-rw-r--r--src/mongo/executor/thread_pool_task_executor_test.cpp1
-rw-r--r--src/mongo/idl/config_option_test.cpp2
-rw-r--r--src/mongo/idl/server_parameter.cpp4
-rw-r--r--src/mongo/logv2/console.cpp1
-rw-r--r--src/mongo/logv2/log_manager.cpp1
-rw-r--r--src/mongo/logv2/ramlog.cpp7
-rw-r--r--src/mongo/platform/mutex.cpp2
-rw-r--r--src/mongo/platform/posix_fadvise.cpp3
-rw-r--r--src/mongo/platform/strcasestr.cpp3
-rw-r--r--src/mongo/s/chunk_manager_refresh_bm.cpp2
-rw-r--r--src/mongo/s/commands/cluster_command_test_fixture.cpp4
-rw-r--r--src/mongo/s/commands/cluster_control_balancer_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_ftdc_commands.cpp2
-rw-r--r--src/mongo/s/mongos_main.cpp6
-rw-r--r--src/mongo/s/mongos_options_init.cpp42
-rw-r--r--src/mongo/s/mongos_topology_coordinator.cpp1
-rw-r--r--src/mongo/shell/encrypted_dbclient_base.cpp1
-rw-r--r--src/mongo/shell/kms_aws.cpp1
-rw-r--r--src/mongo/shell/kms_local.cpp1
-rw-r--r--src/mongo/shell/kms_shell.cpp1
-rw-r--r--src/mongo/shell/mongo_main.cpp2
-rw-r--r--src/mongo/shell/mongodbcr.cpp1
-rw-r--r--src/mongo/shell/shell_options_init.cpp8
-rw-r--r--src/mongo/tools/bridge_commands.cpp1
-rw-r--r--src/mongo/tools/mongobridge_options_init.cpp8
-rw-r--r--src/mongo/transport/message_compressor_registry.cpp3
-rw-r--r--src/mongo/transport/message_compressor_snappy.cpp1
-rw-r--r--src/mongo/transport/message_compressor_zlib.cpp1
-rw-r--r--src/mongo/transport/message_compressor_zstd.cpp1
-rw-r--r--src/mongo/unittest/integration_test_main.cpp31
-rw-r--r--src/mongo/unittest/temp_dir.cpp13
-rw-r--r--src/mongo/unittest/unittest_main.cpp1
-rw-r--r--src/mongo/util/cmdline_utils/censor_cmdline.cpp16
-rw-r--r--src/mongo/util/concurrency/thread_pool_test.cpp1
-rw-r--r--src/mongo/util/diagnostic_info.cpp4
-rw-r--r--src/mongo/util/fail_point.cpp1
-rwxr-xr-xsrc/mongo/util/generate_icu_init_cpp.py3
-rw-r--r--src/mongo/util/heap_profiler.cpp1
-rw-r--r--src/mongo/util/icu_init_stub.cpp4
-rw-r--r--src/mongo/util/latch_analyzer.cpp2
-rw-r--r--src/mongo/util/net/openssl_init.cpp2
-rw-r--r--src/mongo/util/net/ssl/detail/impl/schannel.ipp2
-rw-r--r--src/mongo/util/net/ssl_manager.cpp2
-rw-r--r--src/mongo/util/net/ssl_manager_apple.cpp2
-rw-r--r--src/mongo/util/net/ssl_manager_none.cpp8
-rw-r--r--src/mongo/util/net/ssl_manager_openssl.cpp1
-rw-r--r--src/mongo/util/net/ssl_manager_windows.cpp1
-rw-r--r--src/mongo/util/net/ssl_options_client.cpp16
-rw-r--r--src/mongo/util/net/ssl_options_server.cpp72
-rw-r--r--src/mongo/util/net/ssl_options_test.cpp30
-rw-r--r--src/mongo/util/options_parser/options_parser.cpp5
-rw-r--r--src/mongo/util/options_parser/options_parser_init.cpp8
-rw-r--r--src/mongo/util/options_parser/startup_option_init.cpp8
-rw-r--r--src/mongo/util/perfctr_collect.cpp8
-rw-r--r--src/mongo/util/platform_init.cpp2
-rw-r--r--src/mongo/util/processinfo.cpp1
-rw-r--r--src/mongo/util/stacktrace_somap.cpp1
-rw-r--r--src/mongo/util/stacktrace_windows.cpp3
-rw-r--r--src/mongo/util/system_tick_source.cpp1
-rw-r--r--src/mongo/util/tcmalloc_set_parameter.cpp8
-rw-r--r--src/mongo/util/testing_options.cpp2
-rw-r--r--src/mongo/util/testing_proctor.cpp1
-rw-r--r--src/mongo/util/thread_context.cpp1
-rw-r--r--src/mongo/util/time_support_test.cpp3
-rw-r--r--src/mongo/util/version_impl.cpp5
158 files changed, 1239 insertions, 2084 deletions
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py
index 2cf21c71d6b..40a84b7ee1f 100644
--- a/buildscripts/idl/idl/generator.py
+++ b/buildscripts/idl/idl/generator.py
@@ -2215,8 +2215,6 @@ class _CppSourceFileWriter(_CppFileWriterBase):
self._gen_server_parameter_deprecated_aliases(param_no, param)
self.write_empty_line()
- self._writer.write_line('return Status::OK();')
-
def gen_config_option(self, opt, section):
# type: (ast.ConfigOption, str) -> None
"""Generate Config Option instance."""
@@ -2288,7 +2286,7 @@ class _CppSourceFileWriter(_CppFileWriterBase):
self.write_empty_line()
- def _gen_config_options_register(self, root_opts, sections):
+ def _gen_config_options_register(self, root_opts, sections, returns_status):
self._writer.write_line('namespace moe = ::mongo::optionenvironment;')
self.write_empty_line()
@@ -2304,13 +2302,18 @@ class _CppSourceFileWriter(_CppFileWriterBase):
self.gen_config_option(opt, 'section')
self._writer.write_line('auto status = options.addSection(section);')
- with self._block('if (!status.isOK()) {', '}'):
- self._writer.write_line('return status;')
- self.write_empty_line()
- self._writer.write_line('return Status::OK();')
+ if returns_status:
+ with self._block('if (!status.isOK()) {', '}'):
+ self._writer.write_line('return status;')
+ else:
+ self._writer.write_line('uassertStatusOK(status);')
+
+ self.write_empty_line()
+ if returns_status:
+ self._writer.write_line('return Status::OK();')
- def _gen_config_options_store(self, configs):
+ def _gen_config_options_store(self, configs, return_status):
# Setup initializer for storing configured options in their variables.
self._writer.write_line('namespace moe = ::mongo::optionenvironment;')
self.write_empty_line()
@@ -2327,7 +2330,8 @@ class _CppSourceFileWriter(_CppFileWriterBase):
'%s = params[%s].as<%s>();' % (opt.cpp_varname, _encaps(opt.name), vartype))
self.write_empty_line()
- self._writer.write_line('return Status::OK();')
+ if return_status:
+ self._writer.write_line('return Status::OK();')
def gen_config_options(self, spec, header_file_name):
# type: (ast.IDLAST, str) -> None
@@ -2369,14 +2373,14 @@ class _CppSourceFileWriter(_CppFileWriterBase):
'Status %s(optionenvironment::OptionSection* options_ptr) {' %
initializer.register, '}'):
self._writer.write_line('auto& options = *options_ptr;')
- self._gen_config_options_register(root_opts, sections)
+ self._gen_config_options_register(root_opts, sections, True)
else:
with self.gen_namespace_block(''):
with self._block(
'MONGO_MODULE_STARTUP_OPTIONS_REGISTER(%s)(InitializerContext*) {' %
(blockname), '}'):
self._writer.write_line('auto& options = optionenvironment::startupOptions;')
- self._gen_config_options_register(root_opts, sections)
+ self._gen_config_options_register(root_opts, sections, False)
self.write_empty_line()
@@ -2385,7 +2389,7 @@ class _CppSourceFileWriter(_CppFileWriterBase):
with self._block(
'Status %s(const optionenvironment::Environment& params) {' %
initializer.store, '}'):
- self._gen_config_options_store(spec.configs)
+ self._gen_config_options_store(spec.configs, True)
else:
with self.gen_namespace_block(''):
with self._block(
@@ -2395,7 +2399,7 @@ class _CppSourceFileWriter(_CppFileWriterBase):
self._writer.write_line(
'MONGO_COMPILER_VARIABLE_UNUSED const auto& params = optionenvironment::startupOptionsParsed;'
)
- self._gen_config_options_store(spec.configs)
+ self._gen_config_options_store(spec.configs, False)
self.write_empty_line()
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 6f1548ddc31..df43a86dd71 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -157,13 +157,11 @@ baseEnv.Library(
'base/data_type.cpp',
'base/data_type_string_data.cpp',
'base/data_type_terminated.cpp',
+ 'base/dependency_graph.cpp',
'base/error_codes.cpp',
'base/error_extra_info.cpp',
- 'base/global_initializer.cpp',
- 'base/global_initializer_registerer.cpp',
'base/init.cpp',
'base/initializer.cpp',
- 'base/initializer_dependency_graph.cpp',
'base/parse_number.cpp',
'base/shim.cpp',
'base/simple_string_data_comparator.cpp',
diff --git a/src/mongo/base/SConscript b/src/mongo/base/SConscript
index 643a5c1d839..7909ef0c396 100644
--- a/src/mongo/base/SConscript
+++ b/src/mongo/base/SConscript
@@ -83,8 +83,8 @@ env.CppUnitTest(
'data_type_terminated_test.cpp',
'data_type_validated_test.cpp',
'data_view_test.cpp',
+ 'dependency_graph_test.cpp',
'encoded_value_storage_test.cpp',
- 'initializer_dependency_graph_test.cpp',
'initializer_test.cpp',
'murmurhash3_test.cpp',
'owned_pointer_map_test.cpp',
diff --git a/src/mongo/base/deinitializer_context.h b/src/mongo/base/deinitializer_context.h
deleted file mode 100644
index 370b5c5526d..00000000000
--- a/src/mongo/base/deinitializer_context.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Copyright (C) 2018-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/db/service_context_fwd.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace mongo {
-/**
- * Context of a deinitialization process. Passed as a parameter to deinitialization functions.
- *
- * See mongo/base/initializer.h and mongo/base/initializer_dependency_graph.h for more details.
- */
-class DeinitializerContext {
-public:
- DeinitializerContext(DeinitializerContext const&) = delete;
- DeinitializerContext& operator=(DeinitializerContext const&) = delete;
-};
-
-} // namespace mongo
diff --git a/src/mongo/base/initializer_dependency_graph.cpp b/src/mongo/base/dependency_graph.cpp
index 24239cb4057..8d9107b5a10 100644
--- a/src/mongo/base/initializer_dependency_graph.cpp
+++ b/src/mongo/base/dependency_graph.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-present MongoDB, Inc.
+ * 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,
@@ -27,10 +27,11 @@
* it in the license file.
*/
-#include "mongo/base/initializer_dependency_graph.h"
+#include "mongo/base/dependency_graph.h"
#include <algorithm>
#include <fmt/format.h>
+#include <fmt/ranges.h>
#include <iostream>
#include <iterator>
#include <random>
@@ -41,50 +42,27 @@
namespace mongo {
-using namespace fmt::literals;
-
-InitializerDependencyGraph::InitializerDependencyGraph() {}
-InitializerDependencyGraph::~InitializerDependencyGraph() {}
-
-Status InitializerDependencyGraph::addInitializer(std::string name,
- InitializerFunction initFn,
- DeinitializerFunction deinitFn,
- std::vector<std::string> prerequisites,
- std::vector<std::string> dependents) {
- if (!initFn)
- return Status(ErrorCodes::BadValue, "Illegal to supply a NULL function");
-
- invariant(!frozen());
-
- InitializerDependencyNode& newNode = _nodes[name];
- if (newNode.initFn) {
- return Status(ErrorCodes::Error(50999), name);
- }
-
- newNode.initFn = std::move(initFn);
- newNode.deinitFn = std::move(deinitFn);
-
- for (size_t i = 0; i < prerequisites.size(); ++i) {
- newNode.prerequisites.insert(prerequisites[i]);
- }
-
- for (size_t i = 0; i < dependents.size(); ++i) {
- _nodes[dependents[i]].prerequisites.insert(name);
+void DependencyGraph::addNode(std::string name,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents,
+ std::unique_ptr<Payload> payload) {
+ if (!payload) {
+ struct DummyPayload : Payload {};
+ payload = std::make_unique<DummyPayload>();
}
-
- return Status::OK();
-}
-
-InitializerDependencyNode* InitializerDependencyGraph::getInitializerNode(const std::string& name) {
- NodeMap::iterator iter = _nodes.find(name);
- if (iter == _nodes.end())
- return nullptr;
-
- return &iter->second;
+ auto& newNode = _nodes[name];
+ uassert(ErrorCodes::Error(50999), name, !newNode.payload); // collision
+ for (auto& otherNode : prerequisites)
+ newNode.prerequisites.insert(otherNode);
+ for (auto& otherNode : dependents)
+ _nodes[otherNode].prerequisites.insert(name);
+ newNode.payload = std::move(payload);
}
namespace {
+using namespace fmt::literals;
+
template <typename Seq>
void strAppendJoin(std::string& out, StringData separator, const Seq& sequence) {
StringData currSep;
@@ -95,26 +73,28 @@ void strAppendJoin(std::string& out, StringData separator, const Seq& sequence)
}
}
-// In the case of a cycle, copy the cycle into `names`.
-// It's undocumented behavior, but it's cheap and a test wants it.
+// In the case of a cycle, copy the cycle node names into `*cycle`.
template <typename Iter>
-void throwGraphContainsCycle(Iter first, Iter last, std::vector<std::string>& names) {
- std::string desc = "Cycle in dependency graph: ";
+void throwGraphContainsCycle(Iter first, Iter last, std::vector<std::string>* cycle) {
+ std::vector<std::string> names;
std::transform(first, last, std::back_inserter(names), [](auto& e) { return e->name(); });
- names.push_back((*first)->name()); // Tests awkwardly want first element to be repeated.
- strAppendJoin(desc, " -> ", names);
- uasserted(ErrorCodes::GraphContainsCycle, desc);
+ if (cycle)
+ *cycle = names;
+ names.push_back((*first)->name());
+ uasserted(ErrorCodes::GraphContainsCycle,
+ format(FMT_STRING("Cycle in dependency graph: {}"), fmt::join(names, " -> ")));
}
+
} // namespace
-Status InitializerDependencyGraph::topSort(std::vector<std::string>* sortedNames) const try {
+std::vector<std::string> DependencyGraph::topSort(std::vector<std::string>* cycle) const {
// Topological sort via repeated depth-first traversal.
// All nodes must have an initFn before running topSort, or we return BadValue.
struct Element {
const std::string& name() const {
- return node->first;
+ return nodeIter->first;
}
- const Node* node;
+ stdx::unordered_map<std::string, Node>::const_iterator nodeIter;
std::vector<Element*> children;
std::vector<Element*>::iterator membership; // Position of this in `elements`.
};
@@ -131,13 +111,12 @@ Status InitializerDependencyGraph::topSort(std::vector<std::string>* sortedNames
};
elementsStore.reserve(_nodes.size());
- std::transform(
- _nodes.begin(), _nodes.end(), std::back_inserter(elementsStore), [](const Node& n) {
- uassert(ErrorCodes::BadValue,
- "No implementation provided for initializer {}"_format(n.first),
- n.second.initFn);
- return Element{&n};
- });
+ for (auto iter = _nodes.begin(); iter != _nodes.end(); ++iter) {
+ uassert(ErrorCodes::BadValue,
+ "node {} was mentioned but never added"_format(iter->first),
+ iter->second.payload);
+ elementsStore.push_back(Element{iter});
+ }
// Wire up all the child relationships by pointer rather than by string names.
{
@@ -145,15 +124,15 @@ Status InitializerDependencyGraph::topSort(std::vector<std::string>* sortedNames
for (Element& e : elementsStore)
byName[e.name()] = &e;
for (Element& element : elementsStore) {
- const auto& prereqs = element.node->second.prerequisites;
+ const auto& prereqs = element.nodeIter->second.prerequisites;
std::transform(prereqs.begin(),
prereqs.end(),
std::back_inserter(element.children),
[&](StringData childName) {
auto iter = byName.find(childName);
uassert(ErrorCodes::BadValue,
- "Initializer {} depends on missing initializer {}"_format(
- element.node->first, childName),
+ "node {} depends on missing node {}"_format(
+ element.nodeIter->first, childName),
iter != byName.end());
return iter->second;
});
@@ -203,23 +182,25 @@ Status InitializerDependencyGraph::topSort(std::vector<std::string>* sortedNames
if (picked->membership < unsortedBegin)
continue;
if (picked->membership >= unsortedEnd) { // O(1) cycle detection
- sortedNames->clear();
- throwGraphContainsCycle(unsortedEnd, elements.end(), *sortedNames);
+ throwGraphContainsCycle(unsortedEnd, elements.end(), cycle);
}
swapPositions(**--unsortedEnd, *picked); // unsorted push to stack
continue;
}
swapPositions(**unsortedEnd++, **unsortedBegin++); // pop from stack to sorted
}
- sortedNames->clear();
- sortedNames->reserve(_nodes.size());
+ std::vector<std::string> sortedNames;
+ sortedNames.reserve(_nodes.size());
std::transform(elements.begin(),
elements.end(),
- std::back_inserter(*sortedNames),
+ std::back_inserter(sortedNames),
[](const Element* e) { return e->name(); });
- return Status::OK();
-} catch (const DBException& ex) {
- return ex.toStatus();
+ return sortedNames;
+}
+
+DependencyGraph::Payload* DependencyGraph::find(const std::string& name) {
+ auto iter = _nodes.find(name);
+ return (iter == _nodes.end()) ? nullptr : iter->second.payload.get();
}
} // namespace mongo
diff --git a/src/mongo/base/dependency_graph.h b/src/mongo/base/dependency_graph.h
new file mode 100644
index 00000000000..e734dc17f9a
--- /dev/null
+++ b/src/mongo/base/dependency_graph.h
@@ -0,0 +1,99 @@
+/**
+ * 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 <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "mongo/base/status.h"
+#include "mongo/stdx/unordered_map.h"
+#include "mongo/stdx/unordered_set.h"
+
+namespace mongo {
+
+/**
+ * To separate concerns, this just captures the setup and execution of a
+ * topological sort without regard to higher-level semantics like process
+ * initialization. Each node is mapped to an abstract Data payload.
+ */
+class DependencyGraph {
+public:
+ class Payload {
+ public:
+ virtual ~Payload() = default;
+ };
+
+ /**
+ * Add a new initializer node, named `name`, to the dependency graph,
+ * having the given `prerequisites` and `dependents`, which are the names
+ * of other nodes which will be in the graph when `topSort` is called.
+ *
+ * The new node can be mapped to an abstract `payload`, which can
+ * be retrieved with `find`.
+ *
+ * Note that cycles in the dependency graph are not discovered by this function.
+ * Rather, they're discovered by `topSort`, below.
+ */
+ void addNode(std::string name,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents,
+ std::unique_ptr<Payload> payload = nullptr);
+
+ /**
+ * Returns a topological sort of the dependency graph, represented
+ * as an ordered vector of node names.
+ *
+ * Throws with `ErrorCodes::GraphContainsCycle` if the graph contains a cycle.
+ * If a `cycle` is given, it will be overwritten with the node sequence involved.
+ *
+ * Throws with `ErrorCodes::BadValue` if any node in the graph names a
+ * prerequisite that is missing from the graph.
+ */
+ std::vector<std::string> topSort(std::vector<std::string>* cycle = nullptr) const;
+
+ Payload* find(const std::string& name);
+
+private:
+ struct Node {
+ stdx::unordered_set<std::string> prerequisites;
+ std::unique_ptr<Payload> payload;
+ };
+
+ /**
+ * Map of all named nodes. Nodes named as prerequisites or dependents but not explicitly
+ * added via addInitializer will either be absent from this map or be present with
+ * NodeData::fn set to a false-ish value.
+ */
+ stdx::unordered_map<std::string, Node> _nodes;
+};
+
+} // namespace mongo
diff --git a/src/mongo/base/dependency_graph_test.cpp b/src/mongo/base/dependency_graph_test.cpp
new file mode 100644
index 00000000000..b79533bc081
--- /dev/null
+++ b/src/mongo/base/dependency_graph_test.cpp
@@ -0,0 +1,279 @@
+/**
+ * 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.
+ */
+
+/**
+ * Unit tests of the DependencyGraph type.
+ */
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include <fmt/ranges.h>
+
+#include "mongo/base/dependency_graph.h"
+#include "mongo/base/init.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+namespace {
+
+template <typename C, typename T>
+size_t count(const C& c, const T& value) {
+ return std::count(c.begin(), c.end(), value);
+}
+
+TEST(DependencyGraphTest, InsertNullPayloadOkay) {
+ DependencyGraph graph;
+ graph.addNode("A", {}, {});
+}
+
+TEST(DependencyGraphTest, InsertSameNameTwiceFails) {
+ DependencyGraph graph;
+ graph.addNode("A", {}, {});
+ ASSERT_THROWS_CODE(graph.addNode("A", {}, {}), DBException, 50999);
+}
+
+TEST(DependencyGraphTest, TopSortEmptyGraph) {
+ DependencyGraph graph;
+ std::vector<std::string> nodeNames = graph.topSort();
+ ASSERT_EQUALS(nodeNames.size(), 0u);
+}
+
+TEST(DependencyGraphTest, TopSortGraphNoDeps) {
+ DependencyGraph graph;
+ graph.addNode("A", {}, {});
+ graph.addNode("B", {}, {});
+ graph.addNode("C", {}, {});
+ auto nodeNames = graph.topSort();
+ ASSERT_EQ(nodeNames.size(), 3);
+ ASSERT_EQ(count(nodeNames, "A"), 1);
+ ASSERT_EQ(count(nodeNames, "B"), 1);
+ ASSERT_EQ(count(nodeNames, "C"), 1);
+}
+
+/**
+ * Verify a node order for the diamond topology used in several tests.
+ * Specifically, this graph:
+ *
+ * A
+ * |
+ * +->B
+ * | |
+ * +---->C
+ * | |
+ * +--+->D
+ *
+ * `B` and `C` have no order relative to each other, but both must
+ * happen after `A` and before `D`.
+ */
+void checkDiamondTopology(const std::vector<std::string>& nodeNames) {
+ ASSERT_STRING_SEARCH_REGEX(
+ fmt::format("{}", fmt::join(nodeNames.begin(), nodeNames.end(), " ")), "^A (B C|C B) D$");
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondPrerequisites) {
+ /*
+ * Top-sorting a simple diamond specified using prerequisites.
+ * See checkDiamondTopology for topology.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {});
+ graph.addNode("B", {"A"}, {});
+ graph.addNode("C", {"A"}, {});
+ graph.addNode("D", {"B", "C"}, {});
+ checkDiamondTopology(graph.topSort());
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondDependents) {
+ /*
+ * Same diamond topology as preceding test, but specified using dependents.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {"B", "C"});
+ graph.addNode("B", {}, {"D"});
+ graph.addNode("C", {}, {"D"});
+ graph.addNode("D", {}, {});
+ checkDiamondTopology(graph.topSort());
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondGeneral1) {
+ /*
+ * Same diamond topology, specified completely by prerequisites and
+ * dependents declared on B and C.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {});
+ graph.addNode("B", {"A"}, {"D"});
+ graph.addNode("C", {"A"}, {"D"});
+ graph.addNode("D", {}, {});
+ checkDiamondTopology(graph.topSort());
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondGeneral2) {
+ /*
+ * Same diamond topology, specified completely by prerequisites and
+ * dependents declared on A and D.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {"B", "C"});
+ graph.addNode("B", {}, {});
+ graph.addNode("C", {}, {});
+ graph.addNode("D", {"C", "B"}, {});
+ checkDiamondTopology(graph.topSort());
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondGeneral3) {
+ /*
+ * Same diamond topology, specified by redundant but coherent constraints.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {"B", "C"});
+ graph.addNode("B", {"A"}, {"D"});
+ graph.addNode("C", {"A"}, {"D"});
+ graph.addNode("D", {"C", "B"}, {});
+ checkDiamondTopology(graph.topSort());
+}
+
+TEST(DependencyGraphTest, TopSortWithDiamondAndCycle) {
+ /*
+ * Cyclic graph. Should fail.
+ *
+ * A
+ * |
+ * +->B<-------+
+ * | | |
+ * +---->C |
+ * | | |
+ * +--+->D |
+ * | |
+ * +->E
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {"B", "C"});
+ graph.addNode("B", {}, {});
+ graph.addNode("C", {}, {});
+ graph.addNode("D", {"C", "B"}, {});
+ graph.addNode("E", {"D"}, {"B"});
+
+ std::vector<std::string> cycle;
+ auto check = [](auto&& ex) {
+ ASSERT_EQ(ex.code(), ErrorCodes::GraphContainsCycle) << ex.toString();
+ };
+ ASSERT_THROWS_WITH_CHECK(graph.topSort(&cycle), DBException, check);
+ ASSERT_EQ(cycle.size(), 3);
+ ASSERT_EQ(count(cycle, "B"), 1);
+ ASSERT_EQ(count(cycle, "D"), 1);
+ ASSERT_EQ(count(cycle, "E"), 1);
+}
+
+TEST(DependencyGraphTest, TopSortFailsWhenMissingPrerequisite) {
+ /*
+ * If a node names a never-declared prerequisite, topSort should fail.
+ */
+ DependencyGraph graph;
+ graph.addNode("B", {"A"}, {});
+ auto check = [&](const DBException& ex) {
+ ASSERT_EQ(ex.code(), ErrorCodes::BadValue) << ex.toString();
+ ASSERT_STRING_CONTAINS(ex.reason(), "node B depends on missing node A");
+ };
+ ASSERT_THROWS_WITH_CHECK(graph.topSort(), DBException, check);
+}
+
+TEST(DependencyGraphTest, TopSortFailsWhenMissingDependent) {
+ /*
+ * If a node names a never-declared dependent, topSort should fail.
+ */
+ DependencyGraph graph;
+ graph.addNode("A", {}, {"B"});
+ auto check = [](const DBException& ex) {
+ ASSERT_EQ(ex.code(), ErrorCodes::BadValue) << ex.toString();
+ ASSERT_STRING_CONTAINS(ex.reason(), "node B was mentioned but never added");
+ };
+ ASSERT_THROWS_WITH_CHECK(graph.topSort(), DBException, check);
+}
+
+std::vector<std::vector<std::string>> allPermutations(std::vector<std::string> vec,
+ size_t first,
+ size_t last) {
+ std::vector<std::vector<std::string>> out;
+ auto i1 = vec.begin() + first;
+ auto i2 = vec.begin() + last;
+ std::sort(i1, i2);
+ do {
+ out.push_back(vec);
+ } while (std::next_permutation(i1, i2));
+ return out;
+}
+
+template <typename Expectations, typename F>
+void doUntilAllSeen(const Expectations& expected, F&& f) {
+ std::vector<int> seen(expected.size(), 0);
+ while (std::find(seen.begin(), seen.end(), 0) != seen.end()) {
+ auto found = std::find(expected.begin(), expected.end(), f());
+ ASSERT_TRUE(found != expected.end());
+ ++seen[found - expected.begin()];
+ }
+}
+
+TEST(DependencyGraphTest, TopSortShufflesNodes) {
+ /*
+ * Make sure all node orderings can appear as outputs.
+ */
+ DependencyGraph graph;
+ std::vector<std::string> graphNodes;
+ for (int i = 0; i < 5; ++i) {
+ std::string s = "Node" + std::to_string(i);
+ graphNodes.push_back(s);
+ graph.addNode(s, {}, {});
+ }
+ doUntilAllSeen(allPermutations(graphNodes, 0, graphNodes.size()),
+ [&] { return graph.topSort(); });
+}
+
+TEST(DependencyGraphTest, TopSortShufflesChildren) {
+ /*
+ * Make sure all child orderings can appear as outputs.
+ */
+ DependencyGraph graph;
+ std::vector<std::string> graphNodes;
+ graphNodes.push_back("Parent");
+ graph.addNode("Parent", {}, {});
+ for (int i = 0; i < 5; ++i) {
+ std::string s = "Child" + std::to_string(i);
+ graphNodes.push_back(s);
+ graph.addNode(s, {"Parent"}, {});
+ }
+ // Permute only the children.
+ doUntilAllSeen(allPermutations(graphNodes, 1, graphNodes.size()),
+ [&] { return graph.topSort(); });
+}
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/base/error_extra_info.h b/src/mongo/base/error_extra_info.h
index 9b64de8427d..c8a05f184ef 100644
--- a/src/mongo/base/error_extra_info.h
+++ b/src/mongo/base/error_extra_info.h
@@ -100,12 +100,10 @@ private:
* You must separately #include "mongo/base/init.h" since including it here would create an include
* cycle.
*/
-#define MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(type) \
- MONGO_INITIALIZER_GENERAL( \
- RegisterErrorExtraInfoFor##type, MONGO_NO_PREREQUISITES, ("default")) \
- (InitializerContext * context) { \
- ErrorExtraInfo::registerType<type>(); \
- return Status::OK(); \
+#define MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(type) \
+ MONGO_INITIALIZER_GENERAL(RegisterErrorExtraInfoFor##type, (), ("default")) \
+ (InitializerContext*) { \
+ ErrorExtraInfo::registerType<type>(); \
}
/**
diff --git a/src/mongo/base/global_initializer.cpp b/src/mongo/base/global_initializer.cpp
deleted file mode 100644
index 28639544668..00000000000
--- a/src/mongo/base/global_initializer.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright (C) 2018-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.
- */
-
-#include "mongo/base/global_initializer.h"
-
-#include "mongo/base/initializer.h"
-
-namespace mongo {
-
-Initializer& getGlobalInitializer() {
- static Initializer theGlobalInitializer;
- return theGlobalInitializer;
-}
-
-namespace {
-
-// Make sure that getGlobalInitializer() is called at least once before main(), and so at least
-// once in a single-threaded context. Otherwise, static initialization inside
-// getGlobalInitializer() won't be thread-safe.
-MONGO_COMPILER_VARIABLE_UNUSED const Initializer* const _theGlobalInitializer =
- &getGlobalInitializer();
-
-} // namespace
-
-} // namespace mongo
diff --git a/src/mongo/base/global_initializer.h b/src/mongo/base/global_initializer.h
deleted file mode 100644
index 53c0ceacdb2..00000000000
--- a/src/mongo/base/global_initializer.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (C) 2018-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
-
-namespace mongo {
-class Initializer;
-
-/**
- * Get the process-global initializer object.
- *
- * See mongo/base/initializer.h and mongo/base/init.h for information about process
- * initialization in mongo applications.
- */
-Initializer& getGlobalInitializer();
-
-} // namespace mongo
diff --git a/src/mongo/base/global_initializer_registerer.cpp b/src/mongo/base/global_initializer_registerer.cpp
deleted file mode 100644
index f12a05fdc58..00000000000
--- a/src/mongo/base/global_initializer_registerer.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Copyright (C) 2018-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.
- */
-
-#include "mongo/base/global_initializer_registerer.h"
-
-#include <cstdlib>
-#include <iostream>
-
-#include "mongo/base/global_initializer.h"
-#include "mongo/base/initializer.h"
-
-namespace mongo {
-
-GlobalInitializerRegisterer::GlobalInitializerRegisterer(std::string name,
- InitializerFunction initFn,
- DeinitializerFunction deinitFn,
- std::vector<std::string> prerequisites,
- std::vector<std::string> dependents) {
- Status status = getGlobalInitializer().getInitializerDependencyGraph().addInitializer(
- std::move(name),
- std::move(initFn),
- std::move(deinitFn),
- std::move(prerequisites),
- std::move(dependents));
-
- if (Status::OK() != status) {
- std::cerr << "Attempt to add global initializer failed, status: " << status << std::endl;
- ::abort();
- }
-}
-
-const std::string& defaultInitializerName() {
- static const auto& s = *new std::string("default"); // Leaked to be shutdown-safe.
- return s;
-}
-
-namespace {
-GlobalInitializerRegisterer defaultInitializerRegisterer(
- defaultInitializerName(), [](auto) { return Status::OK(); }, nullptr, {}, {});
-} // namespace
-
-} // namespace mongo
diff --git a/src/mongo/base/global_initializer_registerer.h b/src/mongo/base/global_initializer_registerer.h
deleted file mode 100644
index 08b0ba625bc..00000000000
--- a/src/mongo/base/global_initializer_registerer.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Copyright (C) 2018-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 <string>
-#include <vector>
-
-#include "mongo/base/initializer_function.h"
-#include "mongo/base/status.h"
-
-namespace mongo {
-
-// The name of the "default" global initializer.
-// Global initializers with no explicit prerequisites depends on it by default.
-extern const std::string& defaultInitializerName();
-
-/**
- * Type representing the registration of a global intialization function.
- *
- * Create a nonlocal static storage duration instance of this type to register a new initializer, to
- * be run by a call to a variant of mongo::runGlobalInitializers(). See "mongo/base/initializer.h",
- * "mongo/base/init.h', and "mongo/base/initializer_dependency_graph.h" for details.
- */
-class GlobalInitializerRegisterer {
-public:
- /**
- * Constructor parameters:
- *
- * - std::string name
- *
- * - InitializerFunction initFn
- * Must be nonnull.
- * Example expression:
- *
- * [](InitializerContext* context) {
- * // initialization code
- * return Status::OK();
- * }
- *
- * - DeinitializerFunction deinitFn
- * A deinitialization that will execute in reverse order from initialization and
- * support re-initialization. If not specified, defaults to the `nullptr` function.
- * Example expression:
- *
- * [](DeinitializerContext* context) {
- * // deinitialization code
- * return Status::OK();
- * }
- *
- * - std::vector<std::string> prerequisites
- * If not specified, defaults to {"default"}.
- *
- * - std::vector<std::string> dependents
- * If not specified, defaults to {} (no dependents).
- *
- *
- * At run time, the full set of prerequisites for `name` will be computed as the union of the
- * `prerequisites` (which can be defaulted) and all other mongo initializers that list `name` in
- * their `dependents`.
- *
- * A non-null `deinitFn` will tag the initializer as supporting re-initialization.
- */
- GlobalInitializerRegisterer(std::string name,
- InitializerFunction initFn,
- DeinitializerFunction deinitFn = nullptr,
- std::vector<std::string> prerequisites = {defaultInitializerName()},
- std::vector<std::string> dependents = {});
-
- GlobalInitializerRegisterer(const GlobalInitializerRegisterer&) = delete;
- GlobalInitializerRegisterer& operator=(const GlobalInitializerRegisterer&) = delete;
-};
-
-} // namespace mongo
diff --git a/src/mongo/base/init.cpp b/src/mongo/base/init.cpp
index c13f2529157..3708841589d 100644
--- a/src/mongo/base/init.cpp
+++ b/src/mongo/base/init.cpp
@@ -28,3 +28,35 @@
*/
#include "mongo/base/init.h"
+
+#include <cstdlib>
+#include <iostream>
+
+#include "mongo/base/initializer.h"
+#include "mongo/util/assert_util.h"
+
+namespace mongo {
+
+GlobalInitializerRegisterer::GlobalInitializerRegisterer(std::string name,
+ InitializerFunction initFn,
+ DeinitializerFunction deinitFn,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents) {
+ try {
+ getGlobalInitializer().addInitializer(std::move(name),
+ std::move(initFn),
+ std::move(deinitFn),
+ std::move(prerequisites),
+ std::move(dependents));
+ } catch (const DBException& ex) {
+ std::cerr << "Attempt to add global initializer failed, status: " << ex.toString()
+ << std::endl;
+ ::abort();
+ }
+}
+
+namespace {
+GlobalInitializerRegisterer defaultInitializerRegisterer("default", [](auto) {}, nullptr, {}, {});
+} // namespace
+
+} // namespace mongo
diff --git a/src/mongo/base/init.h b/src/mongo/base/init.h
index 84d9ae97ddb..871d49a1905 100644
--- a/src/mongo/base/init.h
+++ b/src/mongo/base/init.h
@@ -35,39 +35,34 @@
* Initializers are arranged in an acyclic directed dependency graph. Declaring
* a cycle will lead to a runtime error.
*
- * Initializer functions take a parameter of type ::mongo::InitializerContext*, and return
- * a Status. Any status other than Status::OK() is considered a failure that will stop further
- * intializer processing.
+ * Initializer functions take a parameter of type ::mongo::InitializerContext*.
+ * They throw to indicate failure, stopping further intializer processing.
*/
#pragma once
-#include "mongo/base/deinitializer_context.h"
-#include "mongo/base/global_initializer.h"
-#include "mongo/base/global_initializer_registerer.h"
+#include <string>
+#include <vector>
+
#include "mongo/base/initializer.h"
-#include "mongo/base/initializer_context.h"
-#include "mongo/base/initializer_function.h"
#include "mongo/base/status.h"
/**
- * Convenience parameter representing an empty set of prerequisites for an initializer function.
- */
-#define MONGO_NO_PREREQUISITES ()
-
-/**
- * Convenience parameter representing an empty set of dependents of an initializer function.
- */
-#define MONGO_NO_DEPENDENTS ()
-
-/**
- * Convenience parameter representing the default set of dependents for initializer functions.
- */
-#define MONGO_DEFAULT_PREREQUISITES (::mongo::defaultInitializerName().c_str())
-
-/**
- * Macro to define an initializer function named "NAME" with the default prerequisites, and
- * no explicit dependents.
+ * Macro to define an initializer function named "NAME" with the default
+ * prerequisite set, that is `("default")`, and no explicit dependents.
+ *
+ * The default set of prerequisites for initializer functions has one member,
+ * called "default". It refers to a do-nothing initializer called "default"
+ * defined by this init system, which serves as a partition point. It splits
+ * the graph into two broad phases. In practice, most initializers can omit
+ * their prerequisites and dependents, and use the MONGO_INITIALIZER macro, and
+ * such rules will be constrained to occur _after_ the "default" sequence
+ * point. Some special rules perform early preparation like options parsing,
+ * and several initializers might depend on these, so they will typically
+ * specify that they happen _before_ the "default" sequence point.
+ *
+ * The pre-"default" phase is further broken down into an orderly series of
+ * internal stages. (See util/options_parser/startup_option_init.cpp).
*
* See MONGO_INITIALIZER_GENERAL.
*
@@ -76,8 +71,7 @@
* ...
* }
*/
-#define MONGO_INITIALIZER(NAME) \
- MONGO_INITIALIZER_WITH_PREREQUISITES(NAME, MONGO_DEFAULT_PREREQUISITES)
+#define MONGO_INITIALIZER(NAME) MONGO_INITIALIZER_GENERAL(NAME, ("default"), ())
/**
* Macro to define an initializer function named "NAME" that depends on the initializers
@@ -92,7 +86,7 @@
* }
*/
#define MONGO_INITIALIZER_WITH_PREREQUISITES(NAME, PREREQUISITES) \
- MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, MONGO_NO_DEPENDENTS)
+ MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, ())
#define MONGO_INITIALIZER_STRIP_PARENS_(...) __VA_ARGS__
@@ -101,12 +95,12 @@
* dependents.
*
* NAME is any legitimate name for a C++ symbol.
- * PREREQUISITES is a tuple of 0 or more std::string literals, i.e., ("a", "b", "c"), or ()
- * DEPENDENTS is a tuple of 0 or more std::string literals.
+ * PREREQUISITES is a tuple of strings surrounded by parens, e.g., ("a", "b", "c"), or ().
+ * DEPENDENTS is a tuple of strings surrounded by parens.
*
* At run time, the full set of prerequisites for NAME will be computed as the union of the
* explicit PREREQUISITES and the set of all other mongo initializers that name NAME in their
- * list of dependents.
+ * list of DEPENDENTS.
*
* Usage:
* MONGO_INITIALIZER_GENERAL(myInitializer,
@@ -119,17 +113,17 @@
* A form that takes an existing function or that lets the programmer supply the name
* of the function to declare would be options.
*/
-#define MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, DEPENDENTS) \
- ::mongo::Status MONGO_INITIALIZER_FUNCTION_NAME_(NAME)(::mongo::InitializerContext*); \
- namespace { \
- ::mongo::GlobalInitializerRegisterer _mongoInitializerRegisterer_##NAME( \
- std::string(#NAME), \
- mongo::InitializerFunction(MONGO_INITIALIZER_FUNCTION_NAME_(NAME)), \
- mongo::DeinitializerFunction(nullptr), \
- std::vector<std::string>{MONGO_INITIALIZER_STRIP_PARENS_ PREREQUISITES}, \
- std::vector<std::string>{MONGO_INITIALIZER_STRIP_PARENS_ DEPENDENTS}); \
- } \
- ::mongo::Status MONGO_INITIALIZER_FUNCTION_NAME_(NAME)
+#define MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, DEPENDENTS) \
+ void MONGO_INITIALIZER_FUNCTION_NAME_(NAME)(::mongo::InitializerContext*); \
+ namespace { \
+ ::mongo::GlobalInitializerRegisterer _mongoInitializerRegisterer_##NAME( \
+ std::string(#NAME), \
+ mongo::InitializerFunction(MONGO_INITIALIZER_FUNCTION_NAME_(NAME)), \
+ mongo::DeinitializerFunction(nullptr), \
+ std::vector<std::string>{MONGO_INITIALIZER_STRIP_PARENS_ PREREQUISITES}, \
+ std::vector<std::string>{MONGO_INITIALIZER_STRIP_PARENS_ DEPENDENTS}); \
+ } \
+ void MONGO_INITIALIZER_FUNCTION_NAME_(NAME)
/**
* Macro to define an initializer group.
@@ -138,13 +132,68 @@
* initialization steps into phases, such as "all global parameter declarations completed", "all
* global parameters initialized".
*/
-#define MONGO_INITIALIZER_GROUP(NAME, PREREQUISITES, DEPENDENTS) \
- MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, DEPENDENTS)(::mongo::InitializerContext*) { \
- return ::mongo::Status::OK(); \
- }
+#define MONGO_INITIALIZER_GROUP(NAME, PREREQUISITES, DEPENDENTS) \
+ MONGO_INITIALIZER_GENERAL(NAME, PREREQUISITES, DEPENDENTS)(::mongo::InitializerContext*) {}
/**
* Macro to produce a name for a mongo initializer function for an initializer operation
* named "NAME".
*/
#define MONGO_INITIALIZER_FUNCTION_NAME_(NAME) _mongoInitializerFunction_##NAME
+
+namespace mongo {
+
+/**
+ * Type representing the registration of a global initialization function.
+ *
+ * Create a nonlocal static storage duration instance of this type to register a new initializer, to
+ * be run by a call to a variant of mongo::runGlobalInitializers().
+ */
+class GlobalInitializerRegisterer {
+public:
+ /**
+ * Constructor parameters:
+ *
+ * - std::string name
+ *
+ * - InitializerFunction initFn
+ * Must be nonnull.
+ * Example expression:
+ *
+ * [](InitializerContext* context) {
+ * // initialization code
+ * }
+ *
+ * - DeinitializerFunction deinitFn
+ * A deinitialization that will execute in reverse order from initialization and
+ * support re-initialization. If not specified, defaults to `nullptr`.
+ * Example expression:
+ *
+ * [](DeinitializerContext* context) {
+ * // deinitialization code
+ * }
+ *
+ * - std::vector<std::string> prerequisites
+ * If not specified, defaults to {"default"}.
+ *
+ * - std::vector<std::string> dependents
+ * If not specified, defaults to {} (no dependents).
+ *
+ *
+ * At run time, the full set of prerequisites for `name` will be computed as the union of the
+ * `prerequisites` (which can be defaulted) and all other mongo initializers that list `name` in
+ * their `dependents`.
+ *
+ * A non-null `deinitFn` will tag the initializer as supporting re-initialization.
+ */
+ GlobalInitializerRegisterer(std::string name,
+ InitializerFunction initFn,
+ DeinitializerFunction deinitFn = nullptr,
+ std::vector<std::string> prerequisites = {"default"},
+ std::vector<std::string> dependents = {});
+
+ GlobalInitializerRegisterer(const GlobalInitializerRegisterer&) = delete;
+ GlobalInitializerRegisterer& operator=(const GlobalInitializerRegisterer&) = delete;
+};
+
+} // namespace mongo
diff --git a/src/mongo/base/initializer.cpp b/src/mongo/base/initializer.cpp
index 89799707ce9..633067784f7 100644
--- a/src/mongo/base/initializer.cpp
+++ b/src/mongo/base/initializer.cpp
@@ -26,109 +26,212 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
#include "mongo/platform/basic.h"
#include "mongo/base/initializer.h"
+#include <fmt/format.h>
#include <iostream>
+#include <string>
+#include <utility>
+#include <vector>
-#include "mongo/base/deinitializer_context.h"
-#include "mongo/base/global_initializer.h"
-#include "mongo/base/initializer_context.h"
+#include "mongo/base/dependency_graph.h"
+#include "mongo/base/status.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/quick_exit.h"
#include "mongo/util/str.h"
namespace mongo {
-Status Initializer::executeInitializers(const std::vector<std::string>& args) {
- auto oldState = std::exchange(_lifecycleState, State::kInitializing);
- invariant(oldState == State::kUninitialized, "invalid initializer state transition");
+class Initializer::Graph {
+public:
+ class Payload : public DependencyGraph::Payload {
+ public:
+ InitializerFunction initFn;
+ DeinitializerFunction deinitFn;
+ bool initialized = false;
+ };
+
+ /**
+ * Note that cycles in the dependency graph are not discovered by this
+ * function. Rather, they're discovered by `topSort`, below.
+ */
+ void add(std::string name,
+ InitializerFunction initFn,
+ DeinitializerFunction deinitFn,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents) {
+ auto data = std::make_unique<Payload>();
+ data->initFn = std::move(initFn);
+ data->deinitFn = std::move(deinitFn);
+ _graph.addNode(
+ std::move(name), std::move(prerequisites), std::move(dependents), std::move(data));
+ }
- if (_sortedNodes.empty()) {
- if (Status status = _graph.topSort(&_sortedNodes); !status.isOK()) {
- return status;
- }
+ /**
+ * Returns the payload of the node that was added by `name`, or nullptr if no such node exists.
+ */
+ Payload* find(const std::string& name) {
+ return static_cast<Payload*>(_graph.find(name));
+ }
+
+ /**
+ * Returns a topological sort of the dependency graph, represented
+ * as an ordered vector of node names.
+ *
+ * - Throws with `ErrorCodes::GraphContainsCycle` if the graph contains a cycle.
+ *
+ * - Throws with `ErrorCodes::BadValue` if the graph is incomplete.
+ * That is, a node named in a dependency edge was never added.
+ */
+ std::vector<std::string> topSort() const {
+ return _graph.topSort();
}
- _graph.freeze();
+
+private:
+ /**
+ * Map of all named nodes. Nodes named as dependency edges but not
+ * explicitly added will either be absent from this map or be present with
+ * a null-valude initFn.
+ */
+ DependencyGraph _graph;
+};
+
+Initializer::Initializer() : _graph(std::make_unique<Graph>()) {}
+Initializer::~Initializer() = default;
+
+void Initializer::_transition(State expected, State next) {
+ if (_lifecycleState != expected)
+ uasserted(
+ ErrorCodes::IllegalOperation,
+ format(
+ FMT_STRING(
+ "Invalid initializer state transition. Expected {} -> {}, but currently at {}"),
+ expected,
+ next,
+ _lifecycleState));
+ _lifecycleState = next;
+}
+
+void Initializer::addInitializer(std::string name,
+ InitializerFunction initFn,
+ DeinitializerFunction deinitFn,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents) {
+ uassert(ErrorCodes::BadValue, "Null-valued init function", initFn);
+ uassert(ErrorCodes::CannotMutateObject,
+ "Initializer dependency graph is frozen",
+ _lifecycleState == State::kNeverInitialized);
+ _graph->add(std::move(name),
+ std::move(initFn),
+ std::move(deinitFn),
+ std::move(prerequisites),
+ std::move(dependents));
+}
+
+
+void Initializer::executeInitializers(const std::vector<std::string>& args) {
+ if (_lifecycleState == State::kNeverInitialized)
+ _transition(State::kNeverInitialized, State::kUninitialized); // freeze
+ _transition(State::kUninitialized, State::kInitializing);
+
+ if (_sortedNodes.empty())
+ _sortedNodes = _graph->topSort();
InitializerContext context(args);
for (const auto& nodeName : _sortedNodes) {
- InitializerDependencyNode* node = _graph.getInitializerNode(nodeName);
-
- // If already initialized then this node is a legacy initializer without re-initialization
- // support.
- if (node->isInitialized())
- continue;
-
- auto const& fn = node->getInitializerFunction();
- if (!fn) {
- return Status(ErrorCodes::InternalError,
- "topSort returned a node that has no associated function: \"" + nodeName +
- '"');
- }
- try {
- if (Status status = fn(&context); !status.isOK()) {
- return status;
- }
- } catch (const DBException& xcp) {
- return xcp.toStatus();
- }
+ auto* node = _graph->find(nodeName);
+
+ if (node->initialized)
+ continue; // Legacy initializer without re-initialization support.
+
+ uassert(ErrorCodes::InternalError,
+ format(FMT_STRING("node has no init function: \"{}\""), nodeName),
+ node->initFn);
+ node->initFn(&context);
- node->setInitialized(true);
+ node->initialized = true;
}
- oldState = std::exchange(_lifecycleState, State::kInitialized);
- invariant(oldState == State::kInitializing, "invalid initializer state transition");
+ _transition(State::kInitializing, State::kInitialized);
- return Status::OK();
+ // The order of the initializers is non-deterministic, so make it available.
+ // Must be after verbose has been parsed, or the Debug(2) severity won't be visible.
+ LOGV2_DEBUG_OPTIONS(4777800,
+ 2,
+ {logv2::LogTruncation::Disabled},
+ "Ran initializers",
+ "nodes"_attr = _sortedNodes);
}
-Status Initializer::executeDeinitializers() {
- auto oldState = std::exchange(_lifecycleState, State::kDeinitializing);
- invariant(oldState == State::kInitialized, "invalid initializer state transition");
+void Initializer::executeDeinitializers() {
+ _transition(State::kInitialized, State::kDeinitializing);
DeinitializerContext context{};
// Execute deinitialization in reverse order from initialization.
for (auto it = _sortedNodes.rbegin(), end = _sortedNodes.rend(); it != end; ++it) {
- InitializerDependencyNode* node = _graph.getInitializerNode(*it);
- auto const& fn = node->getDeinitializerFunction();
- if (fn) {
- try {
- if (Status status = fn(&context); !status.isOK()) {
- return status;
- }
- } catch (const DBException& xcp) {
- return xcp.toStatus();
- }
-
- node->setInitialized(false);
+ auto* node = _graph->find(*it);
+ if (node->deinitFn) {
+ node->deinitFn(&context);
+ node->initialized = false;
}
}
- oldState = std::exchange(_lifecycleState, State::kUninitialized);
- invariant(oldState == State::kDeinitializing, "invalid initializer state transition");
+ _transition(State::kDeinitializing, State::kUninitialized);
+}
+
+InitializerFunction Initializer::getInitializerFunctionForTesting(const std::string& name) {
+ auto node = _graph->find(name);
+ return node ? node->initFn : nullptr;
+}
+
- return Status::OK();
+Initializer& getGlobalInitializer() {
+ static auto g = new Initializer;
+ return *g;
}
Status runGlobalInitializers(const std::vector<std::string>& argv) {
- return getGlobalInitializer().executeInitializers(argv);
+ try {
+ getGlobalInitializer().executeInitializers(argv);
+ return Status::OK();
+ } catch (const DBException& ex) {
+ return ex.toStatus();
+ }
}
Status runGlobalDeinitializers() {
- return getGlobalInitializer().executeDeinitializers();
+ try {
+ getGlobalInitializer().executeDeinitializers();
+ return Status::OK();
+ } catch (const DBException& ex) {
+ return ex.toStatus();
+ }
}
void runGlobalInitializersOrDie(const std::vector<std::string>& argv) {
- Status status = runGlobalInitializers(argv);
- if (!status.isOK()) {
+ if (Status status = runGlobalInitializers(argv); !status.isOK()) {
std::cerr << "Failed global initialization: " << status << std::endl;
quickExit(1);
}
}
+namespace {
+
+// Make sure that getGlobalInitializer() is called at least once before main(), and so at least
+// once in a single-threaded context. Otherwise, static initialization inside
+// getGlobalInitializer() won't be thread-safe.
+MONGO_COMPILER_VARIABLE_UNUSED const auto earlyCaller = [] {
+ getGlobalInitializer();
+ return 0;
+}();
+
+} // namespace
+
} // namespace mongo
diff --git a/src/mongo/base/initializer.h b/src/mongo/base/initializer.h
index 131e3144477..12a2fa9bf7e 100644
--- a/src/mongo/base/initializer.h
+++ b/src/mongo/base/initializer.h
@@ -29,56 +29,141 @@
#pragma once
+#include <functional>
#include <string>
#include <vector>
-#include "mongo/base/initializer_context.h"
-#include "mongo/base/initializer_dependency_graph.h"
#include "mongo/base/status.h"
namespace mongo {
+/** Context of an initialization process. Passed as a parameter to initialization functions. */
+class InitializerContext {
+public:
+ explicit InitializerContext(std::vector<std::string> args) : _args(std::move(args)) {}
+
+ const std::vector<std::string>& args() const {
+ return _args;
+ }
+
+private:
+ std::vector<std::string> _args;
+};
+
+/** Context of a deinitialization process. Passed as a parameter to deinitialization functions. */
+class DeinitializerContext {
+public:
+ DeinitializerContext(const DeinitializerContext&) = delete;
+ DeinitializerContext& operator=(const DeinitializerContext&) = delete;
+};
+
+/**
+ * An InitializerFunction implements the behavior of an initializer operation.
+ * It may inspect and mutate the supplied InitializerContext.
+ * Throws on failure.
+ */
+using InitializerFunction = std::function<void(InitializerContext*)>;
+
+/**
+ * A DeinitializerFunction implements the behavior of a deinitializer operation.
+ * It may inspect and mutate the supplied DeinitializerContext.
+ * Throws on failure.
+ */
+using DeinitializerFunction = std::function<void(DeinitializerContext*)>;
+
+
/**
* Class representing an initialization process.
*
* Such a process is described by a directed acyclic graph of initialization operations, the
- * InitializerDependencyGraph. One constructs an initialization process by adding nodes and
+ * InitializerDependencyGraph. One constructs an initialization process by adding nodes and
* edges to the graph. Then, one executes the process, causing each initialization operation to
* execute in an order that respects the programmer-established prerequistes.
+ *
+ * The initialize and delinitialize process can repeat, a features which
+ * supports embedded contexts. However, the graph cannot be modified with
+ * `addInitializer` after the first initialization. Latecomers are rejected.
*/
class Initializer {
public:
+ Initializer();
+ ~Initializer();
+
/**
- * Get the initializer dependency graph, presumably for the purpose of adding more nodes.
+ * Add a new initializer node, with the specified `name`, to the dependency graph, with the
+ * given behavior, `initFn`, `deinitFn`, and with the given `prerequisites` and `dependents`,
+ * which are the names of other initializers which will be in the graph when `topSort`
+ * is called. `initFn` must be non-null, but null-valued `deinitFn` are allowed.
+ *
+ * - Throws `ErrorCodes::BadValue` if `initFn` is null-valued.
+ *
+ * - Throws with `ErrorCodes::CannotMutateObject` if the graph has been frozen
+ * by a previous call to `executeInitializers`.
*/
- InitializerDependencyGraph& getInitializerDependencyGraph() {
- return _graph;
- }
+ void addInitializer(std::string name,
+ InitializerFunction initFn,
+ DeinitializerFunction deinitFn,
+ std::vector<std::string> prerequisites,
+ std::vector<std::string> dependents);
/**
- * Execute the initializer process, using the given argv and environment data as input.
+ * Execute the initializer process, using the given args as input.
+ * This call freezes the graph, so that addInitializer will reject any latecomers.
*
- * Returns Status::OK on success. All other returns constitute initialization failures,
- * and the thing being initialized should be considered dead in the water.
+ * Throws on initialization failures, or on invalid call sequences
+ * (double-init, double-deinit, etc) and the thing being initialized should
+ * be considered dead in the water.
*/
- Status executeInitializers(const std::vector<std::string>& args);
+ void executeInitializers(const std::vector<std::string>& args);
- Status executeDeinitializers();
+ /**
+ * Executes all deinit functions in reverse order from init order.
+ * Note that this does not unfreeze the graph. Freezing is permanent.
+ */
+ void executeDeinitializers();
+
+ /**
+ * Returns the function mapped to `name`, for testing only.
+ *
+ * Throws with `ErrorCodes::BadValue` if name is not mapped to a node.
+ */
+ InitializerFunction getInitializerFunctionForTesting(const std::string& name);
private:
+ class Graph;
+
+ /**
+ * kNeverInitialized
+ * |
+ * +-> kUninitialized <----------+
+ * | |
+ * +-> kInitializing |
+ * | |
+ * +-> kInitialized |
+ * | |
+ * +-> kDeinitializing
+ */
enum class State {
+ kNeverInitialized, ///< still accepting addInitializer calls
kUninitialized,
kInitializing,
kInitialized,
kDeinitializing,
};
- InitializerDependencyGraph _graph;
+ void _transition(State expected, State next);
+
+ std::unique_ptr<Graph> _graph; // pimpl
std::vector<std::string> _sortedNodes;
- State _lifecycleState{State::kUninitialized};
+ State _lifecycleState = State::kNeverInitialized;
};
/**
+ * Get the process-global initializer object.
+ */
+Initializer& getGlobalInitializer();
+
+/**
* Run the global initializers.
*
* It's a programming error for this to fail, but if it does it will return a status other
diff --git a/src/mongo/base/initializer_context.h b/src/mongo/base/initializer_context.h
deleted file mode 100644
index 9ba23d69441..00000000000
--- a/src/mongo/base/initializer_context.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (C) 2018-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/db/service_context_fwd.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace mongo {
-/**
- * Context of an initialization process. Passed as a parameter to initialization functions.
- *
- * See mongo/base/initializer.h and mongo/base/initializer_dependency_graph.h for more details.
- */
-class InitializerContext {
-public:
- explicit InitializerContext(std::vector<std::string> args) : _args(std::move(args)) {}
-
- const std::vector<std::string>& args() const {
- return _args;
- }
-
-private:
- std::vector<std::string> _args;
-};
-
-} // namespace mongo
diff --git a/src/mongo/base/initializer_dependency_graph.h b/src/mongo/base/initializer_dependency_graph.h
deleted file mode 100644
index 515f75cff26..00000000000
--- a/src/mongo/base/initializer_dependency_graph.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * Copyright (C) 2018-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 <string>
-#include <utility>
-#include <vector>
-
-#include "mongo/base/initializer_function.h"
-#include "mongo/base/status.h"
-#include "mongo/stdx/unordered_map.h"
-#include "mongo/stdx/unordered_set.h"
-
-namespace mongo {
-
-class InitializerDependencyNode {
- friend class InitializerDependencyGraph;
-
-public:
- bool isInitialized() const {
- return initialized;
- }
- void setInitialized(bool value) {
- initialized = value;
- };
-
- InitializerFunction const& getInitializerFunction() const {
- return initFn;
- }
- DeinitializerFunction const& getDeinitializerFunction() const {
- return deinitFn;
- }
-
-private:
- InitializerFunction initFn;
- DeinitializerFunction deinitFn;
- stdx::unordered_set<std::string> prerequisites;
- bool initialized{false};
-};
-
-/**
- * Representation of a dependency graph of "initialization operations."
- *
- * Each operation has a unique name, a function object implementing the operation's behavior,
- * and a set of prerequisite operations, which may be empty. A legal graph contains no cycles.
- *
- * Instances of this class are used in two phases. In the first phase, the graph is "unfrozen",
- * which permits it to be constructed by repeated calls to addInitializer(). In the second phase,
- * the graph is "frozen" by calling frozen(), which prevents the addition of any further
- * initializers to the graph. A user can then call the topSort() method to produce an
- * initialization order that respects the dependencies among operations, and then uses the
- * getInitializerFunction() to get the behavior function for each operation, in turn.
- *
- * Concurrency Notes: The user is responsible for synchronization. Multiple threads may
- * simultaneously call the const functions, getInitializerFunction and topSort, on the same instance
- * of InitializerDependencyGraph. However, no thread may call addInitializer or freeze while any
- * thread is executing those functions, addInitializer or freeze on the same instance.
- */
-class InitializerDependencyGraph {
- InitializerDependencyGraph(const InitializerDependencyGraph&) = delete;
- InitializerDependencyGraph& operator=(const InitializerDependencyGraph&) = delete;
-
-public:
- InitializerDependencyGraph();
- ~InitializerDependencyGraph();
-
- /**
- * Add a new initializer node, named "name", to the dependency graph, with the given
- * behavior, "fn", and the given "prerequisites" (input dependencies) and "dependents"
- * (output dependencies).
- *
- * The graph must not be frozen.
- *
- * If "!fn" (fn is NULL in function pointer parlance), returns status with code
- * ErrorCodes::badValue. If "name" is a duplicate of a name already present in the graph,
- * returns "ErrorCodes::duplicateKey". Otherwise, returns Status::OK() and adds the new node
- * to the graph. Note that cycles in the dependency graph are not discovered in this phase.
- * Rather, they're discovered by topSort, below.
- */
- Status addInitializer(std::string name,
- InitializerFunction initFn,
- DeinitializerFunction deinitFn,
- std::vector<std::string> prerequisites,
- std::vector<std::string> dependents);
-
- /**
- * Given a dependency operation node named "name", return its behavior function. Returns
- * a value that evaluates to "false" in boolean context, otherwise.
- */
- InitializerDependencyNode* getInitializerNode(const std::string& name);
-
- /**
- * Construct a topological sort of the dependency graph, and store that order into
- * "sortedNames". Returns Status::OK() on success.
- *
- * If the graph contains a cycle, returns ErrorCodes::graphContainsCycle, and "sortedNames"
- * is an ordered sequence of nodes involved in a cycle. In this case, the first and last
- * element of "sortedNames" will be equal.
- *
- * If any node in the graph names a prerequisite that was never added to the graph via
- * addInitializer, this function will return ErrorCodes::badValue.
- *
- * Any other return value indicates an internal error, and should not occur.
- */
- Status topSort(std::vector<std::string>* sortedNames) const;
-
- /**
- * Called to mark the end of the period when nodes are allowed to be added to the graph.
- * The graph is effectively read-only after this point.
- */
- void freeze() {
- _frozen = true;
- }
-
- /**
- * Returns true if this graph has been frozen.
- */
- bool frozen() const {
- return _frozen;
- }
-
-private:
- typedef stdx::unordered_map<std::string, InitializerDependencyNode> NodeMap;
- typedef NodeMap::value_type Node;
-
- /**
- * Map of all named nodes. Nodes named as prerequisites or dependents but not explicitly
- * added via addInitializer will either be absent from this map or be present with
- * NodeData::fn set to a false-ish value.
- */
- NodeMap _nodes;
-
- /**
- * If true, then the graph is "frozen" (ie. effectively read-only), and adding initializer nodes
- * is not allowed.
- */
- bool _frozen{false};
-};
-
-} // namespace mongo
diff --git a/src/mongo/base/initializer_dependency_graph_test.cpp b/src/mongo/base/initializer_dependency_graph_test.cpp
deleted file mode 100644
index 3194041d1a9..00000000000
--- a/src/mongo/base/initializer_dependency_graph_test.cpp
+++ /dev/null
@@ -1,405 +0,0 @@
-/**
- * Copyright (C) 2018-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.
- */
-
-/**
- * Unit tests of the InitializerDependencyGraph type.
- */
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include "mongo/base/init.h"
-#include "mongo/base/initializer_dependency_graph.h"
-#include "mongo/unittest/death_test.h"
-#include "mongo/unittest/unittest.h"
-
-#define STRIP_PARENS_(...) __VA_ARGS__
-
-#define ADD_INITIALIZER(GRAPH, NAME, FN, PREREQS, DEPS) \
- (GRAPH).addInitializer((NAME), \
- (FN), \
- DeinitializerFunction(), \
- std::vector<std::string>{STRIP_PARENS_ PREREQS}, \
- std::vector<std::string>{STRIP_PARENS_ DEPS})
-
-#define ASSERT_ADD_INITIALIZER(GRAPH, NAME, FN, PREREQS, DEPS) \
- ASSERT_EQUALS(Status::OK(), ADD_INITIALIZER(GRAPH, NAME, FN, PREREQS, DEPS))
-
-#define ASSERT_EXACTLY_N_IN_CONTAINER(N, CONTAINER, THING) \
- ASSERT_EQUALS(N, std::count((CONTAINER).begin(), (CONTAINER).end(), (THING)))
-
-#define ASSERT_AT_LEAST_N_IN_CONTAINER(N, CONTAINER, THING) \
- ASSERT_LESS_THAN_OR_EQUALS(N, std::count((CONTAINER).begin(), (CONTAINER).end(), (THING)))
-
-#define ASSERT_EXACTLY_ONE_IN_CONTAINER(CONTAINER, THING) \
- ASSERT_EXACTLY_N_IN_CONTAINER(1, CONTAINER, THING)
-
-namespace mongo {
-namespace {
-
-Status doNothing(InitializerContext*) {
- return Status::OK();
-}
-
-TEST(InitializerDependencyGraphTest, InsertNullFunctionFails) {
- InitializerDependencyGraph graph;
- ASSERT_EQUALS(
- ErrorCodes::BadValue,
- ADD_INITIALIZER(
- graph, "A", InitializerFunction(), MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS));
-}
-
-TEST(InitializerDependencyGraphTest, InsertSameNameTwiceFails) {
- InitializerDependencyGraph graph;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_EQUALS(
- 50999,
- ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS).code());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortEmptyGraph) {
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(0U, nodeNames.size());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortGraphNoDeps) {
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(3U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondPrerequisites) {
- /*
- * This tests top-sorting a simple diamond, specified using prerequisites:
- *
- * B
- * / ^
- * v \
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("B", "C"), MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), MONGO_NO_DEPENDENTS);
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "D");
- ASSERT_EQUALS("A", nodeNames.front());
- ASSERT_EQUALS("D", nodeNames.back());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondDependents) {
- /*
- * This tests top-sorting a simple diamond, specified using dependents:
- *
- * B
- * / ^
- * v \
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, ("D"));
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, ("D"));
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "D");
- ASSERT_EQUALS("A", nodeNames.front());
- ASSERT_EQUALS("D", nodeNames.back());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondGeneral1) {
- /*
- * This tests top-sorting a simple diamond, where B and C specify all prerequisites and
- * dependents.
- *
- * B
- * / ^
- * v \
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ("D"));
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), ("D"));
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "D");
- ASSERT_EQUALS("A", nodeNames.front());
- ASSERT_EQUALS("D", nodeNames.back());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondGeneral2) {
- /*
- * This tests top-sorting a simple diamond, where A and D specify all prerequisites and
- * dependents.
- *
- * B
- * / ^
- * v \
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "D");
- ASSERT_EQUALS("A", nodeNames.front());
- ASSERT_EQUALS("D", nodeNames.back());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondGeneral3) {
- /*
- * This tests top-sorting a simple diamond, where A and D specify all prerequisites and
- * dependents, but so do B and C.
- *
- * B
- * / ^
- * v \
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ("D"));
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), ("D"));
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "D");
- ASSERT_EQUALS("A", nodeNames.front());
- ASSERT_EQUALS("D", nodeNames.back());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortWithDiamondAndCycle) {
- /*
- * This tests top-sorting a graph with a cycle, which should fail..
- *
- * B <- E
- * / ^ ^
- * v \ /
- * A D
- * ^ /
- * \ v
- * C
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "E", doNothing, ("D"), ("B"));
- ASSERT_EQUALS(ErrorCodes::GraphContainsCycle, graph.topSort(&nodeNames));
- ASSERT_EQUALS(4U, nodeNames.size());
- ASSERT_EQUALS(nodeNames.front(), nodeNames.back());
- ASSERT_AT_LEAST_N_IN_CONTAINER(1, nodeNames, "D");
- ASSERT_AT_LEAST_N_IN_CONTAINER(1, nodeNames, "E");
- ASSERT_AT_LEAST_N_IN_CONTAINER(1, nodeNames, "B");
- ASSERT_EXACTLY_N_IN_CONTAINER(0, nodeNames, "A");
- ASSERT_EXACTLY_N_IN_CONTAINER(0, nodeNames, "C");
-}
-
-TEST(InitializerDependencyGraphTest, TopSortFailsWhenMissingPrerequisite) {
- /*
- * If a node names a never-declared prerequisite, topSort should fail.
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), MONGO_NO_DEPENDENTS);
- auto status = graph.topSort(&nodeNames);
- ASSERT_EQUALS(ErrorCodes::BadValue, status);
- ASSERT_STRING_CONTAINS(status.reason(), "depends on missing initializer A");
-}
-
-TEST(InitializerDependencyGraphTest, TopSortFailsWhenMissingDependent) {
- /*
- * If a node names a never-declared dependent, topSort should fail.
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B"));
- auto status = graph.topSort(&nodeNames);
- ASSERT_EQUALS(ErrorCodes::BadValue, status);
- ASSERT_STRING_CONTAINS(status.reason(), "No implementation provided for initializer B");
-}
-
-std::vector<std::vector<std::string>> allPermutations(std::vector<std::string> vec,
- size_t first,
- size_t last) {
- std::vector<std::vector<std::string>> out;
- auto i1 = vec.begin() + first;
- auto i2 = vec.begin() + last;
- std::sort(i1, i2);
- do {
- out.push_back(vec);
- } while (std::next_permutation(i1, i2));
- return out;
-}
-
-template <typename Expectations, typename F>
-void doUntilAllSeen(const Expectations& expected, F&& f) {
- std::vector<int> seen(expected.size(), 0);
- while (std::find(seen.begin(), seen.end(), 0) != seen.end()) {
- auto found = std::find(expected.begin(), expected.end(), f());
- ASSERT_TRUE(found != expected.end());
- ++seen[found - expected.begin()];
- }
-}
-
-TEST(InitializerDependencyGraphTest, TopSortShufflesNodes) {
- /*
- * Make sure all node orderings can appear as outputs.
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> graphNodes;
- for (int i = 0; i < 5; ++i) {
- std::string s = "Node" + std::to_string(i);
- graphNodes.push_back(s);
- ASSERT_ADD_INITIALIZER(graph, s, doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- }
- std::vector<std::string> nodeNames;
- doUntilAllSeen(allPermutations(graphNodes, 0, graphNodes.size()), [&]() -> decltype(auto) {
- nodeNames.clear();
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- return nodeNames;
- });
-}
-
-TEST(InitializerDependencyGraphTest, TopSortShufflesChildren) {
- /*
- * Make sure all child orderings can appear as outputs.
- */
- InitializerDependencyGraph graph;
- std::vector<std::string> graphNodes;
- graphNodes.push_back("Parent");
- ASSERT_ADD_INITIALIZER(graph, "Parent", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- for (int i = 0; i < 5; ++i) {
- std::string s = "Child" + std::to_string(i);
- graphNodes.push_back(s);
- ASSERT_ADD_INITIALIZER(graph, s, doNothing, ("Parent"), MONGO_NO_DEPENDENTS);
- }
- std::vector<std::string> nodeNames;
- // Permute only the children.
- doUntilAllSeen(allPermutations(graphNodes, 1, graphNodes.size()), [&]() -> decltype(auto) {
- nodeNames.clear();
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- return nodeNames;
- });
-}
-
-TEST(InitializerDependencyGraphTest, FreezeCausesFrozen) {
- InitializerDependencyGraph graph;
- ASSERT_FALSE(graph.frozen());
- graph.freeze();
- ASSERT_TRUE(graph.frozen());
- graph.freeze();
- ASSERT_TRUE(graph.frozen());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortEmptyGraphWhileFrozen) {
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- graph.freeze();
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(0U, nodeNames.size());
-}
-
-TEST(InitializerDependencyGraphTest, TopSortGraphNoDepsWhileFrozen) {
- InitializerDependencyGraph graph;
- std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
- graph.freeze();
- ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
- ASSERT_EQUALS(3U, nodeNames.size());
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "B");
- ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "C");
-}
-
-DEATH_TEST(InitializerDependencyGraphTest, CannotAddWhenFrozen, "!frozen()") {
- InitializerDependencyGraph graph;
- graph.freeze();
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
-}
-
-} // namespace
-} // namespace mongo
diff --git a/src/mongo/base/initializer_function.h b/src/mongo/base/initializer_function.h
deleted file mode 100644
index 05025010a87..00000000000
--- a/src/mongo/base/initializer_function.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright (C) 2018-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 <functional>
-
-#include "mongo/base/status.h"
-
-namespace mongo {
-
-class InitializerContext;
-class DeinitializerContext;
-
-/**
- * An InitializerFunction implements the behavior of an initializer operation.
- *
- * On successful execution, an InitializerFunction returns Status::OK(). It may
- * inspect and mutate the supplied InitializerContext.
- */
-typedef std::function<Status(InitializerContext*)> InitializerFunction;
-
-/**
- * A DeinitializerFunction implements the behavior of a deinitializer operation.
- *
- * On successful execution, a DeinitializerFunction returns Status::OK(). It may
- * inspect and mutate the supplied DeinitializerContext.
- */
-typedef std::function<Status(DeinitializerContext*)> DeinitializerFunction;
-
-
-} // namespace mongo
diff --git a/src/mongo/base/initializer_test.cpp b/src/mongo/base/initializer_test.cpp
index 3598e26694f..907b3881384 100644
--- a/src/mongo/base/initializer_test.cpp
+++ b/src/mongo/base/initializer_test.cpp
@@ -31,418 +31,267 @@
* Unit tests of the Initializer type.
*/
+#include <fmt/format.h>
+
#include "mongo/base/init.h"
#include "mongo/base/initializer.h"
-#include "mongo/base/initializer_dependency_graph.h"
-#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
-/*
- * Unless otherwise specified, all tests herein use the following
- * dependency graph.
- *
- * 0 <- 3 <- 7
- * ^ / ^ ^
- * \ v \ \
- * 2 5 <- 8
- * / ^ / /
- * v \ v v
- * 1 <- 4 <- 6
- *
- */
-
-#define STRIP_PARENS_(...) __VA_ARGS__
-
-#define ADD_INITIALIZER(GRAPH, NAME, INIT_FN, DEINIT_FN, PREREQS, DEPS) \
- (GRAPH).addInitializer((NAME), \
- (INIT_FN), \
- (DEINIT_FN), \
- std::vector<std::string>{STRIP_PARENS_ PREREQS}, \
- std::vector<std::string>{STRIP_PARENS_ DEPS})
-
-#define ASSERT_ADD_INITIALIZER(GRAPH, NAME, INIT_FN, DEINIT_FN, PREREQS, DEPS) \
- ASSERT_EQUALS(Status::OK(), ADD_INITIALIZER(GRAPH, NAME, INIT_FN, DEINIT_FN, PREREQS, DEPS))
-
-
-#define CONSTRUCT_DEPENDENCY_GRAPH(GRAPH, \
- INIT_FN0, \
- DEINIT_FN0, \
- INIT_FN1, \
- DEINIT_FN1, \
- INIT_FN2, \
- DEINIT_FN2, \
- INIT_FN3, \
- DEINIT_FN3, \
- INIT_FN4, \
- DEINIT_FN4, \
- INIT_FN5, \
- DEINIT_FN5, \
- INIT_FN6, \
- DEINIT_FN6, \
- INIT_FN7, \
- DEINIT_FN7, \
- INIT_FN8, \
- DEINIT_FN8) \
- do { \
- InitializerDependencyGraph& _graph_ = (GRAPH); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n0", INIT_FN0, DEINIT_FN0, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n1", INIT_FN1, DEINIT_FN1, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n2", INIT_FN2, DEINIT_FN2, ("n0", "n1"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n3", INIT_FN3, DEINIT_FN3, ("n0", "n2"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n4", INIT_FN4, DEINIT_FN4, ("n2", "n1"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n5", INIT_FN5, DEINIT_FN5, ("n3", "n4"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER(_graph_, "n6", INIT_FN6, DEINIT_FN6, ("n4"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER(_graph_, "n7", INIT_FN7, DEINIT_FN7, ("n3"), MONGO_NO_DEPENDENTS); \
- ASSERT_ADD_INITIALIZER( \
- _graph_, "n8", INIT_FN8, DEINIT_FN8, ("n5", "n6", "n7"), MONGO_NO_DEPENDENTS); \
- } while (false)
-
namespace mongo {
namespace {
-enum State {
- UNSET = 0,
- INITIALIZED = 1,
- DEINITIALIZED = 2,
+using namespace fmt::literals;
+
+class InitializerTest : public unittest::Test {
+public:
+ enum State {
+ kUnset = 0,
+ kInitialized = 1,
+ kDeinitialized = 2,
+ };
+
+ struct Graph {
+ struct Node {
+ std::string name;
+ std::vector<size_t> prereqs;
+ };
+
+ /**
+ * The dependency graph expressed as a vector of vectors.
+ * Each row is a vector of the corresponding node's dependencies.
+ */
+ auto prerequisites() const {
+ std::vector<std::vector<size_t>> result;
+ for (const auto& node : nodes)
+ result.push_back(node.prereqs);
+ return result;
+ }
+
+ /** Invert the prereq edges. */
+ auto dependents() const {
+ std::vector<std::vector<size_t>> result(nodes.size());
+ for (size_t i = 0; i != nodes.size(); ++i)
+ for (auto& r : nodes[i].prereqs)
+ result[r].push_back(i);
+ return result;
+ }
+
+ size_t size() const {
+ return nodes.size();
+ }
+
+ std::vector<Node> nodes;
+ };
+
+ /*
+ * Unless otherwise specified, all tests herein use the following
+ * dependency graph.
+ */
+ static inline const Graph graph{{
+ {"n0", {}}, // 0
+ // |
+ {"n1", {}}, // | 1
+ // | |
+ {"n2", {0, 1}}, // +--+->2
+ // | | |
+ {"n3", {0, 2}}, // +-----+->3
+ // | | |
+ {"n4", {1, 2}}, // +--+---->4
+ // | |
+ {"n5", {3, 4}}, // +--+->5
+ // | | |
+ {"n6", {4}}, // | +---->6
+ // | | |
+ {"n7", {3}}, // +---------->7
+ // | | |
+ {"n8", {5, 6, 7}}, // +--+--+->8
+ }};
+
+ /** The arguments for an addInitializer call. */
+ struct NodeSpec {
+ std::string name;
+ std::function<void(InitializerContext*)> init;
+ std::function<void(DeinitializerContext*)> deinit;
+ std::vector<std::string> prerequisites;
+ std::vector<std::string> dependents;
+ };
+
+ void initImpl(size_t idx) {
+ auto reqs = graph.prerequisites()[idx];
+ for (auto req : reqs)
+ if (states[req] != kInitialized)
+ uasserted(ErrorCodes::UnknownError,
+ "(init{0}) {1} not already initialized"_format(idx, req));
+ states[idx] = kInitialized;
+ }
+
+ void deinitImpl(size_t idx) {
+ if (states[idx] != kInitialized)
+ uasserted(ErrorCodes::UnknownError, "(deinit{0}) {0} not initialized"_format(idx));
+ auto deps = graph.dependents()[idx];
+ for (auto dep : deps)
+ if (states[dep] != kDeinitialized)
+ uasserted(ErrorCodes::UnknownError,
+ "(deinit{0}) {1} not already deinitialized"_format(idx, dep));
+ states[idx] = kDeinitialized;
+ }
+
+ static void initNoop(InitializerContext*) {}
+ static void deinitNoop(DeinitializerContext*) {}
+
+ std::vector<NodeSpec> makeDependencyGraphSpecs(const Graph& graph) {
+ std::vector<NodeSpec> specs;
+ for (size_t idx = 0; idx != graph.size(); ++idx) {
+ std::vector<std::string> reqNames;
+ for (auto&& req : graph.nodes[idx].prereqs)
+ reqNames.push_back(graph.nodes[req].name);
+ specs.push_back({graph.nodes[idx].name,
+ [this, idx](InitializerContext*) { initImpl(idx); },
+ [this, idx](DeinitializerContext*) { deinitImpl(idx); },
+ reqNames,
+ {}});
+ }
+ return specs;
+ }
+
+ void constructDependencyGraph(Initializer& initializer,
+ const std::vector<NodeSpec>& nodeSpecs) {
+ for (const auto& n : nodeSpecs)
+ initializer.addInitializer(n.name, n.init, n.deinit, n.prerequisites, n.dependents);
+ }
+
+ void constructDependencyGraph(Initializer& initializer) {
+ constructDependencyGraph(initializer, makeDependencyGraphSpecs(graph));
+ }
+
+ std::vector<State> states = std::vector<State>(graph.size(), kUnset);
};
-State globalStates[9];
-
-Status initNoop(InitializerContext*) {
- return Status::OK();
-}
-
-Status deinitNoop(DeinitializerContext*) {
- return Status::OK();
-}
-
-Status init0(InitializerContext*) {
- globalStates[0] = INITIALIZED;
- return Status::OK();
-}
-
-Status init1(InitializerContext*) {
- globalStates[1] = INITIALIZED;
- return Status::OK();
-}
-
-Status init2(InitializerContext*) {
- if (globalStates[0] != INITIALIZED || globalStates[1] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init2) one of 0 or 1 not already initialized");
- globalStates[2] = INITIALIZED;
- return Status::OK();
-}
-
-Status init3(InitializerContext*) {
- if (globalStates[0] != INITIALIZED || globalStates[2] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init3) one of 0 or 2 not already initialized");
- globalStates[3] = INITIALIZED;
- return Status::OK();
-}
-
-Status init4(InitializerContext*) {
- if (globalStates[1] != INITIALIZED || globalStates[2] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init4) one of 1 or 2 not already initialized");
- globalStates[4] = INITIALIZED;
- return Status::OK();
-}
-
-Status init5(InitializerContext*) {
- if (globalStates[3] != INITIALIZED || globalStates[4] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init5) one of 3 or 4 not already initialized");
- globalStates[5] = INITIALIZED;
- return Status::OK();
-}
-
-Status init6(InitializerContext*) {
- if (globalStates[4] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init6) 4 not already initialized");
- globalStates[6] = INITIALIZED;
- return Status::OK();
-}
-
-Status init7(InitializerContext*) {
- if (globalStates[3] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init7) 3 not already initialized");
- globalStates[7] = INITIALIZED;
- return Status::OK();
-}
-
-Status init8(InitializerContext*) {
- if (globalStates[5] != INITIALIZED || globalStates[6] != INITIALIZED ||
- globalStates[7] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(init8) one of 5, 6, 7 not already initialized");
- globalStates[8] = INITIALIZED;
- return Status::OK();
-}
-
-Status deinit8(DeinitializerContext*) {
- if (globalStates[8] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit8) 8 not initialized");
- globalStates[8] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit7(DeinitializerContext*) {
- if (globalStates[7] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit7) 7 not initialized");
- if (globalStates[8] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit7) 8 not already deinitialized");
- globalStates[7] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit6(DeinitializerContext*) {
- if (globalStates[6] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit6) 6 not initialized");
- if (globalStates[8] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit6) 8 not already deinitialized");
- globalStates[6] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit5(DeinitializerContext*) {
- if (globalStates[5] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit5) 5 not initialized");
- if (globalStates[8] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit5) 8 not already deinitialized");
- globalStates[5] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit4(DeinitializerContext*) {
- if (globalStates[4] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit4) 4 not initialized");
- if (globalStates[5] != DEINITIALIZED || globalStates[6] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError,
- "(deinit4) one of 5 or 6 not already deinitialized");
- globalStates[4] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit3(DeinitializerContext*) {
- if (globalStates[3] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit3) 3 not initialized");
- if (globalStates[5] != DEINITIALIZED || globalStates[7] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError,
- "(deinit3) one of 5 or 7 not already deinitialized");
- globalStates[3] = DEINITIALIZED;
- return Status::OK();
-}
-
-Status deinit2(DeinitializerContext*) {
- if (globalStates[2] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit2) 2 not initialized");
- if (globalStates[3] != DEINITIALIZED || globalStates[4] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError,
- "(deinit2) one of 3 or 4 not already deinitialized");
- globalStates[2] = DEINITIALIZED;
- return Status::OK();
-}
+TEST_F(InitializerTest, SuccessfulInitializationAndDeinitialization) {
+ Initializer initializer;
+ constructDependencyGraph(initializer);
-Status deinit1(DeinitializerContext*) {
- if (globalStates[1] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit1) 1 not initialized");
- if (globalStates[2] != DEINITIALIZED || globalStates[4] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError,
- "(deinit1) one of 2 or 4 not already deinitialized");
- globalStates[1] = DEINITIALIZED;
- return Status::OK();
-}
+ initializer.executeInitializers({});
+ for (size_t i = 0; i != states.size(); ++i)
+ ASSERT_EQ(states[i], kInitialized) << i;
-Status deinit0(DeinitializerContext*) {
- if (globalStates[0] != INITIALIZED)
- return Status(ErrorCodes::UnknownError, "(deinit0) 0 not initialized");
- if (globalStates[2] != DEINITIALIZED || globalStates[3] != DEINITIALIZED)
- return Status(ErrorCodes::UnknownError,
- "(deinit0) one of 2 or 3 not already deinitialized");
- globalStates[0] = DEINITIALIZED;
- return Status::OK();
+ initializer.executeDeinitializers();
+ for (size_t i = 0; i != states.size(); ++i)
+ ASSERT_EQ(states[i], kDeinitialized) << i;
}
-void clearCounts() {
- for (size_t i = 0; i < 9; ++i)
- globalStates[i] = UNSET;
+TEST_F(InitializerTest, Init5Misimplemented) {
+ auto specs = makeDependencyGraphSpecs(graph);
+ for (auto&& spec : specs)
+ spec.deinit = deinitNoop;
+ specs[5].init = initNoop;
+ Initializer initializer;
+ constructDependencyGraph(initializer, specs);
+
+ ASSERT_THROWS_CODE(initializer.executeInitializers({}), DBException, ErrorCodes::UnknownError);
+
+ std::vector<State> expected{
+ kInitialized,
+ kInitialized,
+ kInitialized,
+ kInitialized,
+ kInitialized,
+ kUnset, // 5: noop init
+ kInitialized,
+ kInitialized,
+ kUnset, // 8: depends on states[5] == kIninitialized, so fails.
+ };
+ for (size_t i = 0; i != states.size(); ++i)
+ ASSERT_EQ(states[i], expected[i]) << i;
}
-void constructNormalDependencyGraph(Initializer* initializer) {
- CONSTRUCT_DEPENDENCY_GRAPH(initializer->getInitializerDependencyGraph(),
- init0,
- deinit0,
- init1,
- deinit1,
- init2,
- deinit2,
- init3,
- deinit3,
- init4,
- deinit4,
- init5,
- deinit5,
- init6,
- deinit6,
- init7,
- deinit7,
- init8,
- deinit8);
+TEST_F(InitializerTest, Deinit2Misimplemented) {
+ auto specs = makeDependencyGraphSpecs(graph);
+ specs[2].deinit = deinitNoop;
+ Initializer initializer;
+ constructDependencyGraph(initializer, specs);
+
+ initializer.executeInitializers({});
+ for (size_t i = 0; i != states.size(); ++i)
+ ASSERT_EQ(states[i], kInitialized) << i;
+
+ ASSERT_THROWS_CODE(initializer.executeDeinitializers(), DBException, ErrorCodes::UnknownError);
+
+ // Since [2]'s deinit has been replaced with deinitNoop, it does not set states[2]
+ // to kDeinitialized. Its dependents [0] and [1] will check for this and fail
+ // with UnknownError, also remaining in the kInitialized state themselves.
+ std::vector<State> expected{
+ kInitialized, // 0: depends on states[2] == kDeinitialized, so fails
+ kInitialized, // 1: depends on states[2] == kDeinitialized, so fails
+ kInitialized, // 2: noop deinit
+ kDeinitialized,
+ kDeinitialized,
+ kDeinitialized,
+ kDeinitialized,
+ kDeinitialized,
+ kDeinitialized,
+ };
+ for (size_t i = 0; i != states.size(); ++i)
+ ASSERT_EQ(states[i], expected[i]) << i;
}
-TEST(InitializerTest, SuccessfulInitializationAndDeinitialization) {
+TEST_F(InitializerTest, InsertNullFunctionFails) {
Initializer initializer;
- constructNormalDependencyGraph(&initializer);
- clearCounts();
-
- ASSERT_OK(initializer.executeInitializers({}));
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(INITIALIZED, globalStates[i]);
-
- ASSERT_OK(initializer.executeDeinitializers());
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(DEINITIALIZED, globalStates[i]);
+ ASSERT_THROWS_CODE(initializer.addInitializer("A", nullptr, nullptr, {}, {}),
+ DBException,
+ ErrorCodes::BadValue);
}
-TEST(InitializerTest, Init5Misimplemented) {
+TEST_F(InitializerTest, CannotAddInitializerAfterInitializing) {
Initializer initializer;
- CONSTRUCT_DEPENDENCY_GRAPH(initializer.getInitializerDependencyGraph(),
- init0,
- deinitNoop,
- init1,
- deinitNoop,
- init2,
- deinitNoop,
- init3,
- deinitNoop,
- init4,
- deinitNoop,
- initNoop,
- deinitNoop,
- init6,
- deinitNoop,
- init7,
- deinitNoop,
- init8,
- deinitNoop);
- clearCounts();
-
- ASSERT_EQUALS(ErrorCodes::UnknownError, initializer.executeInitializers({}));
-
- ASSERT_EQUALS(INITIALIZED, globalStates[0]);
- ASSERT_EQUALS(INITIALIZED, globalStates[1]);
- ASSERT_EQUALS(INITIALIZED, globalStates[2]);
- ASSERT_EQUALS(INITIALIZED, globalStates[3]);
- ASSERT_EQUALS(INITIALIZED, globalStates[4]);
- ASSERT_EQUALS(UNSET, globalStates[5]);
- ASSERT_EQUALS(INITIALIZED, globalStates[6]);
- ASSERT_EQUALS(INITIALIZED, globalStates[7]);
- ASSERT_EQUALS(UNSET, globalStates[8]);
+ constructDependencyGraph(initializer);
+ initializer.executeInitializers({});
+ ASSERT_THROWS_CODE(initializer.addInitializer("test", initNoop, deinitNoop, {}, {}),
+ DBException,
+ ErrorCodes::CannotMutateObject);
}
-TEST(InitializerTest, Deinit2Misimplemented) {
+TEST_F(InitializerTest, CannotDoubleInitialize) {
Initializer initializer;
- CONSTRUCT_DEPENDENCY_GRAPH(initializer.getInitializerDependencyGraph(),
- init0,
- deinit0,
- init1,
- deinit1,
- init2,
- deinitNoop,
- init3,
- deinit3,
- init4,
- deinit4,
- init5,
- deinit5,
- init6,
- deinit6,
- init7,
- deinit7,
- init8,
- deinit8);
- clearCounts();
-
- ASSERT_OK(initializer.executeInitializers({}));
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(INITIALIZED, globalStates[i]);
-
- ASSERT_EQUALS(ErrorCodes::UnknownError, initializer.executeDeinitializers());
-
- ASSERT_EQUALS(DEINITIALIZED, globalStates[8]);
- ASSERT_EQUALS(DEINITIALIZED, globalStates[7]);
- ASSERT_EQUALS(DEINITIALIZED, globalStates[6]);
- ASSERT_EQUALS(DEINITIALIZED, globalStates[5]);
- ASSERT_EQUALS(DEINITIALIZED, globalStates[4]);
- ASSERT_EQUALS(DEINITIALIZED, globalStates[3]);
- ASSERT_EQUALS(INITIALIZED, globalStates[2]);
- ASSERT_EQUALS(INITIALIZED, globalStates[1]);
- ASSERT_EQUALS(INITIALIZED, globalStates[0]);
+ constructDependencyGraph(initializer);
+ initializer.executeInitializers({});
+ ASSERT_THROWS_CODE(
+ initializer.executeInitializers({}), DBException, ErrorCodes::IllegalOperation);
}
-DEATH_TEST(InitializerTest, CannotAddInitializerAfterInitializing, "!frozen()") {
+TEST_F(InitializerTest, RepeatingInitializerCycle) {
Initializer initializer;
- constructNormalDependencyGraph(&initializer);
- clearCounts();
-
- ASSERT_OK(initializer.executeInitializers({}));
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(INITIALIZED, globalStates[i]);
-
- ASSERT_ADD_INITIALIZER(initializer.getInitializerDependencyGraph(),
- "test",
- initNoop,
- deinitNoop,
- MONGO_NO_PREREQUISITES,
- MONGO_NO_DEPENDENTS);
+ constructDependencyGraph(initializer);
+ initializer.executeInitializers({});
+ initializer.executeDeinitializers();
+ initializer.executeInitializers({});
+ initializer.executeDeinitializers();
}
-DEATH_TEST(InitializerTest, CannotDoubleInitialize, "invalid initializer state transition") {
+TEST_F(InitializerTest, CannotDeinitializeWithoutInitialize) {
Initializer initializer;
- constructNormalDependencyGraph(&initializer);
- clearCounts();
-
- ASSERT_OK(initializer.executeInitializers({}));
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(INITIALIZED, globalStates[i]);
-
- initializer.executeInitializers({}).ignore();
+ constructDependencyGraph(initializer);
+ ASSERT_THROWS_CODE(
+ initializer.executeDeinitializers(), DBException, ErrorCodes::IllegalOperation);
}
-DEATH_TEST(InitializerTest,
- CannotDeinitializeWithoutInitialize,
- "invalid initializer state transition") {
+TEST_F(InitializerTest, CannotDoubleDeinitialize) {
Initializer initializer;
- constructNormalDependencyGraph(&initializer);
- clearCounts();
-
- initializer.executeDeinitializers().ignore();
+ constructDependencyGraph(initializer);
+ initializer.executeInitializers({});
+ initializer.executeDeinitializers();
+ ASSERT_THROWS_CODE(
+ initializer.executeDeinitializers(), DBException, ErrorCodes::IllegalOperation);
}
-DEATH_TEST(InitializerTest, CannotDoubleDeinitialize, "invalid initializer state transition") {
+TEST_F(InitializerTest, CannotAddWhenFrozen) {
Initializer initializer;
- constructNormalDependencyGraph(&initializer);
- clearCounts();
-
- ASSERT_OK(initializer.executeInitializers({}));
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(INITIALIZED, globalStates[i]);
-
- ASSERT_OK(initializer.executeDeinitializers());
-
- for (int i = 0; i < 9; ++i)
- ASSERT_EQUALS(DEINITIALIZED, globalStates[i]);
-
- initializer.executeDeinitializers().ignore();
+ constructDependencyGraph(initializer);
+ initializer.executeInitializers({});
+ initializer.executeDeinitializers();
+ ASSERT_THROWS_CODE(initializer.addInitializer("A", initNoop, nullptr, {}, {}),
+ DBException,
+ ErrorCodes::CannotMutateObject);
}
} // namespace
diff --git a/src/mongo/base/secure_allocator.cpp b/src/mongo/base/secure_allocator.cpp
index 299751f553e..fca3e4ab82c 100644
--- a/src/mongo/base/secure_allocator.cpp
+++ b/src/mongo/base/secure_allocator.cpp
@@ -335,14 +335,12 @@ std::shared_ptr<Allocation> lastAllocation = nullptr;
} // namespace
-MONGO_INITIALIZER_GENERAL(SecureAllocator, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS)
+MONGO_INITIALIZER_GENERAL(SecureAllocator, (), ())
(InitializerContext* context) {
#if _WIN32
// Enable the increase working set size privilege in our access token.
EnablePrivilege(SE_INC_WORKING_SET_NAME);
#endif
-
- return Status::OK();
}
namespace secure_allocator_details {
diff --git a/src/mongo/base/validate_locale.cpp b/src/mongo/base/validate_locale.cpp
index 6159764ba7a..7a102f5bf24 100644
--- a/src/mongo/base/validate_locale.cpp
+++ b/src/mongo/base/validate_locale.cpp
@@ -38,20 +38,18 @@
namespace mongo {
-MONGO_INITIALIZER_GENERAL(ValidateLocale, MONGO_NO_PREREQUISITES, MONGO_DEFAULT_PREREQUISITES)
+MONGO_INITIALIZER_GENERAL(ValidateLocale, (), ("default"))
(InitializerContext*) {
try {
// Validate that boost can correctly load the user's locale
boost::filesystem::path("/").has_root_directory();
} catch (const std::runtime_error& e) {
- return Status(
- ErrorCodes::BadValue,
- str::stream()
- << "Invalid or no user locale set. "
+ std::string extraHint;
#ifndef _WIN32
- << " Please ensure LANG and/or LC_* environment variables are set correctly. "
+ extraHint = " Please ensure LANG and/or LC_* environment variables are set correctly. ";
#endif
- << e.what());
+ uasserted(ErrorCodes::BadValue,
+ str::stream() << "Invalid or no user locale set. " << extraHint << e.what());
}
#ifdef _WIN32
@@ -59,8 +57,6 @@ MONGO_INITIALIZER_GENERAL(ValidateLocale, MONGO_NO_PREREQUISITES, MONGO_DEFAULT_
std::locale loc(std::locale(""), new std::codecvt_utf8_utf16<wchar_t>);
boost::filesystem::path::imbue(loc);
#endif
-
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index 70c8b056a70..37fed3b5831 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -53,12 +53,11 @@ const std::size_t kIncrementOffset = kInstanceUniqueOffset + OID::kInstanceUniqu
OID::InstanceUnique _instanceUnique;
} // namespace
-MONGO_INITIALIZER_GENERAL(OIDGeneration, MONGO_NO_PREREQUISITES, ("default"))
+MONGO_INITIALIZER_GENERAL(OIDGeneration, (), ("default"))
(InitializerContext* context) {
SecureRandom entropy;
counter = std::make_unique<AtomicWord<int64_t>>(entropy.nextInt64());
_instanceUnique = OID::InstanceUnique::generate(entropy);
- return Status::OK();
}
OID::Increment OID::Increment::next() {
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp
index f742a8dcef8..e3a5a925636 100644
--- a/src/mongo/client/connpool.cpp
+++ b/src/mongo/client/connpool.cpp
@@ -739,7 +739,6 @@ MONGO_INITIALIZER(SetupDBClientBaseWithConnection)(InitializerContext*) {
cb(conn.get());
conn.done();
};
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/client/cyrus_sasl_client_session.cpp b/src/mongo/client/cyrus_sasl_client_session.cpp
index cf40a491f25..84ae1ab0b5a 100644
--- a/src/mongo/client/cyrus_sasl_client_session.cpp
+++ b/src/mongo/client/cyrus_sasl_client_session.cpp
@@ -114,7 +114,6 @@ MONGO_INITIALIZER(CyrusSaslAllocatorsAndMutexes)(InitializerContext*) {
sasl_set_alloc(saslOurMalloc, saslOurCalloc, saslOurRealloc, free);
sasl_set_mutex(saslMutexAlloc, saslMutexLock, saslMutexUnlock, saslMutexFree);
- return Status::OK();
}
int saslClientLogSwallow(void* context, int priority, const char* message) throw() {
@@ -145,13 +144,12 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(CyrusSaslClientContext,
// TODO: Call sasl_client_done() at shutdown when we have a story for orderly shutdown.
int result = sasl_client_init(saslClientGlobalCallbacks);
if (result != SASL_OK) {
- return Status(ErrorCodes::UnknownError,
- str::stream() << "Could not initialize sasl client components ("
- << sasl_errstring(result, nullptr, nullptr) << ")");
+ uasserted(ErrorCodes::UnknownError,
+ str::stream() << "Could not initialize sasl client components ("
+ << sasl_errstring(result, nullptr, nullptr) << ")");
}
SaslClientSession::create = createCyrusSaslClientSession;
- return Status::OK();
}
/**
diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp
index 3765148e8ff..2ec975e1cb4 100644
--- a/src/mongo/client/dbclient_rs_test.cpp
+++ b/src/mongo/client/dbclient_rs_test.cpp
@@ -65,7 +65,6 @@ using std::vector;
MONGO_INITIALIZER(DisableReplicaSetMonitorRefreshRetries)(InitializerContext*) {
ScanningReplicaSetMonitor::disableRefreshRetries_forTest();
- return Status::OK();
}
/**
diff --git a/src/mongo/client/global_conn_pool.cpp b/src/mongo/client/global_conn_pool.cpp
index d126fb87e76..0533c1a760c 100644
--- a/src/mongo/client/global_conn_pool.cpp
+++ b/src/mongo/client/global_conn_pool.cpp
@@ -43,8 +43,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(InitializeGlobalConnectionPool, ("EndStartu
globalConnPool.setMaxPoolSize(maxConnsPerHost);
globalConnPool.setMaxInUse(maxInUseConnsPerHost);
globalConnPool.setIdleTimeout(globalConnPoolIdleTimeout);
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/client/native_sasl_client_session.cpp b/src/mongo/client/native_sasl_client_session.cpp
index 169cc73c6ca..3d37f9db9cc 100644
--- a/src/mongo/client/native_sasl_client_session.cpp
+++ b/src/mongo/client/native_sasl_client_session.cpp
@@ -54,7 +54,6 @@ SaslClientSession* createNativeSaslClientSession(const std::string mech) {
MONGO_INITIALIZER(NativeSaslClientContext)(InitializerContext* context) {
SaslClientSession::create = createNativeSaslClientSession;
- return Status::OK();
}
// Global cache for SCRAM-SHA-1/256 credentials
diff --git a/src/mongo/client/sasl_client_authenticate_impl.cpp b/src/mongo/client/sasl_client_authenticate_impl.cpp
index 1e06f3ee9ff..323f7a6b321 100644
--- a/src/mongo/client/sasl_client_authenticate_impl.cpp
+++ b/src/mongo/client/sasl_client_authenticate_impl.cpp
@@ -289,7 +289,6 @@ Future<void> saslClientAuthenticateImpl(auth::RunCommandHook runCommand,
MONGO_INITIALIZER(SaslClientAuthenticateFunction)(InitializerContext* context) {
saslClientAuthenticate = saslClientAuthenticateImpl;
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/client/sasl_sspi.cpp b/src/mongo/client/sasl_sspi.cpp
index 42963e68b0f..f904eaa24a7 100644
--- a/src/mongo/client/sasl_sspi.cpp
+++ b/src/mongo/client/sasl_sspi.cpp
@@ -476,12 +476,10 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SaslSspiClientPlugin,
(InitializerContext*) {
int ret = sasl_client_add_plugin(sspiPluginName, sspiClientPluginInit);
if (SASL_OK != ret) {
- return Status(ErrorCodes::UnknownError,
- str::stream() << "could not add SASL Client SSPI plugin " << sspiPluginName
- << ": " << sasl_errstring(ret, nullptr, nullptr));
+ uasserted(ErrorCodes::UnknownError,
+ str::stream() << "could not add SASL Client SSPI plugin " << sspiPluginName
+ << ": " << sasl_errstring(ret, nullptr, nullptr));
}
-
- return Status::OK();
}
MONGO_INITIALIZER_WITH_PREREQUISITES(SaslPlainClientPlugin,
@@ -489,12 +487,10 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SaslPlainClientPlugin,
(InitializerContext*) {
int ret = sasl_client_add_plugin("PLAIN", plain_client_plug_init);
if (SASL_OK != ret) {
- return Status(ErrorCodes::UnknownError,
- str::stream() << "Could not add SASL Client PLAIN plugin " << sspiPluginName
- << ": " << sasl_errstring(ret, nullptr, nullptr));
+ uasserted(ErrorCodes::UnknownError,
+ str::stream() << "Could not add SASL Client PLAIN plugin " << sspiPluginName
+ << ": " << sasl_errstring(ret, nullptr, nullptr));
}
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/client/sasl_sspi_options.cpp b/src/mongo/client/sasl_sspi_options.cpp
index 378ae103de0..4c548d6ebff 100644
--- a/src/mongo/client/sasl_sspi_options.cpp
+++ b/src/mongo/client/sasl_sspi_options.cpp
@@ -64,7 +64,7 @@ Status storeSASLSSPIOptions(const moe::Environment& params) {
}
MONGO_STARTUP_OPTIONS_STORE(SASLSSPIOptions)(InitializerContext* context) {
- return storeSASLSSPIOptions(moe::startupOptionsParsed);
+ uassertStatusOK(storeSASLSSPIOptions(moe::startupOptionsParsed));
}
} // namespace mongo
diff --git a/src/mongo/crypto/symmetric_crypto.cpp b/src/mongo/crypto/symmetric_crypto.cpp
index b03cae0cd6b..825fb21efd7 100644
--- a/src/mongo/crypto/symmetric_crypto.cpp
+++ b/src/mongo/crypto/symmetric_crypto.cpp
@@ -47,9 +47,7 @@
namespace mongo {
namespace crypto {
-MONGO_INITIALIZER(CreateKeyEntropySource)(InitializerContext* context) {
- return Status::OK();
-}
+MONGO_INITIALIZER(CreateKeyEntropySource)(InitializerContext* context) {}
size_t aesGetIVSize(crypto::aesMode mode) {
switch (mode) {
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index 50401c7809a..729df9178a7 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -89,10 +89,8 @@ MONGO_INITIALIZER_GENERAL(SetupInternalSecurityUser,
}
internalSecurity.user = user;
-
- return Status::OK();
} catch (...) {
- return exceptionToStatus();
+ uassertStatusOK(exceptionToStatus());
}
class PinnedUserSetParameter {
diff --git a/src/mongo/db/auth/builtin_roles.cpp b/src/mongo/db/auth/builtin_roles.cpp
index 622ba2f5a87..037f7765c35 100644
--- a/src/mongo/db/auth/builtin_roles.cpp
+++ b/src/mongo/db/auth/builtin_roles.cpp
@@ -259,8 +259,6 @@ MONGO_INITIALIZER(AuthorizationBuiltinRoles)(InitializerContext* context) {
<< ActionType::splitVector
<< ActionType::refineCollectionShardKey
<< ActionType::reshardCollection;
-
- return Status::OK();
}
// clang-format on
diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp
index d352eeeb082..e89dda82f7c 100644
--- a/src/mongo/db/auth/sasl_commands.cpp
+++ b/src/mongo/db/auth/sasl_commands.cpp
@@ -433,8 +433,6 @@ MONGO_INITIALIZER(PreSaslCommands)
(InitializerContext*) {
if (!sequenceContains(saslGlobalParams.authenticationMechanisms, kX509AuthMechanism))
disableAuthMechanism(kX509AuthMechanism);
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/auth/sasl_options.cpp b/src/mongo/db/auth/sasl_options.cpp
index d390ad99524..63414acc3a1 100644
--- a/src/mongo/db/auth/sasl_options.cpp
+++ b/src/mongo/db/auth/sasl_options.cpp
@@ -52,7 +52,6 @@ namespace {
MONGO_INITIALIZER_WITH_PREREQUISITES(InitSpeculativeCounters, ("EndStartupOptionStorage"))
(InitializerContext*) {
authCounter.initializeMechanismMap(saslGlobalParams.authenticationMechanisms);
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/auth/sasl_options_init.cpp b/src/mongo/db/auth/sasl_options_init.cpp
index 21050612cbd..6d22544af6d 100644
--- a/src/mongo/db/auth/sasl_options_init.cpp
+++ b/src/mongo/db/auth/sasl_options_init.cpp
@@ -89,7 +89,7 @@ Status storeSASLOptions(const moe::Environment& params) {
}
MONGO_INITIALIZER_GENERAL(StoreSASLOptions, ("CoreOptions_Store"), ("EndStartupOptionStorage"))
-(InitializerContext* const context) {
- return storeSASLOptions(moe::startupOptionsParsed);
+(InitializerContext*) {
+ uassertStatusOK(storeSASLOptions(moe::startupOptionsParsed));
}
} // namespace mongo
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 9043b84612a..140d7bccee4 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -1127,19 +1127,19 @@ private:
CommandRegistry* globalCommandRegistry();
/**
- * Creates a test command object of type CmdType if test commands are enabled for this process.
- * Prefer this syntax to using MONGO_INITIALIZER directly.
- * The created Command object is "leaked" intentionally, since it will register itself.
+ * Creates a test command object of type CmdType if test commands are enabled
+ * for this process. Prefer this syntax to using MONGO_INITIALIZER directly.
+ * The created Command object is "leaked" intentionally, since it will register
+ * itself.
+ *
+ * The command objects will be created after the "default" initializer, and all
+ * startup option processing happens prior to "default" (see base/init.h).
*/
-#define MONGO_REGISTER_TEST_COMMAND(CmdType) \
- MONGO_INITIALIZER_WITH_PREREQUISITES( \
- RegisterTestCommand_##CmdType, \
- (::mongo::defaultInitializerName().c_str(), "EndStartupOptionHandling")) \
- (InitializerContext*) { \
- if (getTestCommandsEnabled()) { \
- new CmdType(); \
- } \
- return Status::OK(); \
+#define MONGO_REGISTER_TEST_COMMAND(CmdType) \
+ MONGO_INITIALIZER(RegisterTestCommand_##CmdType)(InitializerContext*) { \
+ if (getTestCommandsEnabled()) { \
+ new CmdType(); \
+ } \
}
} // namespace mongo
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp
index cc50ca5bf3a..5573e813b7b 100644
--- a/src/mongo/db/commands/fsync.cpp
+++ b/src/mongo/db/commands/fsync.cpp
@@ -448,7 +448,6 @@ void FSyncLockThread::run() {
MONGO_INITIALIZER(fsyncLockedForWriting)(InitializerContext* context) {
setLockedForWritingImpl([]() { return fsyncCmd.fsyncLocked(); });
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index ec7529c608e..c9a82127980 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -94,13 +94,11 @@ static Status getQuerySettingsAndPlanCache(OperationContext* opCtx,
// available to the client.
//
-MONGO_INITIALIZER_WITH_PREREQUISITES(SetupIndexFilterCommands, MONGO_NO_PREREQUISITES)
+MONGO_INITIALIZER_WITH_PREREQUISITES(SetupIndexFilterCommands, ())
(InitializerContext* context) {
new ListFilters();
new ClearFilters();
new SetFilter();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp
index 0a118ffa566..c2b5e716523 100644
--- a/src/mongo/db/commands/isself.cpp
+++ b/src/mongo/db/commands/isself.cpp
@@ -69,7 +69,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(RegisterIsSelfCommand, ("GenerateInstanceId
(InitializerContext* context) {
// Leaked intentionally: a Command registers itself when constructed
new IsSelfCommand();
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp
index 74aeecbbc64..2188631a109 100644
--- a/src/mongo/db/commands/oplog_note.cpp
+++ b/src/mongo/db/commands/oplog_note.cpp
@@ -154,7 +154,6 @@ public:
MONGO_INITIALIZER(RegisterAppendOpLogNoteCmd)(InitializerContext* context) {
new AppendOplogNoteCmd();
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 382b8978400..58d75f67e71 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -34,7 +34,6 @@
#include "mongo/platform/basic.h"
#include "mongo/base/init.h"
-#include "mongo/base/initializer_context.h"
#include "mongo/db/catalog/capped_utils.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/client.h"
diff --git a/src/mongo/db/commands/top_command.cpp b/src/mongo/db/commands/top_command.cpp
index 328b318a73f..50999b993c1 100644
--- a/src/mongo/db/commands/top_command.cpp
+++ b/src/mongo/db/commands/top_command.cpp
@@ -88,7 +88,5 @@ public:
MONGO_INITIALIZER(RegisterTopCommand)(InitializerContext* context) {
new TopCommand();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/exec/sbe/stages/exchange.cpp b/src/mongo/db/exec/sbe/stages/exchange.cpp
index af748cb4089..a2e932d3553 100644
--- a/src/mongo/db/exec/sbe/stages/exchange.cpp
+++ b/src/mongo/db/exec/sbe/stages/exchange.cpp
@@ -45,8 +45,6 @@ MONGO_INITIALIZER(s_globalThreadPool)(InitializerContext* context) {
options.onCreateThread = [](const std::string& name) { Client::initThread(name); };
s_globalThreadPool = std::make_unique<ThreadPool>(options);
s_globalThreadPool->startup();
-
- return Status::OK();
}
ExchangePipe::ExchangePipe(size_t size) {
diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp
index 4225e71efbb..e074e73c7f0 100644
--- a/src/mongo/db/free_mon/free_mon_controller_test.cpp
+++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp
@@ -41,7 +41,6 @@
#include "mongo/db/free_mon/free_mon_storage.h"
#include "mongo/base/data_type_validated.h"
-#include "mongo/base/deinitializer_context.h"
#include "mongo/bson/bson_validate.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobjbuilder.h"
diff --git a/src/mongo/db/free_mon/free_mon_options.cpp b/src/mongo/db/free_mon/free_mon_options.cpp
index 173d11847e2..df1255e1200 100644
--- a/src/mongo/db/free_mon/free_mon_options.cpp
+++ b/src/mongo/db/free_mon/free_mon_options.cpp
@@ -35,7 +35,6 @@
#include "mongo/db/free_mon/free_mon_options.h"
#include "mongo/base/error_codes.h"
-#include "mongo/base/initializer_context.h"
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
#include "mongo/base/string_data.h"
@@ -92,8 +91,8 @@ Status storeFreeMonitoringOptions(const moe::Environment& params) {
return Status::OK();
}
-MONGO_STARTUP_OPTIONS_STORE(FreeMonitoringOptions)(InitializerContext* /*unused*/) {
- return storeFreeMonitoringOptions(moe::startupOptionsParsed);
+MONGO_STARTUP_OPTIONS_STORE(FreeMonitoringOptions)(InitializerContext*) {
+ uassertStatusOK(storeFreeMonitoringOptions(moe::startupOptionsParsed));
}
} // namespace
diff --git a/src/mongo/db/ftdc/ftdc_commands.cpp b/src/mongo/db/ftdc/ftdc_commands.cpp
index bd403010ebc..aa274c1858e 100644
--- a/src/mongo/db/ftdc/ftdc_commands.cpp
+++ b/src/mongo/db/ftdc/ftdc_commands.cpp
@@ -106,8 +106,6 @@ Command* ftdcCommand;
MONGO_INITIALIZER(CreateDiagnosticDataCommand)(InitializerContext* context) {
ftdcCommand = new GetDiagnosticDataCommand();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/fts/fts_index_format.cpp b/src/mongo/db/fts/fts_index_format.cpp
index a6f12f6cef5..418ea2d8629 100644
--- a/src/mongo/db/fts/fts_index_format.cpp
+++ b/src/mongo/db/fts/fts_index_format.cpp
@@ -107,7 +107,6 @@ MONGO_INITIALIZER(FTSIndexFormat)(InitializerContext* context) {
b.appendNull("");
nullObj = b.obj();
nullElt = nullObj.firstElement();
- return Status::OK();
}
void FTSIndexFormat::getKeys(SharedBufferFragmentBuilder& pooledBufferBuilder,
diff --git a/src/mongo/db/fts/stop_words.cpp b/src/mongo/db/fts/stop_words.cpp
index 39be67707bc..9c415a2d262 100644
--- a/src/mongo/db/fts/stop_words.cpp
+++ b/src/mongo/db/fts/stop_words.cpp
@@ -68,7 +68,6 @@ MONGO_INITIALIZER(StopWords)(InitializerContext* context) {
for (StringMap<std::set<std::string>>::const_iterator i = raw.begin(); i != raw.end(); ++i) {
StopWordsMap[i->first].reset(new StopWords(i->second));
}
- return Status::OK();
}
} // namespace fts
} // namespace mongo
diff --git a/src/mongo/db/geo/r2_region_coverer_test.cpp b/src/mongo/db/geo/r2_region_coverer_test.cpp
index 806fc9d4e37..0a499f2a74a 100644
--- a/src/mongo/db/geo/r2_region_coverer_test.cpp
+++ b/src/mongo/db/geo/r2_region_coverer_test.cpp
@@ -59,7 +59,6 @@ MONGO_INITIALIZER(R2CellUnion_Test)(InitializerContext* context) {
}
generator.seed(seed);
LOGV2(20640, "R2CellUnion Test - Random Number Generator Seed: {seed}", "seed"_attr = seed);
- return Status::OK();
}
// Returns an integral number in [lower, upper]
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index aef5a665d4f..6dd9a7ef69d 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -298,8 +298,8 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
if (serverGlobalParams.logWithSyslog) {
#ifdef _WIN32
- return Status(ErrorCodes::InternalError,
- "Syslog requested in Windows build; command line processor logic error");
+ uasserted(ErrorCodes::InternalError,
+ "Syslog requested in Windows build; command line processor logic error");
#else
lv2Config.consoleEnabled = false;
lv2Config.syslogEnabled = true;
@@ -316,16 +316,16 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
try {
exists = boost::filesystem::exists(absoluteLogpath);
} catch (boost::filesystem::filesystem_error& e) {
- return Status(ErrorCodes::FileNotOpen,
- str::stream() << "Failed probe for \"" << absoluteLogpath
- << "\": " << e.code().message());
+ uasserted(ErrorCodes::FileNotOpen,
+ str::stream() << "Failed probe for \"" << absoluteLogpath
+ << "\": " << e.code().message());
}
if (exists) {
if (boost::filesystem::is_directory(absoluteLogpath)) {
- return Status(ErrorCodes::FileNotOpen,
- str::stream() << "logpath \"" << absoluteLogpath
- << "\" should name a file, not a directory.");
+ uasserted(ErrorCodes::FileNotOpen,
+ str::stream() << "logpath \"" << absoluteLogpath
+ << "\" should name a file, not a directory.");
}
if (!serverGlobalParams.logAppend && boost::filesystem::is_regular(absoluteLogpath)) {
@@ -339,12 +339,11 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
"oldLogPath"_attr = absoluteLogpath,
"newLogPath"_attr = renameTarget);
} else {
- return Status(ErrorCodes::FileRenameFailed,
- str::stream()
- << "Could not rename preexisting log file \""
- << absoluteLogpath << "\" to \"" << renameTarget
- << "\"; run with --logappend or manually remove file: "
- << ec.message());
+ uasserted(ErrorCodes::FileRenameFailed,
+ str::stream() << "Could not rename preexisting log file \""
+ << absoluteLogpath << "\" to \"" << renameTarget
+ << "\"; run with --logappend or manually remove file: "
+ << ec.message());
}
}
}
@@ -369,8 +368,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
if (result.isOK() && writeServerRestartedAfterLogConfig) {
LOGV2(20698, "***** SERVER RESTARTED *****");
}
-
- return result;
+ uassertStatusOK(result);
}
/**
@@ -389,8 +387,7 @@ static void shortCircuitExit() {
MONGO_INITIALIZER(RegisterShortCircuitExitHandler)(InitializerContext*) {
if (std::atexit(&shortCircuitExit) != 0)
- return Status(ErrorCodes::InternalError, "Failed setting short-circuit exit handler.");
- return Status::OK();
+ uasserted(ErrorCodes::InternalError, "Failed setting short-circuit exit handler.");
}
bool initializeServerGlobalState(ServiceContext* service, PidFileWrite pidWrite) {
@@ -447,8 +444,6 @@ MONGO_INITIALIZER_GENERAL(MungeUmask, ("EndStartupOptionHandling"), ("ServerLogR
// in order to pull out the user portion of the current umask.
umask((umask(S_IRWXU | S_IRWXG | S_IRWXO) & S_IRWXU) | getUmaskOverride());
}
-
- return Status::OK();
}
} // namespace
#endif
diff --git a/src/mongo/db/logical_time_validator.cpp b/src/mongo/db/logical_time_validator.cpp
index d88bbbd3294..c56a3a146f0 100644
--- a/src/mongo/db/logical_time_validator.cpp
+++ b/src/mongo/db/logical_time_validator.cpp
@@ -64,7 +64,6 @@ MONGO_INITIALIZER(InitializeAdvanceClusterTimePrivilegeVector)(InitializerContex
ActionSet actions;
actions.addAction(ActionType::advanceClusterTime);
advanceClusterTimePrivilege.emplace_back(ResourcePattern::forClusterResource(), actions);
- return Status::OK();
}
Milliseconds kRefreshIntervalIfErrored(200);
diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp
index e8d2acfd489..197cc481e3c 100644
--- a/src/mongo/db/matcher/expression_parser.cpp
+++ b/src/mongo/db/matcher/expression_parser.cpp
@@ -1981,7 +1981,6 @@ MONGO_INITIALIZER(PathlessOperatorMap)(InitializerContext* context) {
{"text", &parseText},
{"where", &parseWhere},
});
- return Status::OK();
}
// Maps from query operator string name to operator PathAcceptingKeyword.
@@ -2036,7 +2035,6 @@ MONGO_INITIALIZER(MatchExpressionParser)(InitializerContext* context) {
{"type", PathAcceptingKeyword::TYPE},
{"within", PathAcceptingKeyword::WITHIN},
});
- return Status::OK();
}
/**
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index b355becdf2a..2a3489eb2be 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -290,7 +290,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini
spec.isInternalClient = true;
WireSpec::instance().initialize(std::move(spec));
- return Status::OK();
}
void initializeCommandHooks(ServiceContext* serviceContext) {
@@ -812,7 +811,6 @@ ExitCode initService() {
MONGO_INITIALIZER_GENERAL(ForkServer, ("EndStartupOptionHandling"), ("default"))
(InitializerContext* context) {
mongo::forkServerOrDie();
- return Status::OK();
}
/*
@@ -1022,10 +1020,9 @@ void setUpObservers(ServiceContext* serviceContext) {
}
#ifdef MONGO_CONFIG_SSL
-MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManager"))
+MONGO_INITIALIZER_GENERAL(setSSLManagerType, (), ("SSLManager"))
(InitializerContext* context) {
isSSLServer = true;
- return Status::OK();
}
#endif
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index fbc888172cf..db09e05615f 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -695,7 +695,6 @@ MONGO_INITIALIZER(IgnoreEnableMajorityReadConcernWarning)
"Ignoring read concern override as config server requires majority read "
"concern");
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/mongod_options_init.cpp b/src/mongo/db/mongod_options_init.cpp
index 8d9a28d7dfe..34d0ac03e2d 100644
--- a/src/mongo/db/mongod_options_init.cpp
+++ b/src/mongo/db/mongod_options_init.cpp
@@ -38,7 +38,7 @@
namespace mongo {
MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongodOptions)(InitializerContext* context) {
- return addMongodOptions(&moe::startupOptions);
+ uassertStatusOK(addMongodOptions(&moe::startupOptions));
}
MONGO_INITIALIZER_GENERAL(MongodOptions,
@@ -50,23 +50,10 @@ MONGO_INITIALIZER_GENERAL(MongodOptions,
}
// 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 = moe::startupOptionsParsed.validate(false /*setValid*/);
- if (!ret.isOK()) {
- return ret;
- }
- ret = validateMongodOptions(moe::startupOptionsParsed);
- if (!ret.isOK()) {
- return ret;
- }
- ret = canonicalizeMongodOptions(&moe::startupOptionsParsed);
- if (!ret.isOK()) {
- return ret;
- }
- ret = moe::startupOptionsParsed.validate();
- if (!ret.isOK()) {
- return ret;
- }
- return Status::OK();
+ uassertStatusOK(moe::startupOptionsParsed.validate(false /*setValid*/));
+ uassertStatusOK(validateMongodOptions(moe::startupOptionsParsed));
+ uassertStatusOK(canonicalizeMongodOptions(&moe::startupOptionsParsed));
+ uassertStatusOK(moe::startupOptionsParsed.validate());
}
MONGO_INITIALIZER_GENERAL(CoreOptions_Store,
@@ -79,7 +66,6 @@ MONGO_INITIALIZER_GENERAL(CoreOptions_Store,
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
quickExit(EXIT_BADOPTIONS);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/pipeline/accumulation_statement.h b/src/mongo/db/pipeline/accumulation_statement.h
index 83f0ad5561c..3d1b3a69b98 100644
--- a/src/mongo/db/pipeline/accumulation_statement.h
+++ b/src/mongo/db/pipeline/accumulation_statement.h
@@ -46,13 +46,11 @@ namespace mongo {
#define REGISTER_ACCUMULATOR(key, factory) \
MONGO_INITIALIZER(addToAccumulatorFactoryMap_##key)(InitializerContext*) { \
AccumulationStatement::registerAccumulator("$" #key, (factory), boost::none); \
- return Status::OK(); \
}
#define REGISTER_ACCUMULATOR_WITH_MIN_VERSION(key, factory, minVersion) \
MONGO_INITIALIZER(addToAccumulatorFactoryMap_##key)(InitializerContext*) { \
AccumulationStatement::registerAccumulator("$" #key, (factory), (minVersion)); \
- return Status::OK(); \
}
/**
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index a1c65ea48d0..8aa736d4b9f 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -90,7 +90,7 @@ class Document;
#define REGISTER_DOCUMENT_SOURCE_CONDITIONALLY(key, liteParser, fullParser, minVersion, ...) \
MONGO_INITIALIZER(addToDocSourceParserMap_##key)(InitializerContext*) { \
if (!__VA_ARGS__) { \
- return Status::OK(); \
+ return; \
} \
auto fullParserWrapper = [](BSONElement stageSpec, \
const boost::intrusive_ptr<ExpressionContext>& expCtx) { \
@@ -99,7 +99,6 @@ class Document;
}; \
LiteParsedDocumentSource::registerParser("$" #key, liteParser); \
DocumentSource::registerParser("$" #key, fullParserWrapper, minVersion); \
- return Status::OK(); \
}
#define REGISTER_DOCUMENT_SOURCE(key, liteParser, fullParser) \
@@ -129,7 +128,6 @@ class Document;
MONGO_INITIALIZER(addAliasToDocSourceParserMap_##key)(InitializerContext*) { \
LiteParsedDocumentSource::registerParser("$" #key, (liteParser)); \
DocumentSource::registerParser("$" #key, (fullParser), boost::none); \
- return Status::OK(); \
}
class DocumentSource : public RefCountable {
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 06481c5d953..9fcfad4daff 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -6715,7 +6715,6 @@ void ExpressionToHashedIndexKey::_doAddDependencies(DepsTracker* deps) const {
MONGO_INITIALIZER(expressionParserMap)(InitializerContext*) {
// Nothing to do. This initializer exists to tie together all the individual initializers
// defined by REGISTER_EXPRESSION / REGISTER_EXPRESSION_WITH_MIN_VERSION.
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index 647f7a24527..ef95686c879 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -73,7 +73,6 @@ class DocumentSource;
MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, (), ("expressionParserMap")) \
(InitializerContext*) { \
Expression::registerExpression("$" #key, (parser), boost::none); \
- return Status::OK(); \
}
/**
@@ -89,7 +88,6 @@ class DocumentSource;
MONGO_INITIALIZER_GENERAL(addToExpressionParserMap_##key, (), ("expressionParserMap")) \
(InitializerContext*) { \
Expression::registerExpression("$" #key, (parser), (minVersion)); \
- return Status::OK(); \
}
/**
@@ -103,7 +101,6 @@ class DocumentSource;
if (getTestCommandsEnabled()) { \
Expression::registerExpression("$" #key, (parser), boost::none); \
} \
- return Status::OK(); \
}
class Expression : public RefCountable {
diff --git a/src/mongo/db/pipeline/granularity_rounder.h b/src/mongo/db/pipeline/granularity_rounder.h
index 813e11b971e..a3cdb0c6086 100644
--- a/src/mongo/db/pipeline/granularity_rounder.h
+++ b/src/mongo/db/pipeline/granularity_rounder.h
@@ -55,7 +55,6 @@ namespace mongo {
#define REGISTER_GRANULARITY_ROUNDER_GENERAL(name, key, rounder) \
MONGO_INITIALIZER(addToGranularityRounderMap_##key)(InitializerContext*) { \
GranularityRounder::registerGranularityRounder(name, rounder); \
- return Status::OK(); \
}
/**
diff --git a/src/mongo/db/profile_filter_impl.cpp b/src/mongo/db/profile_filter_impl.cpp
index 7f76083bd22..b010b51841b 100644
--- a/src/mongo/db/profile_filter_impl.cpp
+++ b/src/mongo/db/profile_filter_impl.cpp
@@ -83,7 +83,6 @@ MONGO_INITIALIZER_GENERAL(ProfileFilterDefault,
if (auto expr = serverGlobalParams.defaultProfileFilter) {
ProfileFilter::setDefault(std::make_shared<ProfileFilterImpl>(*expr));
}
- return Status::OK();
} catch (AssertionException& e) {
// Add more context to the error
uasserted(ErrorCodes::FailedToParse,
diff --git a/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp b/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp
index 6eacae4c5a1..6ca6ae52ee6 100644
--- a/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp
+++ b/src/mongo/db/query/collation/collator_factory_icu_decoration.cpp
@@ -36,13 +36,10 @@
#include "mongo/db/service_context.h"
namespace mongo {
-
namespace {
-
ServiceContext::ConstructorActionRegisterer registerIcuCollator{
"CreateCollatorFactory", {"LoadICUData"}, [](ServiceContext* service) {
CollatorFactoryInterface::set(service, std::make_unique<CollatorFactoryICU>());
}};
} // namespace
-
} // namespace mongo
diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.cpp b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
index 31bb90785cd..8e693456799 100644
--- a/src/mongo/db/repl/data_replicator_external_state_impl.cpp
+++ b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
@@ -55,10 +55,9 @@ const char kBlockingQueueOplogBufferName[] = "inMemoryBlockingQueue";
MONGO_INITIALIZER(initialSyncOplogBuffer)(InitializerContext*) {
if ((initialSyncOplogBuffer != kCollectionOplogBufferName) &&
(initialSyncOplogBuffer != kBlockingQueueOplogBufferName)) {
- return Status(ErrorCodes::BadValue,
- "unsupported initial sync oplog buffer option: " + initialSyncOplogBuffer);
+ uasserted(ErrorCodes::BadValue,
+ "unsupported initial sync oplog buffer option: " + initialSyncOplogBuffer);
}
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp
index 1c561ff9f5d..85549d118d3 100644
--- a/src/mongo/db/repl/isself.cpp
+++ b/src/mongo/db/repl/isself.cpp
@@ -84,7 +84,6 @@ OID instanceId;
MONGO_INITIALIZER(GenerateInstanceId)(InitializerContext*) {
instanceId = OID::gen();
- return Status::OK();
}
namespace {
diff --git a/src/mongo/db/s/balancer/core_options_stub.cpp b/src/mongo/db/s/balancer/core_options_stub.cpp
index 2b9c5d8b837..234d91c322a 100644
--- a/src/mongo/db/s/balancer/core_options_stub.cpp
+++ b/src/mongo/db/s/balancer/core_options_stub.cpp
@@ -35,8 +35,6 @@ namespace {
MONGO_INITIALIZER_GENERAL(CoreOptions_Store,
("BeginStartupOptionStorage"),
("EndStartupOptionStorage"))
-(InitializerContext* context) {
- return Status::OK();
-}
+(InitializerContext* context) {}
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/s/config/configsvr_control_balancer_command.cpp b/src/mongo/db/s/config/configsvr_control_balancer_command.cpp
index 407828446fa..10fa0aa6739 100644
--- a/src/mongo/db/s/config/configsvr_control_balancer_command.cpp
+++ b/src/mongo/db/s/config/configsvr_control_balancer_command.cpp
@@ -148,8 +148,6 @@ MONGO_INITIALIZER(ClusterBalancerControlCommands)(InitializerContext* context) {
new ConfigSvrBalancerStartCommand();
new ConfigSvrBalancerStopCommand();
new ConfigSvrBalancerStatusCommand();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/server_options_init.cpp b/src/mongo/db/server_options_init.cpp
index 29a278981ff..6396125dc77 100644
--- a/src/mongo/db/server_options_init.cpp
+++ b/src/mongo/db/server_options_init.cpp
@@ -36,7 +36,7 @@ MONGO_INITIALIZER_GENERAL(ServerOptions_Setup,
("BeginStartupOptionSetup"),
("EndStartupOptionSetup"))
(InitializerContext* context) {
- return setupServerOptions(context->args());
+ uassertStatusOK(setupServerOptions(context->args()));
}
} // namespace mongo
diff --git a/src/mongo/db/server_options_test.cpp b/src/mongo/db/server_options_test.cpp
index d09cde9b797..5cc26ccd3c1 100644
--- a/src/mongo/db/server_options_test.cpp
+++ b/src/mongo/db/server_options_test.cpp
@@ -75,7 +75,6 @@ namespace moe = mongo::optionenvironment;
MONGO_INITIALIZER(ServerLogRedirection)(mongo::InitializerContext*) {
// ssl_options_server.cpp has an initializer which depends on logging.
// We can stub that dependency out for unit testing purposes.
- return Status::OK();
}
class OptionsParserTester : public moe::OptionsParser {
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index d69416b33b0..7fa4b4f637c 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -467,20 +467,16 @@ ServiceContext::ConstructorActionRegisterer::ConstructorActionRegisterer(
DestructorAction destructor) {
if (!destructor)
destructor = [](ServiceContext*) {};
- _registerer.emplace(std::move(name),
- [this, constructor, destructor](InitializerContext* context) {
- _iter = registeredConstructorActions().emplace(
- registeredConstructorActions().end(),
- std::move(constructor),
- std::move(destructor));
- return Status::OK();
- },
- [this](DeinitializerContext* context) {
- registeredConstructorActions().erase(_iter);
- return Status::OK();
- },
- std::move(prereqs),
- std::move(dependents));
+ _registerer.emplace(
+ std::move(name),
+ [this, constructor, destructor](InitializerContext*) {
+ _iter = registeredConstructorActions().emplace(registeredConstructorActions().end(),
+ std::move(constructor),
+ std::move(destructor));
+ },
+ [this](DeinitializerContext*) { registeredConstructorActions().erase(_iter); },
+ std::move(prereqs),
+ std::move(dependents));
}
ServiceContext::UniqueServiceContext ServiceContext::make() {
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h
index 4b900fa6384..1e4dffda45e 100644
--- a/src/mongo/db/service_context.h
+++ b/src/mongo/db/service_context.h
@@ -35,7 +35,6 @@
#include <memory>
#include <vector>
-#include "mongo/base/global_initializer_registerer.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/platform/atomic_word.h"
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_kv_engine_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_kv_engine_test.cpp
index e249daed751..76c5c843ff9 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_kv_engine_test.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_kv_engine_test.cpp
@@ -73,7 +73,6 @@ std::unique_ptr<mongo::KVHarnessHelper> makeHelper() {
MONGO_INITIALIZER(RegisterEphemeralForTestKVHarnessFactory)(InitializerContext*) {
KVHarnessHelper::registerFactory(makeHelper);
- return Status::OK();
}
class EphemeralForTestKVEngineTest : public unittest::Test {
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp
index ec4c5db41ed..278510f7c16 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp
@@ -91,9 +91,8 @@ std::unique_ptr<mongo::RecordStoreHarnessHelper> makeRecordStoreHarnessHelper()
return std::make_unique<RecordStoreHarnessHelper>();
}
-MONGO_INITIALIZER(RegisterRecordStoreHarnessFactory)(InitializerContext* const) {
+MONGO_INITIALIZER(RegisterRecordStoreHarnessFactory)(InitializerContext*) {
mongo::registerRecordStoreHarnessHelperFactory(makeRecordStoreHarnessHelper);
- return Status::OK();
}
} // namespace
} // namespace ephemeral_for_test
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit_test.cpp
index d796c783c4e..fbcf2b5fb9d 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit_test.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit_test.cpp
@@ -69,7 +69,6 @@ std::unique_ptr<mongo::RecoveryUnitHarnessHelper> makeRecoveryUnitHarnessHelper(
MONGO_INITIALIZER(RegisterRecoveryUnitHarnessFactory)(InitializerContext* const) {
mongo::registerRecoveryUnitHarnessHelperFactory(makeRecoveryUnitHarnessHelper);
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_sorted_impl_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_sorted_impl_test.cpp
index 7b3c88a4532..be04273b3f2 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_sorted_impl_test.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_sorted_impl_test.cpp
@@ -104,7 +104,6 @@ std::unique_ptr<mongo::SortedDataInterfaceHarnessHelper> makeSortedDataInterface
MONGO_INITIALIZER(RegisterSortedDataInterfaceHarnessFactory)(InitializerContext* const) {
mongo::registerSortedDataInterfaceHarnessHelperFactory(makeSortedDataInterfaceHarnessHelper);
- return Status::OK();
}
} // namespace
} // namespace ephemeral_for_test
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
index 8bf3312e1c2..e5d2fda83c0 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
@@ -397,7 +397,6 @@ std::unique_ptr<KVHarnessHelper> makeHelper() {
MONGO_INITIALIZER(RegisterKVHarnessFactory)(InitializerContext*) {
KVHarnessHelper::registerFactory(makeHelper);
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
index 90292778505..9773f267e05 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_options_init.cpp
@@ -48,6 +48,5 @@ MONGO_STARTUP_OPTIONS_STORE(WiredTigerOptions)(InitializerContext* context) {
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
::_exit(EXIT_BADOPTIONS);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
index 20afb98beac..e29e7ca4b17 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp
@@ -147,7 +147,6 @@ std::unique_ptr<SortedDataInterfaceHarnessHelper> makeWTPrefixedIndexHarnessHelp
MONGO_INITIALIZER(RegisterSortedDataInterfaceHarnessFactory)(InitializerContext* const) {
mongo::registerSortedDataInterfaceHarnessHelperFactory(makeWTPrefixedIndexHarnessHelper);
- return Status::OK();
}
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp
index aabe631120d..43c6e9a706e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp
@@ -203,7 +203,6 @@ std::unique_ptr<RecordStoreHarnessHelper> makeWTRSHarnessHelper() {
MONGO_INITIALIZER(RegisterRecordStoreHarnessFactory)(InitializerContext* const) {
mongo::registerRecordStoreHarnessHelperFactory(makeWTRSHarnessHelper);
- return Status::OK();
}
TEST(WiredTigerRecordStoreTest, PrefixedTableScan) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp
index c7ba49f4c61..0fe252a0f3a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp
@@ -127,7 +127,6 @@ std::unique_ptr<RecoveryUnitHarnessHelper> makeWTRUHarnessHelper() {
MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) {
mongo::registerRecoveryUnitHarnessHelperFactory(makeWTRUHarnessHelper);
- return Status::OK();
}
class WiredTigerRecoveryUnitTestFixture : public unittest::Test {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
index 05a9eb69c23..4113027a395 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp
@@ -148,7 +148,6 @@ std::unique_ptr<SortedDataInterfaceHarnessHelper> makeWTIndexHarnessHelper() {
MONGO_INITIALIZER(RegisterSortedDataInterfaceHarnessFactory)(InitializerContext* const) {
mongo::registerSortedDataInterfaceHarnessHelperFactory(makeWTIndexHarnessHelper);
- return Status::OK();
}
TEST(WiredTigerStandardIndexText, CursorInActiveTxnAfterNext) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
index 78b627ed40c..1f93a9fc63c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
@@ -200,7 +200,6 @@ std::unique_ptr<RecordStoreHarnessHelper> makeWTRSHarnessHelper() {
MONGO_INITIALIZER(RegisterRecordStoreHarnessFactory)(InitializerContext* const) {
mongo::registerRecordStoreHarnessHelperFactory(makeWTRSHarnessHelper);
- return Status::OK();
}
TEST(WiredTigerRecordStoreTest, StorageSizeStatisticsDisabled) {
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index b08598d0f51..c2eedda74ea 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -85,8 +85,6 @@ MONGO_INITIALIZER(AuthIndexKeyPatterns)(InitializerContext*) {
v3SystemRolesIndexSpec.addKeys(v3SystemRolesKeyPattern);
v3SystemRolesIndexSpec.unique();
v3SystemRolesIndexSpec.name(v3SystemRolesIndexName);
-
- return Status::OK();
}
void generateSystemIndexForExistingCollection(OperationContext* opCtx,
diff --git a/src/mongo/db/traffic_recorder.cpp b/src/mongo/db/traffic_recorder.cpp
index f13388e1892..7cbfaeef7c5 100644
--- a/src/mongo/db/traffic_recorder.cpp
+++ b/src/mongo/db/traffic_recorder.cpp
@@ -54,22 +54,20 @@ bool shouldAlwaysRecordTraffic = false;
MONGO_INITIALIZER(ShouldAlwaysRecordTraffic)(InitializerContext*) {
if (!gAlwaysRecordTraffic.size()) {
- return Status::OK();
+ return;
}
if (gTrafficRecordingDirectory.empty()) {
if (serverGlobalParams.logpath.empty()) {
- return Status(ErrorCodes::BadValue,
- "invalid to set AlwaysRecordTraffic without a logpath or "
- "trafficRecordingDirectory");
+ uasserted(ErrorCodes::BadValue,
+ "invalid to set AlwaysRecordTraffic without a logpath or "
+ "trafficRecordingDirectory");
} else {
gTrafficRecordingDirectory = serverGlobalParams.logpath;
}
}
shouldAlwaysRecordTraffic = true;
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/db/update/modifier_table.cpp b/src/mongo/db/update/modifier_table.cpp
index ed054989547..9e181b40dc1 100644
--- a/src/mongo/db/update/modifier_table.cpp
+++ b/src/mongo/db/update/modifier_table.cpp
@@ -123,8 +123,6 @@ MONGO_INITIALIZER(ModifierTable)(InitializerContext* context) {
MODIFIER_NAME_MAP = new NameMap(
SimpleStringDataComparator::kInstance.makeStringDataUnorderedMap<ModifierEntry*>());
init(MODIFIER_NAME_MAP);
-
- return Status::OK();
}
ModifierType getType(StringData typeStr) {
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index c083e433558..76529854f12 100644
--- a/src/mongo/dbtests/dbtests.cpp
+++ b/src/mongo/dbtests/dbtests.cpp
@@ -85,7 +85,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini
spec.outgoing.maxWireVersion = LATEST_WIRE_VERSION;
WireSpec::instance().initialize(std::move(spec));
- return Status::OK();
}
Status createIndex(OperationContext* opCtx, StringData ns, const BSONObj& keys, bool unique) {
diff --git a/src/mongo/dbtests/framework_options_init.cpp b/src/mongo/dbtests/framework_options_init.cpp
index 9ecf7993499..ebabe8f329a 100644
--- a/src/mongo/dbtests/framework_options_init.cpp
+++ b/src/mongo/dbtests/framework_options_init.cpp
@@ -39,18 +39,14 @@
namespace mongo {
MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(FrameworkOptions)(InitializerContext* context) {
- return addTestFrameworkOptions(&moe::startupOptions);
+ uassertStatusOK(addTestFrameworkOptions(&moe::startupOptions));
}
MONGO_STARTUP_OPTIONS_VALIDATE(FrameworkOptions)(InitializerContext* context) {
if (!handlePreValidationTestFrameworkOptions(moe::startupOptionsParsed, context->args())) {
quickExit(EXIT_SUCCESS);
}
- Status ret = moe::startupOptionsParsed.validate();
- if (!ret.isOK()) {
- return ret;
- }
- return Status::OK();
+ uassertStatusOK(moe::startupOptionsParsed.validate());
}
MONGO_STARTUP_OPTIONS_STORE(FrameworkOptions)(InitializerContext* context) {
@@ -60,11 +56,8 @@ MONGO_STARTUP_OPTIONS_STORE(FrameworkOptions)(InitializerContext* context) {
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
quickExit(EXIT_BADOPTIONS);
}
- return Status::OK();
}
-MONGO_INITIALIZER_GENERAL(CoreOptions_Store, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS)
-(InitializerContext* context) {
- return Status::OK();
-}
+MONGO_INITIALIZER_GENERAL(CoreOptions_Store, (), ())
+(InitializerContext* context) {}
} // namespace mongo
diff --git a/src/mongo/dbtests/mock/mock_conn_registry.cpp b/src/mongo/dbtests/mock/mock_conn_registry.cpp
index 37d9df06ceb..018cc8ba7b2 100644
--- a/src/mongo/dbtests/mock/mock_conn_registry.cpp
+++ b/src/mongo/dbtests/mock/mock_conn_registry.cpp
@@ -41,7 +41,7 @@ using std::string;
std::unique_ptr<MockConnRegistry> MockConnRegistry::_instance;
MONGO_INITIALIZER(MockConnRegistry)(InitializerContext* context) {
- return MockConnRegistry::init();
+ uassertStatusOK(MockConnRegistry::init());
}
Status MockConnRegistry::init() {
diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp
index 215a99a8c9c..d8301a76ead 100644
--- a/src/mongo/embedded/embedded.cpp
+++ b/src/mongo/embedded/embedded.cpp
@@ -94,14 +94,11 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini
spec.isInternalClient = true;
WireSpec::instance().initialize(std::move(spec));
- return Status::OK();
}
// Noop, to fulfill dependencies for other initializers.
MONGO_INITIALIZER_GENERAL(ForkServer, ("EndStartupOptionHandling"), ("default"))
-(InitializerContext* context) {
- return Status::OK();
-}
+(InitializerContext* context) {}
void setUpCatalog(ServiceContext* serviceContext) {
DatabaseHolder::set(serviceContext, std::make_unique<DatabaseHolderImpl>());
@@ -124,7 +121,6 @@ ServiceContext::ConstructorActionRegisterer replicationManagerInitializer(
MONGO_INITIALIZER(fsyncLockedForWriting)(InitializerContext* context) {
setLockedForWritingImpl([]() { return false; });
- return Status::OK();
}
GlobalInitializerRegisterer filterAllowedIndexFieldNamesEmbeddedInitializer(
@@ -135,7 +131,6 @@ GlobalInitializerRegisterer filterAllowedIndexFieldNamesEmbeddedInitializer(
allowedIndexFieldNames.erase(IndexDescriptor::kBackgroundFieldName);
allowedIndexFieldNames.erase(IndexDescriptor::kExpireAfterSecondsFieldName);
};
- return Status::OK();
},
DeinitializerFunction(nullptr),
{},
diff --git a/src/mongo/embedded/embedded_options_init.cpp b/src/mongo/embedded/embedded_options_init.cpp
index dcb40582c9e..d2c69d2200f 100644
--- a/src/mongo/embedded/embedded_options_init.cpp
+++ b/src/mongo/embedded/embedded_options_init.cpp
@@ -36,7 +36,7 @@ namespace mongo {
namespace embedded {
MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(EmbeddedOptions)(InitializerContext* context) {
- return addOptions(&optionenvironment::startupOptions);
+ uassertStatusOK(addOptions(&optionenvironment::startupOptions));
}
GlobalInitializerRegisterer embeddedOptionsInitializer(
diff --git a/src/mongo/executor/network_interface_thread_pool_test.cpp b/src/mongo/executor/network_interface_thread_pool_test.cpp
index b6847284985..88a69a8b9fc 100644
--- a/src/mongo/executor/network_interface_thread_pool_test.cpp
+++ b/src/mongo/executor/network_interface_thread_pool_test.cpp
@@ -82,7 +82,6 @@ private:
MONGO_INITIALIZER(ThreadPoolCommonTests)(InitializerContext*) {
addTestsForThreadPool("ThreadPoolCommon",
[]() { return std::make_unique<NetworkInterfaceThreadPoolWithASIO>(); });
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/executor/thread_pool_task_executor_test.cpp b/src/mongo/executor/thread_pool_task_executor_test.cpp
index 556d9ee95f0..826f76a7c01 100644
--- a/src/mongo/executor/thread_pool_task_executor_test.cpp
+++ b/src/mongo/executor/thread_pool_task_executor_test.cpp
@@ -53,7 +53,6 @@ MONGO_INITIALIZER(ThreadPoolExecutorCommonTests)(InitializerContext*) {
addTestsForExecutor("ThreadPoolExecutorCommon", [](std::unique_ptr<NetworkInterfaceMock> net) {
return makeSharedThreadPoolTestExecutor(std::move(net));
});
- return Status::OK();
}
TEST_F(ThreadPoolExecutorTest, TimelyCancelationOfScheduleWorkAt) {
diff --git a/src/mongo/idl/config_option_test.cpp b/src/mongo/idl/config_option_test.cpp
index 78bdf0df513..cdc56cb0138 100644
--- a/src/mongo/idl/config_option_test.cpp
+++ b/src/mongo/idl/config_option_test.cpp
@@ -93,7 +93,7 @@ MONGO_STARTUP_OPTIONS_PARSE(ConfigOption)(InitializerContext*) {
"--testConfigOpt14",
"set14",
};
- return parseArgv(argv, &moe::startupOptionsParsed);
+ uassertStatusOK(parseArgv(argv, &moe::startupOptionsParsed));
}
template <typename T>
diff --git a/src/mongo/idl/server_parameter.cpp b/src/mongo/idl/server_parameter.cpp
index b0cd8c6d16e..05db8b9c856 100644
--- a/src/mongo/idl/server_parameter.cpp
+++ b/src/mongo/idl/server_parameter.cpp
@@ -36,9 +36,7 @@
namespace mongo {
using SPT = ServerParameterType;
-MONGO_INITIALIZER_GROUP(BeginServerParameterRegistration,
- MONGO_NO_PREREQUISITES,
- ("EndServerParameterRegistration"))
+MONGO_INITIALIZER_GROUP(BeginServerParameterRegistration, (), ("EndServerParameterRegistration"))
MONGO_INITIALIZER_GROUP(EndServerParameterRegistration,
("BeginServerParameterRegistration"),
("BeginStartupOptionHandling"))
diff --git a/src/mongo/logv2/console.cpp b/src/mongo/logv2/console.cpp
index 48fc9a16b84..4691b332d47 100644
--- a/src/mongo/logv2/console.cpp
+++ b/src/mongo/logv2/console.cpp
@@ -235,7 +235,6 @@ std::ostream* windowsOutputStream = getWindowsOutputStream();
// the initalizer chain.
MONGO_INITIALIZER(EnsureIosBaseInitConstructedV2)(InitializerContext*) {
Console forInitializationOnly;
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/logv2/log_manager.cpp b/src/mongo/logv2/log_manager.cpp
index 4794636ea45..e75b2f155bc 100644
--- a/src/mongo/logv2/log_manager.cpp
+++ b/src/mongo/logv2/log_manager.cpp
@@ -104,7 +104,6 @@ MONGO_INITIALIZER(GlobalLogRotator)(InitializerContext*) {
addLogRotator([](bool renameFiles, StringData suffix) {
return LogManager::global().getGlobalDomainInternal().rotate(renameFiles, suffix);
});
- return Status::OK();
}
} // namespace mongo::logv2
diff --git a/src/mongo/logv2/ramlog.cpp b/src/mongo/logv2/ramlog.cpp
index eb2a01b72e1..fd024403d42 100644
--- a/src/mongo/logv2/ramlog.cpp
+++ b/src/mongo/logv2/ramlog.cpp
@@ -31,6 +31,8 @@
#include "mongo/logv2/ramlog.h"
+#include <map>
+
#include "mongo/base/init.h"
#include "mongo/base/status.h"
#include "mongo/util/str.h"
@@ -193,15 +195,12 @@ void RamLog::getNames(std::vector<string>& names) {
MONGO_INITIALIZER(RamLogCatalogV2)(InitializerContext*) {
if (!_namedLock) {
if (_named) {
- return Status(ErrorCodes::InternalError,
- "Inconsistent intiailization of RamLogCatalog.");
+ uasserted(ErrorCodes::InternalError, "Inconsistent intiailization of RamLogCatalog.");
}
_namedLock = new stdx::mutex(); // NOLINT
_named = new RM();
}
-
- return Status::OK();
}
} // namespace mongo::logv2
diff --git a/src/mongo/platform/mutex.cpp b/src/mongo/platform/mutex.cpp
index b913cd0d152..eb2501000c2 100644
--- a/src/mongo/platform/mutex.cpp
+++ b/src/mongo/platform/mutex.cpp
@@ -155,8 +155,6 @@ void Mutex::_onUnlock() noexcept {
MONGO_INITIALIZER(FinalizeDiagnosticListeners)(InitializerContext* context) {
auto& state = latch_detail::getDiagnosticListenerState();
state.isFinalized.store(true);
-
- return Status::OK();
}
} // namespace mongo::latch_detail
diff --git a/src/mongo/platform/posix_fadvise.cpp b/src/mongo/platform/posix_fadvise.cpp
index 689d5de94b0..a9b605dc185 100644
--- a/src/mongo/platform/posix_fadvise.cpp
+++ b/src/mongo/platform/posix_fadvise.cpp
@@ -54,14 +54,13 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
// 'posix_fadvise()' on Solaris will call the emulation if the symbol is not found
//
-MONGO_INITIALIZER_GENERAL(SolarisPosixFadvise, MONGO_NO_PREREQUISITES, ("default"))
+MONGO_INITIALIZER_GENERAL(SolarisPosixFadvise, (), ("default"))
(InitializerContext* context) {
void* functionAddress = dlsym(RTLD_DEFAULT, "posix_fadvise");
if (functionAddress != nullptr) {
mongo::pal::posix_fadvise_switcher =
reinterpret_cast<mongo::pal::PosixFadviseFunc>(functionAddress);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/platform/strcasestr.cpp b/src/mongo/platform/strcasestr.cpp
index 9c5ffe23a3c..1d0f4b5a006 100644
--- a/src/mongo/platform/strcasestr.cpp
+++ b/src/mongo/platform/strcasestr.cpp
@@ -93,14 +93,13 @@ namespace mongo {
// 'strcasestr()' on Solaris will call the emulation if the symbol is not found
//
-MONGO_INITIALIZER_GENERAL(SolarisStrCaseCmp, MONGO_NO_PREREQUISITES, ("default"))
+MONGO_INITIALIZER_GENERAL(SolarisStrCaseCmp, (), ("default"))
(InitializerContext* context) {
void* functionAddress = dlsym(RTLD_DEFAULT, "strcasestr");
if (functionAddress != nullptr) {
mongo::pal::strcasestr_switcher =
reinterpret_cast<mongo::pal::StrCaseStrFunc>(functionAddress);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/s/chunk_manager_refresh_bm.cpp b/src/mongo/s/chunk_manager_refresh_bm.cpp
index 9b0e05dc2cd..28f36dd07fd 100644
--- a/src/mongo/s/chunk_manager_refresh_bm.cpp
+++ b/src/mongo/s/chunk_manager_refresh_bm.cpp
@@ -402,8 +402,6 @@ MONGO_INITIALIZER(RegisterBenchmarks)(InitializerContext* context) {
->Args({1000, 50000})
->Args({2, 2});
}
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/s/commands/cluster_command_test_fixture.cpp b/src/mongo/s/commands/cluster_command_test_fixture.cpp
index 8c8813a3b11..76f294518b5 100644
--- a/src/mongo/s/commands/cluster_command_test_fixture.cpp
+++ b/src/mongo/s/commands/cluster_command_test_fixture.cpp
@@ -309,8 +309,6 @@ void ClusterCommandTestFixture::appendTxnResponseMetadata(BSONObjBuilder& bob) {
}
// Satisfies dependency from StoreSASLOPtions.
-MONGO_STARTUP_OPTIONS_STORE(CoreOptions)(InitializerContext*) {
- return Status::OK();
-}
+MONGO_STARTUP_OPTIONS_STORE(CoreOptions)(InitializerContext*) {}
} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_control_balancer_cmd.cpp b/src/mongo/s/commands/cluster_control_balancer_cmd.cpp
index 5ded533666b..a4b2b2c9d48 100644
--- a/src/mongo/s/commands/cluster_control_balancer_cmd.cpp
+++ b/src/mongo/s/commands/cluster_control_balancer_cmd.cpp
@@ -141,8 +141,6 @@ MONGO_INITIALIZER(ClusterBalancerControlCommands)(InitializerContext* context) {
new BalancerStartCommand();
new BalancerStopCommand();
new BalancerStatusCommand();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/s/commands/cluster_ftdc_commands.cpp b/src/mongo/s/commands/cluster_ftdc_commands.cpp
index 26694115c7c..3b2ac9e0a16 100644
--- a/src/mongo/s/commands/cluster_ftdc_commands.cpp
+++ b/src/mongo/s/commands/cluster_ftdc_commands.cpp
@@ -111,8 +111,6 @@ Command* ftdcCommand;
MONGO_INITIALIZER(CreateDiagnosticDataCommand)(InitializerContext* context) {
ftdcCommand = new GetDiagnosticDataCommand();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp
index b2a7cb15b77..861c3c830d1 100644
--- a/src/mongo/s/mongos_main.cpp
+++ b/src/mongo/s/mongos_main.cpp
@@ -485,7 +485,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionHandling"))(Ini
spec.isInternalClient = true;
WireSpec::instance().initialize(std::move(spec));
- return Status::OK();
}
class ShardingReplicaSetChangeListener final
@@ -876,7 +875,6 @@ ExitCode main(ServiceContext* serviceContext) {
MONGO_INITIALIZER_GENERAL(ForkServer, ("EndStartupOptionHandling"), ("default"))
(InitializerContext* context) {
forkServerOrDie();
- return Status::OK();
}
// Initialize the featureCompatibilityVersion server parameter since mongos does not have a
@@ -890,14 +888,12 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetFeatureCompatibilityVersionLatest,
(InitializerContext* context) {
serverGlobalParams.mutableFeatureCompatibility.setVersion(
ServerGlobalParams::FeatureCompatibility::kLatest);
- return Status::OK();
}
#ifdef MONGO_CONFIG_SSL
-MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManager"))
+MONGO_INITIALIZER_GENERAL(setSSLManagerType, (), ("SSLManager"))
(InitializerContext* context) {
isSSLServer = true;
- return Status::OK();
}
#endif
diff --git a/src/mongo/s/mongos_options_init.cpp b/src/mongo/s/mongos_options_init.cpp
index cf139b81b92..b0c96991f52 100644
--- a/src/mongo/s/mongos_options_init.cpp
+++ b/src/mongo/s/mongos_options_init.cpp
@@ -44,22 +44,10 @@
namespace mongo {
MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongosOptions)(InitializerContext* context) {
- auto status = addGeneralServerOptions(&moe::startupOptions);
- if (!status.isOK()) {
- return status;
- }
-
- status = addKeyfileServerOption(&moe::startupOptions);
- if (!status.isOK()) {
- return status;
- }
-
- status = addClusterAuthModeServerOption(&moe::startupOptions);
- if (!status.isOK()) {
- return status;
- }
-
- return addNonGeneralServerOptions(&moe::startupOptions);
+ uassertStatusOK(addGeneralServerOptions(&moe::startupOptions));
+ uassertStatusOK(addKeyfileServerOption(&moe::startupOptions));
+ uassertStatusOK(addClusterAuthModeServerOption(&moe::startupOptions));
+ uassertStatusOK(addNonGeneralServerOptions(&moe::startupOptions));
}
MONGO_INITIALIZER_GENERAL(MongosOptions,
@@ -71,23 +59,10 @@ MONGO_INITIALIZER_GENERAL(MongosOptions,
}
// 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 = moe::startupOptionsParsed.validate(false /*setValid*/);
- if (!ret.isOK()) {
- return ret;
- }
- ret = validateMongosOptions(moe::startupOptionsParsed);
- if (!ret.isOK()) {
- return ret;
- }
- ret = canonicalizeMongosOptions(&moe::startupOptionsParsed);
- if (!ret.isOK()) {
- return ret;
- }
- ret = moe::startupOptionsParsed.validate();
- if (!ret.isOK()) {
- return ret;
- }
- return Status::OK();
+ uassertStatusOK(moe::startupOptionsParsed.validate(false /*setValid*/));
+ uassertStatusOK(validateMongosOptions(moe::startupOptionsParsed));
+ uassertStatusOK(canonicalizeMongosOptions(&moe::startupOptionsParsed));
+ uassertStatusOK(moe::startupOptionsParsed.validate());
}
MONGO_INITIALIZER_GENERAL(CoreOptions_Store,
@@ -100,7 +75,6 @@ MONGO_INITIALIZER_GENERAL(CoreOptions_Store,
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
quickExit(EXIT_BADOPTIONS);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/s/mongos_topology_coordinator.cpp b/src/mongo/s/mongos_topology_coordinator.cpp
index 2cc3d230690..8b0cec8c2fa 100644
--- a/src/mongo/s/mongos_topology_coordinator.cpp
+++ b/src/mongo/s/mongos_topology_coordinator.cpp
@@ -51,7 +51,6 @@ OID instanceId;
MONGO_INITIALIZER(GenerateMongosInstanceId)(InitializerContext*) {
instanceId = OID::gen();
- return Status::OK();
}
// Signals that a hello request has started waiting.
diff --git a/src/mongo/shell/encrypted_dbclient_base.cpp b/src/mongo/shell/encrypted_dbclient_base.cpp
index 688484c4769..dd20a63e9cf 100644
--- a/src/mongo/shell/encrypted_dbclient_base.cpp
+++ b/src/mongo/shell/encrypted_dbclient_base.cpp
@@ -787,7 +787,6 @@ std::unique_ptr<DBClientBase> createEncryptedDBClientBase(std::unique_ptr<DBClie
MONGO_INITIALIZER(setCallbacksForEncryptedDBClientBase)(InitializerContext*) {
mongo::mozjs::setEncryptedDBClientCallback(createEncryptedDBClientBase);
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/shell/kms_aws.cpp b/src/mongo/shell/kms_aws.cpp
index 4b2364fe3d7..2cc3b2ee2bd 100644
--- a/src/mongo/shell/kms_aws.cpp
+++ b/src/mongo/shell/kms_aws.cpp
@@ -334,7 +334,6 @@ MONGO_INITIALIZER(KMSRegister)(::mongo::InitializerContext* context) {
kms_message_init();
KMSServiceController::registerFactory(KMSProviderEnum::aws,
std::make_unique<AWSKMSServiceFactory>());
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/shell/kms_local.cpp b/src/mongo/shell/kms_local.cpp
index 1430596c18e..10fcb46f2a8 100644
--- a/src/mongo/shell/kms_local.cpp
+++ b/src/mongo/shell/kms_local.cpp
@@ -141,7 +141,6 @@ public:
MONGO_INITIALIZER(LocalKMSRegister)(::mongo::InitializerContext* context) {
KMSServiceController::registerFactory(KMSProviderEnum::local,
std::make_unique<LocalKMSServiceFactory>());
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/shell/kms_shell.cpp b/src/mongo/shell/kms_shell.cpp
index f05fbdf3c8e..673fe7fb921 100644
--- a/src/mongo/shell/kms_shell.cpp
+++ b/src/mongo/shell/kms_shell.cpp
@@ -45,7 +45,6 @@ void callback_fn(Scope& scope) {
MONGO_INITIALIZER(setKeyvaultCallback)(InitializerContext*) {
shell_utils::setEnterpriseShellCallback(mongo::callback_fn);
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/shell/mongo_main.cpp b/src/mongo/shell/mongo_main.cpp
index 6d0ff876265..32328dbe682 100644
--- a/src/mongo/shell/mongo_main.cpp
+++ b/src/mongo/shell/mongo_main.cpp
@@ -120,12 +120,10 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetFeatureCompatibilityVersionLatest,
(InitializerContext* context) {
mongo::serverGlobalParams.mutableFeatureCompatibility.setVersion(
ServerGlobalParams::FeatureCompatibility::kLatest);
- return Status::OK();
}
MONGO_INITIALIZER_WITH_PREREQUISITES(WireSpec, ("EndStartupOptionSetup"))(InitializerContext*) {
WireSpec::instance().initialize(WireSpec::Specification{});
- return Status::OK();
}
const auto kAuthParam = "authSource"s;
diff --git a/src/mongo/shell/mongodbcr.cpp b/src/mongo/shell/mongodbcr.cpp
index b177a316426..e90320c527e 100644
--- a/src/mongo/shell/mongodbcr.cpp
+++ b/src/mongo/shell/mongodbcr.cpp
@@ -138,7 +138,6 @@ Future<void> authMongoCRImpl(RunCommandHook runCommand, const BSONObj& params) {
MONGO_INITIALIZER(RegisterAuthMongoCR)(InitializerContext* context) {
authMongoCR = authMongoCRImpl;
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/shell/shell_options_init.cpp b/src/mongo/shell/shell_options_init.cpp
index 2ea64570bc8..b89b024a2b6 100644
--- a/src/mongo/shell/shell_options_init.cpp
+++ b/src/mongo/shell/shell_options_init.cpp
@@ -42,12 +42,7 @@ MONGO_STARTUP_OPTIONS_VALIDATE(MongoShellOptions)(InitializerContext* context) {
if (!handlePreValidationMongoShellOptions(moe::startupOptionsParsed, context->args())) {
quickExit(EXIT_SUCCESS);
}
- Status ret = moe::startupOptionsParsed.validate();
- if (!ret.isOK()) {
- return ret;
- }
-
- return Status::OK();
+ uassertStatusOK(moe::startupOptionsParsed.validate());
}
MONGO_STARTUP_OPTIONS_STORE(MongoShellOptions)(InitializerContext* context) {
@@ -57,6 +52,5 @@ MONGO_STARTUP_OPTIONS_STORE(MongoShellOptions)(InitializerContext* context) {
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
quickExit(EXIT_BADOPTIONS);
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/tools/bridge_commands.cpp b/src/mongo/tools/bridge_commands.cpp
index aa3bc583a15..6ff96970e7e 100644
--- a/src/mongo/tools/bridge_commands.cpp
+++ b/src/mongo/tools/bridge_commands.cpp
@@ -167,7 +167,6 @@ MONGO_INITIALIZER(RegisterBridgeCommands)(InitializerContext* context) {
bridgeCommandMap["acceptConnectionsFrom"] = new CmdAcceptConnectionsFrom();
bridgeCommandMap["rejectConnectionsFrom"] = new CmdRejectConnectionsFrom();
bridgeCommandMap["discardMessagesFrom"] = new CmdDiscardMessagesFrom();
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/tools/mongobridge_options_init.cpp b/src/mongo/tools/mongobridge_options_init.cpp
index d1373ccd7a2..f27a73c6aeb 100644
--- a/src/mongo/tools/mongobridge_options_init.cpp
+++ b/src/mongo/tools/mongobridge_options_init.cpp
@@ -43,11 +43,7 @@ MONGO_STARTUP_OPTIONS_VALIDATE(MongoBridgeOptions)(InitializerContext* context)
if (!handlePreValidationMongoBridgeOptions(moe::startupOptionsParsed)) {
quickExit(EXIT_SUCCESS);
}
- Status ret = moe::startupOptionsParsed.validate();
- if (!ret.isOK()) {
- return ret;
- }
- return Status::OK();
+ uassertStatusOK(moe::startupOptionsParsed.validate());
}
MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) {
@@ -66,7 +62,5 @@ MONGO_STARTUP_OPTIONS_STORE(MongoBridgeOptions)(InitializerContext* context) {
quickExit(EXIT_BADOPTIONS);
}
}
-
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/transport/message_compressor_registry.cpp b/src/mongo/transport/message_compressor_registry.cpp
index 90a89855048..cbb77606b92 100644
--- a/src/mongo/transport/message_compressor_registry.cpp
+++ b/src/mongo/transport/message_compressor_registry.cpp
@@ -134,13 +134,12 @@ MONGO_INITIALIZER_GENERAL(NoopMessageCompressorInit,
(InitializerContext* context) {
auto& compressorRegistry = MessageCompressorRegistry::get();
compressorRegistry.registerImplementation(std::make_unique<NoopMessageCompressor>());
- return Status::OK();
}
// This cleans up any compressors that were requested by the user, but weren't registered by
// any compressor. It must be run after all the compressors have registered themselves with
// the global registry.
MONGO_INITIALIZER(AllCompressorsRegistered)(InitializerContext* context) {
- return MessageCompressorRegistry::get().finalizeSupportedCompressors();
+ uassertStatusOK(MessageCompressorRegistry::get().finalizeSupportedCompressors());
}
} // namespace mongo
diff --git a/src/mongo/transport/message_compressor_snappy.cpp b/src/mongo/transport/message_compressor_snappy.cpp
index 56384ce8854..1d926174cf5 100644
--- a/src/mongo/transport/message_compressor_snappy.cpp
+++ b/src/mongo/transport/message_compressor_snappy.cpp
@@ -82,6 +82,5 @@ MONGO_INITIALIZER_GENERAL(SnappyMessageCompressorInit,
(InitializerContext* context) {
auto& compressorRegistry = MessageCompressorRegistry::get();
compressorRegistry.registerImplementation(std::make_unique<SnappyMessageCompressor>());
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/transport/message_compressor_zlib.cpp b/src/mongo/transport/message_compressor_zlib.cpp
index 599a2f5e40f..878431b2824 100644
--- a/src/mongo/transport/message_compressor_zlib.cpp
+++ b/src/mongo/transport/message_compressor_zlib.cpp
@@ -84,6 +84,5 @@ MONGO_INITIALIZER_GENERAL(ZlibMessageCompressorInit,
(InitializerContext* context) {
auto& compressorRegistry = MessageCompressorRegistry::get();
compressorRegistry.registerImplementation(std::make_unique<ZlibMessageCompressor>());
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/transport/message_compressor_zstd.cpp b/src/mongo/transport/message_compressor_zstd.cpp
index 79ce2a5b0f1..22721c6e16c 100644
--- a/src/mongo/transport/message_compressor_zstd.cpp
+++ b/src/mongo/transport/message_compressor_zstd.cpp
@@ -82,6 +82,5 @@ MONGO_INITIALIZER_GENERAL(ZstdMessageCompressorInit,
(InitializerContext* context) {
auto& compressorRegistry = MessageCompressorRegistry::get();
compressorRegistry.registerImplementation(std::make_unique<ZstdMessageCompressor>());
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/unittest/integration_test_main.cpp b/src/mongo/unittest/integration_test_main.cpp
index 6fb5a68fb5e..43173c361b9 100644
--- a/src/mongo/unittest/integration_test_main.cpp
+++ b/src/mongo/unittest/integration_test_main.cpp
@@ -63,7 +63,6 @@ ConnectionString fixtureConnectionString{};
MONGO_INITIALIZER(WireSpec)(InitializerContext*) {
WireSpec::instance().initialize(WireSpec::Specification{});
- return Status::OK();
}
} // namespace
@@ -95,60 +94,40 @@ MONGO_INITIALIZER_GENERAL(ForkServer, ("EndStartupOptionHandling"), ("default"))
(InitializerContext* context) {
// Integration tests do not fork, however the init graph requires a deliberate initializer that
// _could_ fork and here choses not to do so.
- return Status::OK();
}
MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(IntegrationTestOptions)(InitializerContext*) {
uassertStatusOK(addBaseServerOptions(&moe::startupOptions));
-
- return Status::OK();
}
MONGO_STARTUP_OPTIONS_VALIDATE(IntegrationTestOptions)(InitializerContext*) {
auto& env = moe::startupOptionsParsed;
auto& opts = moe::startupOptions;
- if (auto ret = env.validate(); !ret.isOK()) {
- return ret;
- }
-
- if (auto ret = validateBaseOptions(env); !ret.isOK()) {
- return ret;
- }
+ uassertStatusOK(env.validate());
+ uassertStatusOK(validateBaseOptions(env));
if (env.count("help")) {
std::cout << opts.helpString() << std::endl;
quickExit(EXIT_SUCCESS);
}
-
- return Status::OK();
}
MONGO_STARTUP_OPTIONS_STORE(IntegrationTestOptions)(InitializerContext*) {
auto& env = moe::startupOptionsParsed;
- if (auto ret = canonicalizeBaseOptions(&env); !ret.isOK()) {
- return ret;
- }
-
- if (auto ret = storeBaseOptions(env); !ret.isOK()) {
- return ret;
- }
+ uassertStatusOK(canonicalizeBaseOptions(&env));
+ uassertStatusOK(storeBaseOptions(env));
std::string connectionString = env["connectionString"].as<std::string>();
auto swConnectionString = ConnectionString::parse(connectionString);
- if (!swConnectionString.isOK()) {
- return swConnectionString.getStatus();
- }
+ uassertStatusOK(swConnectionString);
fixtureConnectionString = std::move(swConnectionString.getValue());
LOGV2(23050,
"Using test fixture with connection string = {connectionString}",
"connectionString"_attr = connectionString);
-
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/unittest/temp_dir.cpp b/src/mongo/unittest/temp_dir.cpp
index ab8ec61f548..88b274883f9 100644
--- a/src/mongo/unittest/temp_dir.cpp
+++ b/src/mongo/unittest/temp_dir.cpp
@@ -61,17 +61,16 @@ MONGO_INITIALIZER(SetTempDirDefaultRoot)(InitializerContext* context) {
}
if (!boost::filesystem::exists(defaultRoot)) {
- return Status(ErrorCodes::BadValue,
- str::stream() << "Attempted to use a tempPath (" << defaultRoot.string()
- << ") that doesn't exist");
+ uasserted(ErrorCodes::BadValue,
+ str::stream() << "Attempted to use a tempPath (" << defaultRoot.string()
+ << ") that doesn't exist");
}
if (!boost::filesystem::is_directory(defaultRoot)) {
- return Status(ErrorCodes::BadValue,
- str::stream() << "Attempted to use a tempPath (" << defaultRoot.string()
- << ") that exists, but isn't a directory");
+ uasserted(ErrorCodes::BadValue,
+ str::stream() << "Attempted to use a tempPath (" << defaultRoot.string()
+ << ") that exists, but isn't a directory");
}
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp
index 1056198a04f..f64d8d4d688 100644
--- a/src/mongo/unittest/unittest_main.cpp
+++ b/src/mongo/unittest/unittest_main.cpp
@@ -56,7 +56,6 @@ namespace {
MONGO_INITIALIZER(WireSpec)(InitializerContext*) {
WireSpec::instance().initialize(WireSpec::Specification{});
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/cmdline_utils/censor_cmdline.cpp b/src/mongo/util/cmdline_utils/censor_cmdline.cpp
index 526414b21e9..fa1d93d7087 100644
--- a/src/mongo/util/cmdline_utils/censor_cmdline.cpp
+++ b/src/mongo/util/cmdline_utils/censor_cmdline.cpp
@@ -77,10 +77,7 @@ MONGO_INITIALIZER_GENERAL(GatherReadctionOptions,
};
std::vector<optionenvironment::OptionDescription> options;
- auto status = optionenvironment::startupOptions.getAllOptions(&options);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(optionenvironment::startupOptions.getAllOptions(&options));
for (const auto& opt : options) {
if (!opt._redact) {
@@ -91,21 +88,14 @@ MONGO_INITIALIZER_GENERAL(GatherReadctionOptions,
gRedactedDottedNames.insert(opt._deprecatedDottedNames.begin(),
opt._deprecatedDottedNames.end());
if (!opt._singleName.empty()) {
- auto status = insertSingleName(opt._singleName);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(insertSingleName(opt._singleName));
}
for (const auto& name : opt._deprecatedSingleNames) {
- auto status = insertSingleName(name);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(insertSingleName(name));
}
}
gGatherOptionsDone = true;
- return Status::OK();
}
bool _isPasswordArgument(const std::string& name) {
diff --git a/src/mongo/util/concurrency/thread_pool_test.cpp b/src/mongo/util/concurrency/thread_pool_test.cpp
index 0b456c6abc1..c5eb7771eb5 100644
--- a/src/mongo/util/concurrency/thread_pool_test.cpp
+++ b/src/mongo/util/concurrency/thread_pool_test.cpp
@@ -55,7 +55,6 @@ using namespace fmt::literals;
MONGO_INITIALIZER(ThreadPoolCommonTests)(InitializerContext*) {
addTestsForThreadPool("ThreadPoolCommon",
[]() { return std::make_unique<ThreadPool>(ThreadPool::Options()); });
- return Status::OK();
}
class ThreadPoolTest : public unittest::Test {
diff --git a/src/mongo/util/diagnostic_info.cpp b/src/mongo/util/diagnostic_info.cpp
index 49076e76c91..bb65abd4a4a 100644
--- a/src/mongo/util/diagnostic_info.cpp
+++ b/src/mongo/util/diagnostic_info.cpp
@@ -216,8 +216,6 @@ MONGO_INITIALIZER_GENERAL(DiagnosticInfo, (/* NO PREREQS */), ("FinalizeDiagnost
};
latch_detail::installDiagnosticListener<DiagnosticListener>();
-
- return Status::OK();
}
MONGO_INITIALIZER(InterruptibleWaitListener)(InitializerContext* context) {
@@ -258,8 +256,6 @@ MONGO_INITIALIZER(InterruptibleWaitListener)(InitializerContext* context) {
};
Interruptible::installWaitListener<WaitListener>();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp
index 34a5cb7454e..745983c107e 100644
--- a/src/mongo/util/fail_point.cpp
+++ b/src/mongo/util/fail_point.cpp
@@ -58,7 +58,6 @@ MONGO_FAIL_POINT_DEFINE(dummy); // used by tests in jstests/fail_point
MONGO_INITIALIZER_GENERAL(AllFailPointsRegistered, (), ())
(InitializerContext* context) {
globalFailPointRegistry().freeze();
- return Status::OK();
}
/** The per-thread PRNG used by fail-points. */
diff --git a/src/mongo/util/generate_icu_init_cpp.py b/src/mongo/util/generate_icu_init_cpp.py
index 2d339660c78..f606a2ee800 100755
--- a/src/mongo/util/generate_icu_init_cpp.py
+++ b/src/mongo/util/generate_icu_init_cpp.py
@@ -103,12 +103,11 @@ alignas(16) const uint8_t kRawData[] = {%(decimal_encoded_data)s};
} // namespace
-MONGO_INITIALIZER_GENERAL(LoadICUData, MONGO_NO_PREREQUISITES, ("BeginStartupOptionHandling"))(
+MONGO_INITIALIZER_GENERAL(LoadICUData, (), ("BeginStartupOptionHandling"))(
InitializerContext* context) {
UErrorCode status = U_ZERO_ERROR;
udata_setCommonData(kRawData, &status);
fassert(40088, U_SUCCESS(status));
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/util/heap_profiler.cpp b/src/mongo/util/heap_profiler.cpp
index 9d0e91ae536..7c39be5e84d 100644
--- a/src/mongo/util/heap_profiler.cpp
+++ b/src/mongo/util/heap_profiler.cpp
@@ -713,7 +713,6 @@ MONGO_INITIALIZER_GENERAL(StartHeapProfiling, ("EndStartupOptionHandling"), ("de
(InitializerContext* context) {
if (HeapProfilingEnabled)
HeapProfiler::heapProfiler = new HeapProfiler();
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/icu_init_stub.cpp b/src/mongo/util/icu_init_stub.cpp
index 29838c88b63..70c641fdcc3 100644
--- a/src/mongo/util/icu_init_stub.cpp
+++ b/src/mongo/util/icu_init_stub.cpp
@@ -36,9 +36,7 @@ namespace {
// This initializer provides a no-op definition of the LoadICUData MONGO_INITIALIZER, for use when
// the system version of ICU is used instead of the vendored version.
-MONGO_INITIALIZER(LoadICUData)(InitializerContext* context) {
- return Status::OK();
-}
+MONGO_INITIALIZER(LoadICUData)(InitializerContext* context) {}
} // namespace
} // namespace mongo
diff --git a/src/mongo/util/latch_analyzer.cpp b/src/mongo/util/latch_analyzer.cpp
index 266f610d83d..a77c21d847e 100644
--- a/src/mongo/util/latch_analyzer.cpp
+++ b/src/mongo/util/latch_analyzer.cpp
@@ -95,8 +95,6 @@ public:
MONGO_INITIALIZER_GENERAL(LatchAnalysis, (/* NO PREREQS */), ("FinalizeDiagnosticListeners"))
(InitializerContext* context) {
latch_detail::installDiagnosticListener<DiagnosticListener>();
-
- return Status::OK();
}
// Create a FailPoint to analyze latches more seriously for diagnostic purposes. This can be used
diff --git a/src/mongo/util/net/openssl_init.cpp b/src/mongo/util/net/openssl_init.cpp
index c4980bb0042..0f2c439e5f9 100644
--- a/src/mongo/util/net/openssl_init.cpp
+++ b/src/mongo/util/net/openssl_init.cpp
@@ -177,8 +177,6 @@ MONGO_INITIALIZER(SetupOpenSSL)(InitializerContext*) {
// Setup OpenSSL multithreading callbacks and mutexes
SSLThreadInfo::init();
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/net/ssl/detail/impl/schannel.ipp b/src/mongo/util/net/ssl/detail/impl/schannel.ipp
index 99ccf211c2f..b46cffd0cd7 100644
--- a/src/mongo/util/net/ssl/detail/impl/schannel.ipp
+++ b/src/mongo/util/net/ssl/detail/impl/schannel.ipp
@@ -817,8 +817,6 @@ MONGO_INITIALIZER(InitializeSchannelGetServerIdentityFn)(mongo::InitializerConte
SSLHandshakeManager::setSslGetServerIdentityFn(
sc->getFunctionAs<SslGetServerIdentityFn>("SslGetServerIdentity").getValue());
-
- return mongo::Status::OK();
}
} // namespace detail
diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp
index 87772d303c8..39228cdfb8c 100644
--- a/src/mongo/util/net/ssl_manager.cpp
+++ b/src/mongo/util/net/ssl_manager.cpp
@@ -633,8 +633,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManagerLogger, ("SSLManager"))
"expiration"_attr = config.serverCertificateExpirationDate);
}
}
-
- return Status::OK();
}
Status SSLX509Name::normalizeStrings() {
diff --git a/src/mongo/util/net/ssl_manager_apple.cpp b/src/mongo/util/net/ssl_manager_apple.cpp
index 6a20c9bbeda..c4547bf28d5 100644
--- a/src/mongo/util/net/ssl_manager_apple.cpp
+++ b/src/mongo/util/net/ssl_manager_apple.cpp
@@ -38,7 +38,6 @@
#include "mongo/base/checked_cast.h"
#include "mongo/base/init.h"
-#include "mongo/base/initializer_context.h"
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
#include "mongo/crypto/sha1_block.h"
@@ -1836,7 +1835,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("EndStartupOptionHandling"))
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
theSSLManagerCoordinator = new SSLManagerCoordinator();
}
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/util/net/ssl_manager_none.cpp b/src/mongo/util/net/ssl_manager_none.cpp
index 696ff2f95a5..178975b2654 100644
--- a/src/mongo/util/net/ssl_manager_none.cpp
+++ b/src/mongo/util/net/ssl_manager_none.cpp
@@ -33,10 +33,8 @@
namespace mongo {
namespace {
-MONGO_INITIALIZER(SSLManager)(InitializerContext*) {
- // we need a no-op initializer so that we can depend on SSLManager as a prerequisite in
- // non-SSL builds.
- return Status::OK();
-}
+// we need a no-op initializer so that we can depend on SSLManager as a prerequisite in
+// non-SSL builds.
+MONGO_INITIALIZER(SSLManager)(InitializerContext*) {}
} // namespace
} // namespace mongo
diff --git a/src/mongo/util/net/ssl_manager_openssl.cpp b/src/mongo/util/net/ssl_manager_openssl.cpp
index cbd75b964f2..1cba80be3a4 100644
--- a/src/mongo/util/net/ssl_manager_openssl.cpp
+++ b/src/mongo/util/net/ssl_manager_openssl.cpp
@@ -1430,7 +1430,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("SetupOpenSSL", "EndStartupOpt
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
theSSLManagerCoordinator = new SSLManagerCoordinator();
}
- return Status::OK();
}
std::shared_ptr<SSLManagerInterface> SSLManagerInterface::create(const SSLParams& params,
diff --git a/src/mongo/util/net/ssl_manager_windows.cpp b/src/mongo/util/net/ssl_manager_windows.cpp
index 8d434e52416..c8cf3f1339d 100644
--- a/src/mongo/util/net/ssl_manager_windows.cpp
+++ b/src/mongo/util/net/ssl_manager_windows.cpp
@@ -43,7 +43,6 @@
#include <winhttp.h>
#include "mongo/base/init.h"
-#include "mongo/base/initializer_context.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/bson/util/builder.h"
#include "mongo/config.h"
diff --git a/src/mongo/util/net/ssl_options_client.cpp b/src/mongo/util/net/ssl_options_client.cpp
index fb40ebb2bc7..6422a37d9e3 100644
--- a/src/mongo/util/net/ssl_options_client.cpp
+++ b/src/mongo/util/net/ssl_options_client.cpp
@@ -51,11 +51,8 @@ MONGO_STARTUP_OPTIONS_STORE(SSLClientOptions)(InitializerContext*) {
}
if (params.count("tls.disabledProtocols")) {
- const auto status =
- storeSSLDisabledProtocols(params["tls.disabledProtocols"].as<std::string>());
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(
+ storeSSLDisabledProtocols(params["tls.disabledProtocols"].as<std::string>()));
#if ((MONGO_CONFIG_SSL_PROVIDER != MONGO_CONFIG_SSL_PROVIDER_OPENSSL) || \
(OPENSSL_VERSION_NUMBER >= 0x100000cf)) /* 1.0.0l */
} else {
@@ -72,17 +69,12 @@ MONGO_STARTUP_OPTIONS_STORE(SSLClientOptions)(InitializerContext*) {
#ifdef MONGO_CONFIG_SSL_CERTIFICATE_SELECTORS
if (params.count("tls.certificateSelector")) {
- const auto status =
+ uassertStatusOK(
parseCertificateSelector(&sslGlobalParams.sslCertificateSelector,
"tls.certificateSelector",
- params["tls.certificateSelector"].as<std::string>());
- if (!status.isOK()) {
- return status;
- }
+ params["tls.certificateSelector"].as<std::string>()));
}
#endif
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/net/ssl_options_server.cpp b/src/mongo/util/net/ssl_options_server.cpp
index 1e21f2d7b22..0b0f0b4e955 100644
--- a/src/mongo/util/net/ssl_options_server.cpp
+++ b/src/mongo/util/net/ssl_options_server.cpp
@@ -95,7 +95,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
if (swMode.isOK()) {
sslGlobalParams.sslMode.store(swMode.getValue());
} else {
- return {ErrorCodes::BadValue, "unsupported value for tlsMode " + sslModeParam};
+ uasserted(ErrorCodes::BadValue, "unsupported value for tlsMode " + sslModeParam);
}
} else if (params.count("net.ssl.mode")) {
std::string sslModeParam = params["net.ssl.mode"].as<string>();
@@ -103,7 +103,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
if (swMode.isOK()) {
sslGlobalParams.sslMode.store(swMode.getValue());
} else {
- return {ErrorCodes::BadValue, "unsupported value for sslMode " + sslModeParam};
+ uasserted(ErrorCodes::BadValue, "unsupported value for sslMode " + sslModeParam);
}
}
@@ -142,9 +142,9 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
23286,
"net.tls.tlsCipherConfig is deprecated. It will be removed in a future release.");
if (sslGlobalParams.sslCipherConfig != kSSLCipherConfigDefault) {
- return {ErrorCodes::BadValue,
- "net.tls.tlsCipherConfig is incompatible with the openTLSCipherConfig "
- "setParameter"};
+ uasserted(ErrorCodes::BadValue,
+ "net.tls.tlsCipherConfig is incompatible with the openTLSCipherConfig "
+ "setParameter");
}
sslGlobalParams.sslCipherConfig = params["net.tls.tlsCipherConfig"].as<string>();
}
@@ -153,9 +153,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
const auto status =
storeSSLDisabledProtocols(params["net.tls.disabledProtocols"].as<string>(),
SSLDisabledProtocolsMode::kAcceptNegativePrefix);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(status);
#if (MONGO_CONFIG_SSL_PROVIDER != MONGO_CONFIG_SSL_PROVIDER_OPENSSL) || \
(OPENSSL_VERSION_NUMBER >= 0x100000cf) /* 1.0.0l */
} else {
@@ -170,10 +168,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
}
if (params.count("net.tls.logVersions")) {
- const auto status = storeTLSLogVersion(params["net.tls.logVersions"].as<string>());
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(storeTLSLogVersion(params["net.tls.logVersions"].as<string>()));
}
#ifdef MONGO_CONFIG_SSL_CERTIFICATE_SELECTORS
@@ -182,9 +177,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
parseCertificateSelector(&sslGlobalParams.sslCertificateSelector,
"net.tls.certificateSelector",
params["net.tls.certificateSelector"].as<std::string>());
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(status);
}
if (params.count("net.tls.clusterCertificateSelector")) {
@@ -192,9 +185,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
&sslGlobalParams.sslClusterCertificateSelector,
"net.tls.clusterCertificateSelector",
params["net.tls.clusterCertificateSelector"].as<std::string>());
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(status);
}
#endif
@@ -202,11 +193,11 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
if (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled) {
bool usingCertifiateSelectors = params.count("net.tls.certificateSelector");
if (sslGlobalParams.sslPEMKeyFile.size() == 0 && !usingCertifiateSelectors) {
- return {ErrorCodes::BadValue,
- "need tlsCertificateKeyFile or certificateSelector when TLS is enabled"};
+ uasserted(ErrorCodes::BadValue,
+ "need tlsCertificateKeyFile or certificateSelector when TLS is enabled");
}
if (!sslGlobalParams.sslCRLFile.empty() && sslGlobalParams.sslCAFile.empty()) {
- return {ErrorCodes::BadValue, "need tlsCAFile with tlsCRLFile"};
+ uasserted(ErrorCodes::BadValue, "need tlsCAFile with tlsCRLFile");
}
std::string sslCANotFoundError(
@@ -218,7 +209,7 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
// X.509 certificates for auth instead of relying on a CA file.
if (sslGlobalParams.sslCAFile.empty() && !usingCertifiateSelectors &&
clusterAuthMode == ServerGlobalParams::ClusterAuthMode_x509) {
- return {ErrorCodes::BadValue, sslCANotFoundError};
+ uasserted(ErrorCodes::BadValue, sslCANotFoundError);
}
} else if (sslGlobalParams.sslPEMKeyFile.size() || sslGlobalParams.sslPEMKeyPassword.size() ||
sslGlobalParams.sslClusterFile.size() || sslGlobalParams.sslClusterPassword.size() ||
@@ -230,16 +221,16 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
params.count("net.tls.clusterCertificateSelector") ||
#endif
sslGlobalParams.sslWeakCertificateValidation) {
- return {ErrorCodes::BadValue,
- "need to enable TLS via the sslMode/tlsMode flag when "
- "using TLS configuration parameters"};
+ uasserted(ErrorCodes::BadValue,
+ "need to enable TLS via the sslMode/tlsMode flag when "
+ "using TLS configuration parameters");
}
if (clusterAuthMode == ServerGlobalParams::ClusterAuthMode_sendKeyFile ||
clusterAuthMode == ServerGlobalParams::ClusterAuthMode_sendX509 ||
clusterAuthMode == ServerGlobalParams::ClusterAuthMode_x509) {
if (sslGlobalParams.sslMode.load() == SSLParams::SSLMode_disabled) {
- return {ErrorCodes::BadValue, "need to enable TLS via the tlsMode flag"};
+ uasserted(ErrorCodes::BadValue, "need to enable TLS via the tlsMode flag");
}
}
@@ -248,12 +239,10 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
if (clusterAuthMode == ServerGlobalParams::ClusterAuthMode_sendX509 ||
(clusterAuthMode == ServerGlobalParams::ClusterAuthMode_x509 &&
!serverGlobalParams.transitionToAuth)) {
- return {ErrorCodes::BadValue,
- "cannot have x.509 cluster authentication in allowTLS mode"};
+ uasserted(ErrorCodes::BadValue,
+ "cannot have x.509 cluster authentication in allowTLS mode");
}
}
-
- return Status::OK();
}
// Alias --tlsOnNormalPorts as --tlsMode=requireTLS
@@ -295,9 +284,7 @@ Status canonicalizeSSLServerOptions(moe::Environment* params) {
MONGO_STARTUP_OPTIONS_VALIDATE(SSLServerOptions)(InitializerContext*) {
auto status = canonicalizeSSLServerOptions(&moe::startupOptionsParsed);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(status);
#ifdef _WIN32
const auto& params = moe::startupOptionsParsed;
@@ -306,31 +293,29 @@ MONGO_STARTUP_OPTIONS_VALIDATE(SSLServerOptions)(InitializerContext*) {
if (params.count("net.tls.certificateKeyFile") &&
!boost::filesystem::path(params["net.tls.certificateKeyFile"].as<string>())
.is_absolute()) {
- return {ErrorCodes::BadValue,
- "PEMKeyFile requires an absolute file path with Windows services"};
+ uasserted(ErrorCodes::BadValue,
+ "PEMKeyFile requires an absolute file path with Windows services");
}
if (params.count("net.tls.clusterFile") &&
!boost::filesystem::path(params["net.tls.clusterFile"].as<string>()).is_absolute()) {
- return {ErrorCodes::BadValue,
- "clusterFile requires an absolute file path with Windows services"};
+ uasserted(ErrorCodes::BadValue,
+ "clusterFile requires an absolute file path with Windows services");
}
if (params.count("net.tls.CAFile") &&
!boost::filesystem::path(params["net.tls.CAFile"].as<string>()).is_absolute()) {
- return {ErrorCodes::BadValue,
- "CAFile requires an absolute file path with Windows services"};
+ uasserted(ErrorCodes::BadValue,
+ "CAFile requires an absolute file path with Windows services");
}
if (params.count("net.tls.CRLFile") &&
!boost::filesystem::path(params["net.tls.CRLFile"].as<string>()).is_absolute()) {
- return {ErrorCodes::BadValue,
- "CRLFile requires an absolute file path with Windows services"};
+ uasserted(ErrorCodes::BadValue,
+ "CRLFile requires an absolute file path with Windows services");
}
}
#endif
-
- return Status::OK();
}
// This warning must be deferred until after
@@ -343,7 +328,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(ImplicitDisableTLS10Warning, ("ServerLogRed
"Automatically disabling TLS 1.0, to force-enable TLS 1.0 "
"specify --sslDisabledProtocols 'none'");
}
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/net/ssl_options_test.cpp b/src/mongo/util/net/ssl_options_test.cpp
index 76ad7f48d0b..c666d9636c2 100644
--- a/src/mongo/util/net/ssl_options_test.cpp
+++ b/src/mongo/util/net/ssl_options_test.cpp
@@ -36,7 +36,6 @@
#include <boost/range/size.hpp>
#include <ostream>
-#include "mongo/base/global_initializer.h"
#include "mongo/base/init.h"
#include "mongo/base/initializer.h"
#include "mongo/db/server_options_base.h"
@@ -54,27 +53,18 @@ namespace moe = mongo::optionenvironment;
namespace mongo {
namespace {
-MONGO_INITIALIZER(ServerLogRedirection)(InitializerContext*) {
- // ssl_options_server.cpp has an initializer which depends on logging.
- // We can stub that dependency out for unit testing purposes.
- return Status::OK();
-}
+// ssl_options_server.cpp has an initializer which depends on logging.
+// We can stub that dependency out for unit testing purposes.
+MONGO_INITIALIZER(ServerLogRedirection)(InitializerContext*) {}
Status executeInitializer(const std::string& name) try {
- const auto* node =
- getGlobalInitializer().getInitializerDependencyGraph().getInitializerNode(name);
- if (!node) {
- return {ErrorCodes::BadValue, str::stream() << "Unknown initializer: '" << name << "'"};
- }
-
- const auto& fn = node->getInitializerFunction();
- if (!fn) {
- return {ErrorCodes::InternalError,
- str::stream() << "Initializer node '" << name << "' has no associated function."};
- }
-
- // The initializers we call don't actually need a context currently.
- return fn(nullptr);
+ InitializerFunction fn = getGlobalInitializer().getInitializerFunctionForTesting(name);
+ uassert(ErrorCodes::InternalError,
+ str::stream() << "Initializer node '" << name << "' has no associated function.",
+ fn);
+ InitializerContext initContext({});
+ fn(&initContext);
+ return Status::OK();
} catch (const DBException& ex) {
return ex.toStatus();
}
diff --git a/src/mongo/util/options_parser/options_parser.cpp b/src/mongo/util/options_parser/options_parser.cpp
index 5a0e5ab8fdb..a01d229514c 100644
--- a/src/mongo/util/options_parser/options_parser.cpp
+++ b/src/mongo/util/options_parser/options_parser.cpp
@@ -85,12 +85,9 @@ bool shouldUseStrict() {
return true;
}
-MONGO_INITIALIZER_GENERAL(OptionsParseUseStrict,
- MONGO_NO_PREREQUISITES,
- ("BeginStartupOptionParsing"))
+MONGO_INITIALIZER_GENERAL(OptionsParseUseStrict, (), ("BeginStartupOptionParsing"))
(InitializerContext* context) {
OptionsParser::useStrict = shouldUseStrict;
- return Status::OK();
}
// The following section contains utility functions that convert between the various objects
diff --git a/src/mongo/util/options_parser/options_parser_init.cpp b/src/mongo/util/options_parser/options_parser_init.cpp
index 304a6d1d152..73272cb8ab5 100644
--- a/src/mongo/util/options_parser/options_parser_init.cpp
+++ b/src/mongo/util/options_parser/options_parser_init.cpp
@@ -51,8 +51,6 @@ MONGO_STARTUP_OPTIONS_PARSE(StartupOptions)(InitializerContext* context) {
std::cerr << "try '" << context->args()[0] << " --help' for more information" << std::endl;
quickExit(EXIT_BADOPTIONS);
}
-
- return Status::OK();
}
MONGO_INITIALIZER_GENERAL(OutputConfig,
@@ -61,16 +59,12 @@ MONGO_INITIALIZER_GENERAL(OutputConfig,
(InitializerContext*) {
if (startupOptionsParsed.count("outputConfig")) {
bool output = false;
- auto status = startupOptionsParsed.get(Key("outputConfig"), &output);
- if (!status.isOK()) {
- return status;
- }
+ uassertStatusOK(startupOptionsParsed.get(Key("outputConfig"), &output));
if (output) {
std::cout << startupOptionsParsed.toYAML() << std::endl;
quickExit(EXIT_CLEAN);
}
}
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/options_parser/startup_option_init.cpp b/src/mongo/util/options_parser/startup_option_init.cpp
index efc1ed82567..6ac10f6098c 100644
--- a/src/mongo/util/options_parser/startup_option_init.cpp
+++ b/src/mongo/util/options_parser/startup_option_init.cpp
@@ -44,12 +44,8 @@ namespace {
std::string makeInitializer(const std::string& name,
const std::vector<std::string>& after,
const std::vector<std::string>& before) {
- uassertStatusOK(getGlobalInitializer().getInitializerDependencyGraph().addInitializer(
- name,
- [](InitializerContext*) { return Status::OK(); },
- [](DeinitializerContext*) { return Status::OK(); },
- after,
- before));
+ getGlobalInitializer().addInitializer(
+ name, [](InitializerContext*) {}, [](DeinitializerContext*) {}, after, before);
return name;
}
diff --git a/src/mongo/util/perfctr_collect.cpp b/src/mongo/util/perfctr_collect.cpp
index 8ee4067b146..6e9ae1dc0f2 100644
--- a/src/mongo/util/perfctr_collect.cpp
+++ b/src/mongo/util/perfctr_collect.cpp
@@ -55,12 +55,10 @@ MONGO_INITIALIZER(PdhInit)(InitializerContext* context) {
hPdhLibrary = LoadLibraryW(L"pdh.dll");
if (nullptr == hPdhLibrary) {
DWORD gle = GetLastError();
- return {ErrorCodes::WindowsPdhError,
- str::stream() << "LoadLibrary of pdh.dll failed with "
- << errnoWithDescription(gle)};
+ uasserted(ErrorCodes::WindowsPdhError,
+ str::stream() << "LoadLibrary of pdh.dll failed with "
+ << errnoWithDescription(gle));
}
-
- return Status::OK();
}
/**
diff --git a/src/mongo/util/platform_init.cpp b/src/mongo/util/platform_init.cpp
index ac75975440f..28cfd6cb9f9 100644
--- a/src/mongo/util/platform_init.cpp
+++ b/src/mongo/util/platform_init.cpp
@@ -113,8 +113,6 @@ MONGO_INITIALIZER(Behaviors_Win32)(InitializerContext*) {
std::min(std::max(int(tc.wPeriodMin), targetResolution), int(tc.wPeriodMax));
invariant(timeBeginPeriod(timerResolution) == TIMERR_NOERROR);
}
-
- return Status::OK();
}
} // namespace mongo
diff --git a/src/mongo/util/processinfo.cpp b/src/mongo/util/processinfo.cpp
index 558415a1705..197ebe00848 100644
--- a/src/mongo/util/processinfo.cpp
+++ b/src/mongo/util/processinfo.cpp
@@ -46,7 +46,6 @@ namespace mongo {
namespace {
MONGO_INITIALIZER(initApplicationInfo)(InitializerContext* context) {
ProcessInfo().appInfo().init(context->args());
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/stacktrace_somap.cpp b/src/mongo/util/stacktrace_somap.cpp
index 767bd42a521..947114affae 100644
--- a/src/mongo/util/stacktrace_somap.cpp
+++ b/src/mongo/util/stacktrace_somap.cpp
@@ -349,7 +349,6 @@ SharedObjectMapInfo& mutableGlobalSharedObjectMapInfo() {
MONGO_INITIALIZER(ExtractSOMap)(InitializerContext*) {
// Call buildObj() again now that there is better VersionInfo.
mutableGlobalSharedObjectMapInfo().setObj(buildObj());
- return Status::OK();
}
const bool dummyToForceEarlyInitializationOfSharedObjectMapInfo = [] {
diff --git a/src/mongo/util/stacktrace_windows.cpp b/src/mongo/util/stacktrace_windows.cpp
index c95911d112c..99ceea9e937 100644
--- a/src/mongo/util/stacktrace_windows.cpp
+++ b/src/mongo/util/stacktrace_windows.cpp
@@ -142,9 +142,6 @@ MONGO_INITIALIZER(IntializeSymbolHandler)(::mongo::InitializerContext* ctx) {
// context. The constructor of SymbolHandler does all the error handling, so we don't need to
// do anything with the return value. Just make sure it gets called.
SymbolHandler::instance();
-
- // Initializing the symbol handler is not a fatal error, so we always return Status::OK() here.
- return Status::OK();
}
/**
diff --git a/src/mongo/util/system_tick_source.cpp b/src/mongo/util/system_tick_source.cpp
index 12defed767c..a11de88fd16 100644
--- a/src/mongo/util/system_tick_source.cpp
+++ b/src/mongo/util/system_tick_source.cpp
@@ -142,7 +142,6 @@ void initTickSource() {}
MONGO_INITIALIZER(SystemTickSourceInit)(InitializerContext* context) {
initTickSource();
SystemTickSource::get();
- return Status::OK();
}
TickSource::Tick SystemTickSource::getTicks() {
diff --git a/src/mongo/util/tcmalloc_set_parameter.cpp b/src/mongo/util/tcmalloc_set_parameter.cpp
index 898d9af9abd..d8ab1f3939f 100644
--- a/src/mongo/util/tcmalloc_set_parameter.cpp
+++ b/src/mongo/util/tcmalloc_set_parameter.cpp
@@ -123,14 +123,12 @@ TCMALLOC_SP_METHODS(AggressiveMemoryDecommit)
namespace {
-MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults,
- MONGO_NO_PREREQUISITES,
- ("BeginStartupOptionHandling"))
+MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults, (), ("BeginStartupOptionHandling"))
(InitializerContext*) {
// Before processing the command line options, if the user has not specified a value in via
// the environment, set tcmalloc.max_total_thread_cache_bytes to its default value.
if (getenv("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES")) {
- return Status::OK();
+ return;
}
ProcessInfo pi;
@@ -140,7 +138,7 @@ MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults,
(systemMemorySizeMB / 8) * 1024 * 1024; // 1/8 of system memory in bytes
size_t cacheSize = std::min(defaultTcMallocCacheSize, derivedTcMallocCacheSize);
- return setProperty(kMaxTotalThreadCacheBytesPropertyName, cacheSize);
+ uassertStatusOK(setProperty(kMaxTotalThreadCacheBytesPropertyName, cacheSize));
}
} // namespace
diff --git a/src/mongo/util/testing_options.cpp b/src/mongo/util/testing_options.cpp
index dcf98b10a11..32ca0896ef7 100644
--- a/src/mongo/util/testing_options.cpp
+++ b/src/mongo/util/testing_options.cpp
@@ -58,8 +58,6 @@ MONGO_INITIALIZER_GENERAL(TestingDiagnostics,
"Testing behaviors are enabled. This has serious implications for both "
"performance and security.");
}
-
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/testing_proctor.cpp b/src/mongo/util/testing_proctor.cpp
index f9f378fb687..416d482ab62 100644
--- a/src/mongo/util/testing_proctor.cpp
+++ b/src/mongo/util/testing_proctor.cpp
@@ -73,7 +73,6 @@ MONGO_INITIALIZER(DisableTestingDiagnosticsByDefault)(InitializerContext*) {
if (!TestingProctor::instance().isInitialized()) {
TestingProctor::instance().setEnabled(false);
}
- return Status::OK();
}
} // namespace
diff --git a/src/mongo/util/thread_context.cpp b/src/mongo/util/thread_context.cpp
index 3bcde4a9fdf..e08122a4405 100644
--- a/src/mongo/util/thread_context.cpp
+++ b/src/mongo/util/thread_context.cpp
@@ -43,7 +43,6 @@ thread_local ThreadContext::Handle ThreadContext::_handle;
MONGO_INITIALIZER(ThreadContextsInitialized)(InitializerContext*) {
ThreadContext::initializeMain();
- return Status::OK();
}
void ThreadContext::initializeMain() {
diff --git a/src/mongo/util/time_support_test.cpp b/src/mongo/util/time_support_test.cpp
index 635e468692c..17dc35f58f3 100644
--- a/src/mongo/util/time_support_test.cpp
+++ b/src/mongo/util/time_support_test.cpp
@@ -59,10 +59,9 @@ char tzEnvString[] = "TZ=America/New_York";
#pragma warning(disable : 4996)
MONGO_INITIALIZER(SetTimeZoneToEasternForTest)(InitializerContext*) {
if (-1 == putenv(tzEnvString)) {
- return Status(ErrorCodes::BadValue, errnoWithDescription());
+ uasserted(ErrorCodes::BadValue, errnoWithDescription());
}
tzset();
- return Status::OK();
}
#pragma warning(pop)
diff --git a/src/mongo/util/version_impl.cpp b/src/mongo/util/version_impl.cpp
index c729751f0b9..d28459aae90 100644
--- a/src/mongo/util/version_impl.cpp
+++ b/src/mongo/util/version_impl.cpp
@@ -99,12 +99,9 @@ public:
const InterpolatedVersionInfo interpolatedVersionInfo;
-MONGO_INITIALIZER_GENERAL(EnableVersionInfo,
- MONGO_NO_PREREQUISITES,
- ("BeginStartupOptionRegistration"))
+MONGO_INITIALIZER_GENERAL(EnableVersionInfo, (), ("BeginStartupOptionRegistration"))
(InitializerContext*) {
VersionInfoInterface::enable(&interpolatedVersionInfo);
- return Status::OK();
}
} // namespace