diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-07-14 18:33:39 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-07-16 11:37:38 -0400 |
commit | 6b5142950b1b5452fc29621ee01abe9c81eaee2c (patch) | |
tree | 7a9c75ade059781381e04ce7c9eac46935cd43f6 /src/mongo/s | |
parent | 69861af0f5d1f569d04b22fbf3ad408403aeca27 (diff) | |
download | mongo-6b5142950b1b5452fc29621ee01abe9c81eaee2c.tar.gz |
SERVER-19414 Clean up ShardRegistry initialization
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.cpp | 14 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.h | 13 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 78 |
5 files changed, 65 insertions, 51 deletions
diff --git a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp index c2c523ebdc2..71b38ef2ade 100644 --- a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp +++ b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp @@ -110,11 +110,9 @@ private: _networkTestEnv = stdx::make_unique<NetworkTestEnv>(executor.get(), network); - _shardRegistry = - stdx::make_unique<ShardRegistry>(stdx::make_unique<RemoteCommandTargeterFactoryMock>(), - std::move(executor), - network, - &_catalogMgr); + _shardRegistry = stdx::make_unique<ShardRegistry>( + stdx::make_unique<RemoteCommandTargeterFactoryMock>(), std::move(executor), network); + _shardRegistry->init(&_catalogMgr); _shardRegistry->startup(); _distLockCatalog = diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp index 1bcf4b1f943..6d7c1b933f1 100644 --- a/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp +++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set_test_fixture.cpp @@ -98,7 +98,8 @@ void CatalogManagerReplSetTestFixture::setUp() { _targeterFactory->addTargeterToReturn(cm->connectionString(), std::move(configTargeter)); auto shardRegistry(stdx::make_unique<ShardRegistry>( - std::move(targeterFactory), std::move(executor), _mockNetwork, cm.get())); + std::move(targeterFactory), std::move(executor), _mockNetwork)); + shardRegistry->init(cm.get()); shardRegistry->startup(); // For now initialize the global grid object. All sharding objects will be accessible diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index 1445d181e0e..5d79a794871 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -63,19 +63,23 @@ const Seconds kConfigCommandTimeout{30}; ShardRegistry::ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory, std::unique_ptr<executor::TaskExecutor> executor, - executor::NetworkInterface* network, - CatalogManager* catalogManager) + executor::NetworkInterface* network) : _targeterFactory(std::move(targeterFactory)), _executor(std::move(executor)), _network(network), - _catalogManager(catalogManager) { + _catalogManager(nullptr) {} + +ShardRegistry::~ShardRegistry() = default; + +void ShardRegistry::init(CatalogManager* catalogManager) { + invariant(!_catalogManager); + _catalogManager = catalogManager; + // add config shard registry entry so know it's always there stdx::lock_guard<stdx::mutex> lk(_mutex); _addConfigShard_inlock(); } -ShardRegistry::~ShardRegistry() = default; - void ShardRegistry::startup() { _executor->startup(); } diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index a3357083a16..27e4f94f701 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -76,12 +76,17 @@ public: */ ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory, std::unique_ptr<executor::TaskExecutor> executor, - executor::NetworkInterface* network, - CatalogManager* catalogManager); + executor::NetworkInterface* network); ~ShardRegistry(); /** + * Stores the given CatalogManager into _catalogManager for use for retrieving the list of + * registered shards, and creates the hard-coded config shard. + */ + void init(CatalogManager* catalogManager); + + /** * Invokes the executor's startup method, which will start any networking/async execution * threads. */ @@ -178,8 +183,8 @@ private: executor::NetworkInterface* const _network; // Catalog manager from which to load the shard information. Not owned and must outlive - // the shard registry object. - CatalogManager* const _catalogManager; + // the shard registry object. Should be set once by a call to init() then never modified again. + CatalogManager* _catalogManager; // Protects the maps below mutable stdx::mutex _mutex; diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 14e72cf4dbe..c413a171988 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -196,6 +196,41 @@ 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); + 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; + } + + if (doUpgrade) { + return Status::OK(); + } + + status = grid.catalogManager()->startup(); + if (!status.isOK()) { + return status; + } + return Status::OK(); +} + static ExitCode runMongosServer(bool doUpgrade) { setThreadName("mongosMain"); printShardingVersionInfo(false); @@ -217,42 +252,13 @@ static ExitCode runMongosServer(bool doUpgrade) { dbexit(EXIT_BADOPTIONS); } - auto catalogManager = stdx::make_unique<CatalogManagerLegacy>(); - - { - Status statusCatalogManagerInit = catalogManager->init(mongosGlobalParams.configdbs); - if (!statusCatalogManagerInit.isOK()) { - error() << "couldn't initialize catalog manager " << statusCatalogManagerInit; - return EXIT_SHARDING_ERROR; - } + Status status = initializeSharding(doUpgrade); + if (!status.isOK()) { + error() << "Error initializing sharding system: " << status; + return EXIT_SHARDING_ERROR; } - - auto shardRegistry(stdx::make_unique<ShardRegistry>( - stdx::make_unique<RemoteCommandTargeterFactoryImpl>(), - stdx::make_unique<repl::ReplicationExecutor>( - executor::makeNetworkInterface().release(), nullptr, 0), - nullptr, - catalogManager.get())); - shardRegistry->startup(); - - grid.init(std::move(catalogManager), std::move(shardRegistry)); - - { - auto upgradeStatus = grid.catalogManager()->checkAndUpgrade(!doUpgrade); - if (!upgradeStatus.isOK()) { - error() << causedBy(upgradeStatus); - return EXIT_SHARDING_ERROR; - } - - if (doUpgrade) { - return EXIT_CLEAN; - } - - Status startupStatus = grid.catalogManager()->startup(); - if (!startupStatus.isOK()) { - error() << "Mongos catalog manager startup failed: " << startupStatus; - return EXIT_SHARDING_ERROR; - } + if (doUpgrade) { + return EXIT_CLEAN; } ConfigServer::reloadSettings(); @@ -270,7 +276,7 @@ static ExitCode runMongosServer(bool doUpgrade) { web.detach(); } - Status status = getGlobalAuthorizationManager()->initialize(NULL); + status = getGlobalAuthorizationManager()->initialize(NULL); if (!status.isOK()) { error() << "Initializing authorization data failed: " << status; return EXIT_SHARDING_ERROR; |