diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2016-12-05 16:54:29 -0500 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2016-12-05 17:00:24 -0500 |
commit | 20ce1aa922673f758cc6c2edc47146c6314a4f57 (patch) | |
tree | 3ece6785ee81871af86f68bef3a86d4361c3d32b | |
parent | 25a351ee3225f3f957beb483d70382a19b7e2a0a (diff) | |
download | mongo-20ce1aa922673f758cc6c2edc47146c6314a4f57.tar.gz |
SERVER-27211 de-duplicate symbol `isMongos`
A hidden global variable representing the "is Mongos process" state
can now be accessed and updated by the `is_mongos.h` interface. All
tests defining their own versions (and test crutches) are replaced
with calls to global registration of the desired state of this variable.
The `mongos` main executable now sets this hidden global state as part
of its startup code.
21 files changed, 48 insertions, 100 deletions
diff --git a/src/mongo/db/pipeline/SConscript b/src/mongo/db/pipeline/SConscript index 3aeea52b08c..ac7ab097c07 100644 --- a/src/mongo/db/pipeline/SConscript +++ b/src/mongo/db/pipeline/SConscript @@ -143,6 +143,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/db/query/query_test_service_context', '$BUILD_DIR/mongo/db/service_context', + '$BUILD_DIR/mongo/s/is_mongos', '$BUILD_DIR/mongo/util/clock_source_mock', ], ) @@ -302,6 +303,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/db/query/query_test_service_context', '$BUILD_DIR/mongo/db/service_context_noop_init', + '$BUILD_DIR/mongo/s/is_mongos', ], ) @@ -325,6 +327,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/db/query/query_test_service_context', '$BUILD_DIR/mongo/db/service_context_noop_init', + '$BUILD_DIR/mongo/s/is_mongos', 'document_source_facet', 'document_value_test_util', ], @@ -336,6 +339,7 @@ env.CppUnitTest( LIBDEPS=[ '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init', '$BUILD_DIR/mongo/db/service_context_noop_init', + '$BUILD_DIR/mongo/s/is_mongos', 'document_source_facet', 'document_value_test_util', ], @@ -373,6 +377,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/db/query/query_test_service_context', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/service_context_noop_init', + '$BUILD_DIR/mongo/s/is_mongos', 'document_value_test_util', 'document_source_lookup', 'pipeline', diff --git a/src/mongo/db/pipeline/document_source_facet_test.cpp b/src/mongo/db/pipeline/document_source_facet_test.cpp index 72d79fd56fe..733634b8994 100644 --- a/src/mongo/db/pipeline/document_source_facet_test.cpp +++ b/src/mongo/db/pipeline/document_source_facet_test.cpp @@ -50,11 +50,6 @@ namespace mongo { using std::deque; using std::vector; -// Crutch. -bool isMongos() { - return false; -} - namespace { using std::deque; diff --git a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp index ddddfe5f5a9..f96e3521017 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp @@ -43,11 +43,6 @@ namespace mongo { -// Crutch. -bool isMongos() { - return false; -} - namespace { // This provides access to getExpCtx(), but we'll use a different name for this test suite. diff --git a/src/mongo/db/pipeline/document_source_sort_test.cpp b/src/mongo/db/pipeline/document_source_sort_test.cpp index 52da88fd616..233e200f374 100644 --- a/src/mongo/db/pipeline/document_source_sort_test.cpp +++ b/src/mongo/db/pipeline/document_source_sort_test.cpp @@ -49,11 +49,6 @@ namespace mongo { -// Crutch. -bool isMongos() { - return false; -} - namespace { using boost::intrusive_ptr; diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp index 7b4331d60b8..41cd6e567d3 100644 --- a/src/mongo/db/pipeline/pipeline_test.cpp +++ b/src/mongo/db/pipeline/pipeline_test.cpp @@ -46,12 +46,6 @@ #include "mongo/db/query/query_test_service_context.h" #include "mongo/dbtests/dbtests.h" -namespace mongo { -bool isMongos() { - return false; -} -} - namespace PipelineTests { using boost::intrusive_ptr; diff --git a/src/mongo/db/pipeline/tee_buffer_test.cpp b/src/mongo/db/pipeline/tee_buffer_test.cpp index 0a8fc7d22a2..2e4495c3d5f 100644 --- a/src/mongo/db/pipeline/tee_buffer_test.cpp +++ b/src/mongo/db/pipeline/tee_buffer_test.cpp @@ -37,12 +37,6 @@ #include "mongo/util/assert_util.h" namespace mongo { - -// Crutch. -bool isMongos() { - return false; -} - namespace { TEST(TeeBufferTest, ShouldRequireAtLeastOneConsumer) { diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 53e74c1d5e3..e9c17720d76 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -69,6 +69,7 @@ env.Library( '$BUILD_DIR/mongo/bson/util/bson_extract', '$BUILD_DIR/mongo/db/common', '$BUILD_DIR/mongo/s/sharding_initialization', + '$BUILD_DIR/mongo/s/is_mongos', 'metadata', 'migration_types', 'type_shard_identity', diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp index bd6867ddc6d..f9785b5325d 100644 --- a/src/mongo/db/s/sharding_state.cpp +++ b/src/mongo/db/s/sharding_state.cpp @@ -818,12 +818,4 @@ void ShardingState::_initializeRangeDeleterTaskExecutor() { executor::ThreadPoolTaskExecutor* ShardingState::getRangeDeleterTaskExecutor() { return _rangeDeleterTaskExecutor.get(); } - -/** - * Global free function. - */ -bool isMongos() { - return false; -} - } // namespace mongo diff --git a/src/mongo/db/sorter/SConscript b/src/mongo/db/sorter/SConscript index 959f6cdb919..365c1a91f54 100644 --- a/src/mongo/db/sorter/SConscript +++ b/src/mongo/db/sorter/SConscript @@ -7,4 +7,5 @@ sorterEnv.CppUnitTest('sorter_test', LIBDEPS=['$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/wiredtiger/storage_wiredtiger_customization_hooks', '$BUILD_DIR/mongo/db/storage/storage_options', + '$BUILD_DIR/mongo/s/is_mongos', '$BUILD_DIR/third_party/shim_snappy']) diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp index 19171fb13ba..1bf02fdcbf3 100644 --- a/src/mongo/db/sorter/sorter_test.cpp +++ b/src/mongo/db/sorter/sorter_test.cpp @@ -52,12 +52,6 @@ using namespace mongo::sorter; using std::make_shared; using std::pair; -// Stub to avoid including the server_options library -// TODO: This should go away once we can do these checks at compile time -bool isMongos() { - return false; -} - // Stub to avoid including the server environment library. MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { setGlobalServiceContext(stdx::make_unique<ServiceContextNoop>()); diff --git a/src/mongo/db/views/SConscript b/src/mongo/db/views/SConscript index 5ba5607297a..fc5ba8b83a1 100644 --- a/src/mongo/db/views/SConscript +++ b/src/mongo/db/views/SConscript @@ -39,7 +39,6 @@ env.CppUnitTest( 'resolved_view_test.cpp', 'view_catalog_test.cpp', 'view_definition_test.cpp', - 'view_test_crutch.cpp' ], LIBDEPS=[ 'views', @@ -47,6 +46,7 @@ env.CppUnitTest( '$BUILD_DIR/mongo/db/query/collation/collator_interface_mock', '$BUILD_DIR/mongo/db/query/query_test_service_context', '$BUILD_DIR/mongo/db/service_context_noop_init', + '$BUILD_DIR/mongo/s/is_mongos', '$BUILD_DIR/mongo/unittest/unittest', ], ) diff --git a/src/mongo/db/views/resolved_view_test.cpp b/src/mongo/db/views/resolved_view_test.cpp index f47b980fba1..2221704e69a 100644 --- a/src/mongo/db/views/resolved_view_test.cpp +++ b/src/mongo/db/views/resolved_view_test.cpp @@ -36,7 +36,6 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/pipeline/aggregation_request.h" #include "mongo/db/views/resolved_view.h" -#include "mongo/db/views/view_test_crutch.h" #include "mongo/unittest/unittest.h" namespace mongo { diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp index 4c93b7d1d18..1a034533a58 100644 --- a/src/mongo/db/views/view_catalog_test.cpp +++ b/src/mongo/db/views/view_catalog_test.cpp @@ -45,7 +45,6 @@ #include "mongo/db/views/view.h" #include "mongo/db/views/view_catalog.h" #include "mongo/db/views/view_graph.h" -#include "mongo/db/views/view_test_crutch.h" #include "mongo/stdx/functional.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" diff --git a/src/mongo/db/views/view_definition_test.cpp b/src/mongo/db/views/view_definition_test.cpp index e61ddaa1b8d..b815324b687 100644 --- a/src/mongo/db/views/view_definition_test.cpp +++ b/src/mongo/db/views/view_definition_test.cpp @@ -37,7 +37,6 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/db/views/view.h" -#include "mongo/db/views/view_test_crutch.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" diff --git a/src/mongo/db/views/view_test_crutch.cpp b/src/mongo/db/views/view_test_crutch.cpp deleted file mode 100644 index ac4434c1911..00000000000 --- a/src/mongo/db/views/view_test_crutch.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2016 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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 - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * 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 GNU Affero General 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/db/views/view_test_crutch.h" - -namespace mongo { -bool isMongos() { - return false; -} -} // namespace mongo diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 2ccbe5b43e4..80fc2930396 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -273,6 +273,14 @@ env.Library( ) env.Library( + target='is_mongos', + source=[ + 'is_mongos.cpp', + ], + LIBDEPS=[], +) + +env.Library( target='mongoscore', source=[ 'chunk_manager_targeter.cpp', @@ -292,6 +300,7 @@ env.Library( '$BUILD_DIR/mongo/s/query/cluster_query', '$BUILD_DIR/mongo/util/concurrency/task', 'cluster_last_error_info', + 'is_mongos', 'write_ops/cluster_write_op', 'write_ops/cluster_write_op_conversion', ], diff --git a/src/mongo/s/is_mongos.cpp b/src/mongo/s/is_mongos.cpp new file mode 100644 index 00000000000..cef0d4c57ef --- /dev/null +++ b/src/mongo/s/is_mongos.cpp @@ -0,0 +1,15 @@ +#include "mongo/s/is_mongos.h" + +namespace mongo { +namespace { +bool mongosState = false; +} // namespace +} // namespace mongo + +bool mongo::isMongos() { + return mongosState; +} + +void mongo::setMongos(const bool state) { + mongosState = state; +} diff --git a/src/mongo/db/views/view_test_crutch.h b/src/mongo/s/is_mongos.h index 8304a29e342..8c3593e599f 100644 --- a/src/mongo/db/views/view_test_crutch.h +++ b/src/mongo/s/is_mongos.h @@ -1,5 +1,5 @@ -/** - * Copyright (C) 2016 MongoDB Inc. +/* + * Copyright (C) 2016 10gen Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, @@ -17,20 +17,21 @@ * 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 GNU Affero General 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. + * must comply with the GNU Affero General 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 { -/** - * Stub for unit tests to avoid including the server_options library. - */ +/** Returns true when the running process is `mongos` and false otherwise. */ bool isMongos(); + +/** Set the global state flag indicating whether the running process is `mongos` or not. */ +void setMongos(const bool state = true); } // namespace mongo diff --git a/src/mongo/s/mongos_options.h b/src/mongo/s/mongos_options.h index 8ac3a1d9321..3e2f5ff4623 100644 --- a/src/mongo/s/mongos_options.h +++ b/src/mongo/s/mongos_options.h @@ -31,6 +31,7 @@ #include "mongo/base/status.h" #include "mongo/client/connection_string.h" #include "mongo/db/server_options.h" +#include "mongo/s/is_mongos.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" @@ -78,8 +79,4 @@ Status validateMongosOptions(const moe::Environment& params); Status canonicalizeMongosOptions(moe::Environment* params); Status storeMongosOptions(const moe::Environment& params); - -// This function should eventually go away, but needs to be here now because the sorter and -// the version manager must know at runtime which binary it is in. -bool isMongos(); } diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index 2fcfc4c30b2..e012c9045a5 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -56,10 +56,6 @@ namespace mongo { using std::string; using std::stringstream; -bool isMongos() { - return true; -} - /** * When this callback is run, we record a shard that we've used for useful work in an operation to * be read later by getLastError() diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 44569f4081a..2bad7e6063f 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -73,6 +73,7 @@ #include "mongo/s/commands/request.h" #include "mongo/s/config.h" #include "mongo/s/grid.h" +#include "mongo/s/is_mongos.h" #include "mongo/s/mongos_options.h" #include "mongo/s/query/cluster_cursor_cleanup_job.h" #include "mongo/s/query/cluster_cursor_manager.h" @@ -435,6 +436,7 @@ MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManage #endif int mongoSMain(int argc, char* argv[], char** envp) { + mongo::setMongos(); static StaticObserver staticObserver; if (argc < 1) return EXIT_FAILURE; |