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 6ae0480db708d..b9fe304530e80 100644 --- a/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp +++ b/src/mongo/s/catalog/dist_lock_catalog_impl_test.cpp @@ -117,7 +117,6 @@ class DistLockCatalogFixture : public mongo::unittest::Test { std::move(executor), network, configCS); - _shardRegistry->init(&_catalogMgr); _shardRegistry->startup(); _distLockCatalog = stdx::make_unique(_shardRegistry.get(), kWTimeout); 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 cf83e61a47e8e..f0f73389d3931 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 @@ -106,7 +106,6 @@ void CatalogManagerReplSetTestFixture::setUp() { auto shardRegistry(stdx::make_unique( std::move(targeterFactory), std::move(executor), _mockNetwork, configCS)); - 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 61544f4a7346c..bd5b885dac103 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -44,6 +44,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/client/shard.h" #include "mongo/s/client/shard_connection.h" +#include "mongo/s/grid.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/mutex.h" #include "mongo/util/log.h" @@ -72,18 +73,12 @@ ShardRegistry::ShardRegistry(std::unique_ptr targe : _targeterFactory(std::move(targeterFactory)), _executor(std::move(executor)), _network(network), - _configServerCS(configServerCS), - _catalogManager(nullptr) { + _configServerCS(configServerCS) { _addConfigShard_inlock(); } ShardRegistry::~ShardRegistry() = default; -void ShardRegistry::init(CatalogManager* catalogManager) { - invariant(!_catalogManager); - _catalogManager = catalogManager; -} - void ShardRegistry::startup() { _executor->startup(); } @@ -95,7 +90,7 @@ void ShardRegistry::shutdown() { void ShardRegistry::reload() { vector shards; - Status status = _catalogManager->getAllShards(&shards); + Status status = grid.catalogManager()->getAllShards(&shards); massert(13632, "couldn't get updated shard list from config server", status.isOK()); int numShards = shards.size(); diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index a7980b61f2ab1..41e6e6b794a3a 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -234,10 +234,6 @@ class ShardRegistry { // Config server connection string ConnectionString _configServerCS; - // Catalog manager from which to load the shard information. Not owned and must outlive - // 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/grid.cpp b/src/mongo/s/grid.cpp index ff9e265ddcb31..35a9b64e87b1a 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -135,6 +135,10 @@ Grid::CatalogManagerGuard Grid::catalogManager(OperationContext* txn) { return Grid::CatalogManagerGuard(txn, this); } +Grid::CatalogManagerGuard Grid::catalogManager() { + return Grid::CatalogManagerGuard(nullptr, this); +} + Grid::CatalogManagerGuard::CatalogManagerGuard(OperationContext* txn, Grid* grid) : _grid(grid) { _grid->_catalogManagerLock.lock_shared(); } diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h index 6b17f3e419989..904eb1a852848 100644 --- a/src/mongo/s/grid.h +++ b/src/mongo/s/grid.h @@ -97,6 +97,7 @@ class Grid { bool getConfigShouldBalance(OperationContext* txn) const; Grid::CatalogManagerGuard catalogManager(OperationContext* txn); + Grid::CatalogManagerGuard catalogManager(); // TODO(spencer): remove CatalogCache* catalogCache() { return _catalogCache.get(); diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp index 8da4e050bb3a1..345aef856d1d6 100644 --- a/src/mongo/s/sharding_initialization.cpp +++ b/src/mongo/s/sharding_initialization.cpp @@ -106,7 +106,6 @@ Status initializeGlobalShardingState(const ConnectionString& configCS) { catalogManager = std::move(catalogManagerLegacy); } - shardRegistry->init(catalogManager.get()); shardRegistry->startup(); grid.init(std::move(catalogManager), std::move(shardRegistry),