summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-07-14 19:43:14 -0400
committerSpencer T Brody <spencer@mongodb.com>2015-07-16 11:37:38 -0400
commitca7c55af9d787cd8456a313a2d5e7bf56cadf36e (patch)
tree78166ae17e9e138ff9b0c85f3a33850251abdf94
parent2689d44d91d9d9e4dcbdb442d788adcc10ab49dd (diff)
downloadmongo-ca7c55af9d787cd8456a313a2d5e7bf56cadf36e.tar.gz
SERVER-19414 Unify global sharding state initialization between mongos and mongod
-rw-r--r--src/mongo/SConscript5
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/sharding_state.cpp19
-rw-r--r--src/mongo/s/SConscript14
-rw-r--r--src/mongo/s/server.cpp22
-rw-r--r--src/mongo/s/sharding_initialization.cpp67
-rw-r--r--src/mongo/s/sharding_initialization.h42
7 files changed, 130 insertions, 40 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index c66798e4e0c..fd95187afea 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -236,15 +236,12 @@ env.Install(
'db/conn_pool_options',
'db/coredb',
'db/mongodandmongos',
- 'db/repl/replication_executor',
- 'executor/network_interface_factory',
- 's/catalog/legacy/catalog_manager_legacy',
- 's/catalog/replset/catalog_manager_replica_set',
's/client/sharding_connection_hook',
's/commands/cluster_commands',
's/commands/shared_cluster_commands',
's/coreshard',
's/mongoscore',
+ 's/sharding_initialization',
'util/ntservice',
'util/options_parser/options_parser_init',
]))
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 43ef1ef14e3..dd07491dcf8 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -31,6 +31,7 @@ env.Library(
'$BUILD_DIR/mongo/bson/bson',
'$BUILD_DIR/mongo/bson/util/bson_extract',
'$BUILD_DIR/mongo/db/common',
+ '$BUILD_DIR/mongo/s/sharding_initialization',
]
)
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index b0acbada38e..92f68371dac 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -36,18 +36,15 @@
#include "mongo/db/client.h"
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/repl/replication_executor.h"
#include "mongo/db/s/collection_metadata.h"
#include "mongo/db/s/metadata_loader.h"
#include "mongo/db/s/sharded_connection_info.h"
-#include "mongo/executor/network_interface_factory.h"
-#include "mongo/executor/task_executor.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/type_chunk.h"
-#include "mongo/s/catalog/legacy/catalog_manager_legacy.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/grid.h"
+#include "mongo/s/sharding_initialization.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/sock.h"
@@ -122,19 +119,7 @@ void ShardingState::initialize(const string& server) {
str::stream() << "Invalid config server connection string: " << errmsg,
configServerCS.isValid());
- auto catalogManager = stdx::make_unique<CatalogManagerLegacy>();
- uassertStatusOK(catalogManager->init(configServerCS));
-
- auto network = executor::makeNetworkInterface();
- auto networkPtr = network.get();
- auto shardRegistry(stdx::make_unique<ShardRegistry>(
- stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
- stdx::make_unique<repl::ReplicationExecutor>(network.release(), nullptr, 0),
- networkPtr));
- shardRegistry->init(catalogManager.get());
- shardRegistry->startup();
-
- grid.init(std::move(catalogManager), std::move(shardRegistry));
+ uassertStatusOK(initializeGlobalShardingState(configServerCS));
_enabled = true;
}
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 8cd2540322a..47d58ee02e6 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -11,6 +11,20 @@ env.SConscript(
],
)
+# Functionality for initializing global sharding state
+env.Library(
+ target='sharding_initialization',
+ source=[
+ 'sharding_initialization.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/db/repl/replication_executor', # TODO: change to thread pool executor
+ '$BUILD_DIR/mongo/executor/network_interface_factory',
+ '$BUILD_DIR/mongo/s/catalog/legacy/catalog_manager_legacy',
+ '$BUILD_DIR/mongo/s/catalog/replset/catalog_manager_replica_set',
+ ]
+)
+
# Functionality shared between mongod and mongos
env.Library(
target='common',
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index c413a171988..4d227cc0dc9 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -52,22 +52,19 @@
#include "mongo/db/instance.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/log_process_details.h"
-#include "mongo/db/repl/replication_executor.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_noop.h"
#include "mongo/db/startup_warnings_common.h"
-#include "mongo/executor/network_interface_factory.h"
-#include "mongo/executor/task_executor.h"
#include "mongo/platform/process_id.h"
#include "mongo/s/balance.h"
-#include "mongo/s/catalog/legacy/catalog_manager_legacy.h"
-#include "mongo/s/client/shard_registry.h"
+#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/client/sharding_connection_hook.h"
#include "mongo/s/config.h"
#include "mongo/s/cursors.h"
#include "mongo/s/grid.h"
#include "mongo/s/mongos_options.h"
#include "mongo/s/request.h"
+#include "mongo/s/sharding_initialization.h"
#include "mongo/s/version_mongos.h"
#include "mongo/stdx/memory.h"
#include "mongo/stdx/thread.h"
@@ -197,24 +194,11 @@ DBClientBase* createDirectClient(OperationContext* txn) {
using namespace mongo;
static Status initializeSharding(bool doUpgrade) {
- auto network = executor::makeNetworkInterface();
- auto networkPtr = network.get();
- auto shardRegistry(stdx::make_unique<ShardRegistry>(
- stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
- stdx::make_unique<repl::ReplicationExecutor>(network.release(), nullptr, 0),
- networkPtr));
-
- auto catalogManager = stdx::make_unique<CatalogManagerLegacy>();
- Status status = catalogManager->init(mongosGlobalParams.configdbs);
+ Status status = initializeGlobalShardingState(mongosGlobalParams.configdbs);
if (!status.isOK()) {
return status;
}
- shardRegistry->init(catalogManager.get());
- shardRegistry->startup();
- grid.init(std::move(catalogManager), std::move(shardRegistry));
-
-
status = grid.catalogManager()->checkAndUpgrade(!doUpgrade);
if (!status.isOK()) {
return status;
diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp
new file mode 100644
index 00000000000..4b9b30a66f0
--- /dev/null
+++ b/src/mongo/s/sharding_initialization.cpp
@@ -0,0 +1,67 @@
+/**
+ * Copyright (C) 2015 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.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/s/sharding_initialization.h"
+
+#include "mongo/client/remote_command_targeter_factory_impl.h"
+#include "mongo/executor/network_interface_factory.h"
+#include "mongo/executor/task_executor.h"
+#include "mongo/db/repl/replication_executor.h"
+#include "mongo/s/catalog/legacy/catalog_manager_legacy.h"
+#include "mongo/s/client/shard_registry.h"
+#include "mongo/s/grid.h"
+#include "mongo/stdx/memory.h"
+
+namespace mongo {
+
+Status initializeGlobalShardingState(const ConnectionString& configCS) {
+ auto network = executor::makeNetworkInterface();
+ auto networkPtr = network.get();
+ auto shardRegistry(stdx::make_unique<ShardRegistry>(
+ stdx::make_unique<RemoteCommandTargeterFactoryImpl>(),
+ stdx::make_unique<repl::ReplicationExecutor>(network.release(), nullptr, 0),
+ networkPtr));
+
+ auto catalogManager = stdx::make_unique<CatalogManagerLegacy>();
+ Status status = catalogManager->init(configCS);
+ if (!status.isOK()) {
+ return status;
+ }
+
+ shardRegistry->init(catalogManager.get());
+ shardRegistry->startup();
+ grid.init(std::move(catalogManager), std::move(shardRegistry));
+
+ return Status::OK();
+}
+
+} // namespace mongo
diff --git a/src/mongo/s/sharding_initialization.h b/src/mongo/s/sharding_initialization.h
new file mode 100644
index 00000000000..22bf9623f3e
--- /dev/null
+++ b/src/mongo/s/sharding_initialization.h
@@ -0,0 +1,42 @@
+/**
+ * Copyright (C) 2015 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.
+ */
+
+#pragma once
+
+#include "mongo/base/status.h"
+#include "mongo/client/connection_string.h"
+
+namespace mongo {
+
+/**
+ * Takes in the connection string for reaching the config servers and initializes the global
+ * CatalogManager, ShardingRegistry, and grid objects.
+ */
+Status initializeGlobalShardingState(const ConnectionString& configCS);
+
+} // namespace mongo