diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2016-04-06 11:36:13 -0400 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2016-04-06 11:42:02 -0400 |
commit | b9bd0eb46147a7a965f50f076dea57f85fe321e8 (patch) | |
tree | 3e5da0d44a5befe3823528476f6f0bcebdff1aa2 | |
parent | 202fd419457c47650be27accb038a700134797ed (diff) | |
download | mongo-b9bd0eb46147a7a965f50f076dea57f85fe321e8.tar.gz |
SERVER-23534 move miscellaneous methods off Grid
23 files changed, 201 insertions, 106 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 1619efa9af8..242201ed57d 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -41,6 +41,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_state_recovery.h" +#include "mongo/s/catalog/catalog_manager.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/grid.h" #include "mongo/s/shard_key_pattern.h" diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index f99a591ca73..337e34970ec 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -184,6 +184,7 @@ env.Library( 'chunk.cpp', 'chunk_manager.cpp', 'config.cpp', + 'db_util.cpp', 'grid.cpp', ], LIBDEPS=[ diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp index 12423ff2cbf..4d9c4d95252 100644 --- a/src/mongo/s/balance.cpp +++ b/src/mongo/s/balance.cpp @@ -156,7 +156,7 @@ int Balancer::_moveChunks(OperationContext* txn, const SettingsType& balancerConfig = isBalSettingsAbsent ? SettingsType{} : balSettingsResult.getValue(); - if ((!isBalSettingsAbsent && !grid.shouldBalance(balancerConfig)) || + if ((!isBalSettingsAbsent && !Chunk::shouldBalance(balancerConfig)) || MONGO_FAIL_POINT(skipBalanceRound)) { LOG(1) << "Stopping balancing round early as balancing was disabled"; return movedCount; @@ -590,7 +590,7 @@ void Balancer::run() { isBalSettingsAbsent ? SettingsType{} : balSettingsResult.getValue(); // now make sure we should even be running - if ((!isBalSettingsAbsent && !grid.shouldBalance(balancerConfig)) || + if ((!isBalSettingsAbsent && !Chunk::shouldBalance(balancerConfig)) || MONGO_FAIL_POINT(skipBalanceRound)) { LOG(1) << "skipping balancing round because balancing is disabled"; diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp index bc5976f3d6b..1edfb6f10ec 100644 --- a/src/mongo/s/chunk.cpp +++ b/src/mongo/s/chunk.cpp @@ -209,6 +209,41 @@ bool ChunkRange::containsKey(const BSONObj& shardKey) const { return getMin().woCompare(shardKey) <= 0 && shardKey.woCompare(getMax()) < 0; } +bool Chunk::shouldBalance(const SettingsType& balancerSettings) { + if (balancerSettings.isBalancerStoppedSet() && balancerSettings.getBalancerStopped()) { + return false; + } + + if (balancerSettings.isBalancerActiveWindowSet()) { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + return balancerSettings.inBalancingWindow(now); + } + + return true; +} + +bool Chunk::getConfigShouldBalance(OperationContext* txn) const { + auto balSettingsResult = + grid.catalogManager(txn)->getGlobalSettings(txn, SettingsType::BalancerDocKey); + if (!balSettingsResult.isOK()) { + if (balSettingsResult == ErrorCodes::NoMatchingDocument) { + // Settings document for balancer does not exist, default to balancing allowed. + return true; + } + + warning() << balSettingsResult.getStatus(); + return false; + } + SettingsType balSettings = balSettingsResult.getValue(); + + if (!balSettings.isKeySet()) { + // Balancer settings doc does not exist. Default to yes. + return true; + } + + return shouldBalance(balSettings); +} + bool Chunk::_minIsInf() const { return 0 == _manager->getShardKeyPattern().getKeyPattern().globalMin().woCompare(getMin()); } @@ -564,7 +599,7 @@ bool Chunk::splitIfShould(OperationContext* txn, long dataWritten) const { _dataWritten = 0; } - bool shouldBalance = grid.getConfigShouldBalance(txn); + bool shouldBalance = getConfigShouldBalance(txn); if (shouldBalance) { auto status = grid.catalogManager(txn)->getCollection(txn, _manager->getns()); if (!status.isOK()) { diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h index 39294692c7f..0adb301bf23 100644 --- a/src/mongo/s/chunk.h +++ b/src/mongo/s/chunk.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/s/catalog/type_chunk.h" +#include "mongo/s/catalog/type_settings.h" #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard.h" @@ -81,6 +82,17 @@ public: return _max; } + /** + * Returns true if the balancer should be running. Caller is responsible for making sure + * settings has the balancer key. + */ + static bool shouldBalance(const SettingsType& balancerSettings); + + /** + * Returns true if the config server settings indicate that the balancer should be active. + */ + bool getConfigShouldBalance(OperationContext* txn) const; + // Returns true if this chunk contains the given shard key, and false otherwise // // Note: this function takes an extracted *key*, not an original document diff --git a/src/mongo/s/chunk_manager_targeter.cpp b/src/mongo/s/chunk_manager_targeter.cpp index d9dfbe7ec48..a58d762e26a 100644 --- a/src/mongo/s/chunk_manager_targeter.cpp +++ b/src/mongo/s/chunk_manager_targeter.cpp @@ -37,6 +37,7 @@ #include "mongo/s/chunk_manager.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/config.h" +#include "mongo/s/db_util.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -268,7 +269,7 @@ ChunkManagerTargeter::ChunkManagerTargeter(const NamespaceString& nss, TargeterS Status ChunkManagerTargeter::init(OperationContext* txn) { - auto status = grid.implicitCreateDb(txn, _nss.db().toString()); + auto status = dbutil::implicitCreateDb(txn, _nss.db().toString()); if (!status.isOK()) { return status.getStatus(); } @@ -623,7 +624,7 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* txn, bool* wasCha ChunkManagerPtr lastManager = _manager; ShardPtr lastPrimary = _primary; - auto status = grid.implicitCreateDb(txn, _nss.db().toString()); + auto status = dbutil::implicitCreateDb(txn, _nss.db().toString()); if (!status.isOK()) { return status.getStatus(); } @@ -684,7 +685,7 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* txn, bool* wasCha } Status ChunkManagerTargeter::refreshNow(OperationContext* txn, RefreshType refreshType) { - auto status = grid.implicitCreateDb(txn, _nss.db().toString()); + auto status = dbutil::implicitCreateDb(txn, _nss.db().toString()); if (!status.isOK()) { return status.getStatus(); } diff --git a/src/mongo/s/cluster_cursor_stats.cpp b/src/mongo/s/cluster_cursor_stats.cpp index bbc460f7178..03ba9fc26d0 100644 --- a/src/mongo/s/cluster_cursor_stats.cpp +++ b/src/mongo/s/cluster_cursor_stats.cpp @@ -30,6 +30,7 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/s/grid.h" +#include "mongo/s/query/cluster_cursor_manager.h" namespace mongo { namespace { diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index 9109ecee01d..0b69571e7e2 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -41,6 +41,7 @@ #include "mongo/s/config.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/cluster_explain.h" +#include "mongo/s/db_util.h" #include "mongo/s/grid.h" #include "mongo/s/stale_exception.h" #include "mongo/s/strategy.h" @@ -145,7 +146,7 @@ public: // findAndModify should only be creating database if upsert is true, but this would require // that the parsing be pulled into this function. - auto conf = uassertStatusOK(grid.implicitCreateDb(txn, dbName)); + auto conf = uassertStatusOK(dbutil::implicitCreateDb(txn, dbName)); if (!conf->isShardingEnabled() || !conf->isSharded(ns)) { return _runCommand(txn, conf, nullptr, conf->getPrimaryId(), ns, cmdObj, result); } diff --git a/src/mongo/s/commands/cluster_killcursors_cmd.cpp b/src/mongo/s/commands/cluster_killcursors_cmd.cpp index 2ee0ef61afe..63235315d4c 100644 --- a/src/mongo/s/commands/cluster_killcursors_cmd.cpp +++ b/src/mongo/s/commands/cluster_killcursors_cmd.cpp @@ -30,6 +30,7 @@ #include "mongo/db/commands/killcursors_common.h" #include "mongo/s/grid.h" +#include "mongo/s/query/cluster_cursor_manager.h" namespace mongo { namespace { diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp index c55d3518a54..fb82df1b7c6 100644 --- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp @@ -48,6 +48,7 @@ #include "mongo/s/config.h" #include "mongo/s/catalog/dist_lock_manager.h" #include "mongo/s/client/shard_registry.h" +#include "mongo/s/db_util.h" #include "mongo/s/grid.h" #include "mongo/s/strategy.h" #include "mongo/stdx/chrono.h" @@ -232,7 +233,7 @@ public: shared_ptr<DBConfig> confOut; if (customOutDB) { // Create the output database implicitly, since we have a custom output requested - confOut = uassertStatusOK(grid.implicitCreateDb(txn, outDB)); + confOut = uassertStatusOK(dbutil::implicitCreateDb(txn, outDB)); } else { confOut = confIn; } diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp index 7f900466ccc..e74c21c3091 100644 --- a/src/mongo/s/commands/commands_public.cpp +++ b/src/mongo/s/commands/commands_public.cpp @@ -54,6 +54,7 @@ #include "mongo/s/commands/cluster_commands_common.h" #include "mongo/s/commands/run_on_all_shards_cmd.h" #include "mongo/s/config.h" +#include "mongo/s/db_util.h" #include "mongo/s/grid.h" #include "mongo/s/query/store_possible_cursor.h" #include "mongo/s/stale_exception.h" @@ -452,7 +453,7 @@ public: int, string& errmsg, BSONObjBuilder& result) { - auto status = grid.implicitCreateDb(txn, dbName); + auto status = dbutil::implicitCreateDb(txn, dbName); if (!status.isOK()) { return appendCommandStatus(result, status.getStatus()); } @@ -573,7 +574,7 @@ public: "invalid todb argument", NamespaceString::validDBName(todb, NamespaceString::DollarInDbNameBehavior::Allow)); - auto confTo = uassertStatusOK(grid.implicitCreateDb(txn, todb)); + auto confTo = uassertStatusOK(dbutil::implicitCreateDb(txn, todb)); uassert(ErrorCodes::IllegalOperation, "cannot copy to a sharded database", !confTo->isShardingEnabled()); diff --git a/src/mongo/s/commands/run_on_all_shards_cmd.cpp b/src/mongo/s/commands/run_on_all_shards_cmd.cpp index c3ff1fd633c..6dd3626fde8 100644 --- a/src/mongo/s/commands/run_on_all_shards_cmd.cpp +++ b/src/mongo/s/commands/run_on_all_shards_cmd.cpp @@ -39,6 +39,7 @@ #include "mongo/s/client/shard.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/commands/cluster_commands_common.h" +#include "mongo/s/db_util.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -78,7 +79,7 @@ bool RunOnAllShardsCommand::run(OperationContext* txn, LOG(1) << "RunOnAllShardsCommand db: " << dbName << " cmd:" << cmdObj; if (_implicitCreateDb) { - uassertStatusOK(grid.implicitCreateDb(txn, dbName)); + uassertStatusOK(dbutil::implicitCreateDb(txn, dbName)); } std::vector<ShardId> shardIds; diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index 8fd0443f0ef..26f1eb2b109 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -52,6 +52,7 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_write.h" #include "mongo/s/grid.h" +#include "mongo/stdx/memory.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/s/db_util.cpp b/src/mongo/s/db_util.cpp new file mode 100644 index 00000000000..ab20cccc245 --- /dev/null +++ b/src/mongo/s/db_util.cpp @@ -0,0 +1,61 @@ +/** + * 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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/s/db_util.h" + +#include "mongo/base/status_with.h" +#include "mongo/s/catalog/catalog_cache.h" +#include "mongo/s/catalog/catalog_manager.h" +#include "mongo/s/grid.h" + +namespace mongo { +namespace dbutil { + +StatusWith<std::shared_ptr<DBConfig>> implicitCreateDb(OperationContext* txn, + const std::string& dbName) { + auto status = grid.catalogCache()->getDatabase(txn, dbName); + if (status.isOK()) { + return status; + } + + if (status == ErrorCodes::NamespaceNotFound) { + auto statusCreateDb = grid.catalogManager(txn)->createDatabase(txn, dbName); + if (statusCreateDb.isOK() || statusCreateDb == ErrorCodes::NamespaceExists) { + return grid.catalogCache()->getDatabase(txn, dbName); + } + + return statusCreateDb; + } + + return status; +} + +} // namespace dbutil +} // namespace mongo diff --git a/src/mongo/s/db_util.h b/src/mongo/s/db_util.h new file mode 100644 index 00000000000..ea1104dba0a --- /dev/null +++ b/src/mongo/s/db_util.h @@ -0,0 +1,50 @@ +/** + * 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. + */ + +#pragma once + +#include <memory> +#include <string> + +namespace mongo { + +class DBConfig; +class OperationContext; +template <typename T> +class StatusWith; + +namespace dbutil { + +/** + * Implicitly creates the specified database as non-sharded. + */ +StatusWith<std::shared_ptr<DBConfig>> implicitCreateDb(OperationContext* txn, + const std::string& dbName); + +} // namespace dbutil +} // namespace mongo diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp index f6049538db9..b2d98d25f6a 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -32,11 +32,11 @@ #include "mongo/s/grid.h" -#include "mongo/base/status_with.h" #include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/catalog/catalog_manager.h" -#include "mongo/s/catalog/type_settings.h" #include "mongo/s/client/shard_registry.h" +#include "mongo/s/query/cluster_cursor_manager.h" +#include "mongo/stdx/memory.h" #include "mongo/util/log.h" namespace mongo { @@ -47,6 +47,7 @@ Grid grid; Grid::Grid() : _allowLocalShard(true) {} void Grid::init(std::unique_ptr<CatalogManager> catalogManager, + std::unique_ptr<CatalogCache> catalogCache, std::unique_ptr<ShardRegistry> shardRegistry, std::unique_ptr<ClusterCursorManager> cursorManager) { invariant(!_catalogManager); @@ -55,30 +56,11 @@ void Grid::init(std::unique_ptr<CatalogManager> catalogManager, invariant(!_cursorManager); _catalogManager = std::move(catalogManager); - _catalogCache = stdx::make_unique<CatalogCache>(); + _catalogCache = std::move(catalogCache); _shardRegistry = std::move(shardRegistry); _cursorManager = std::move(cursorManager); } -StatusWith<std::shared_ptr<DBConfig>> Grid::implicitCreateDb(OperationContext* txn, - const std::string& dbName) { - auto status = catalogCache()->getDatabase(txn, dbName); - if (status.isOK()) { - return status; - } - - if (status == ErrorCodes::NamespaceNotFound) { - auto statusCreateDb = catalogManager(txn)->createDatabase(txn, dbName); - if (statusCreateDb.isOK() || statusCreateDb == ErrorCodes::NamespaceExists) { - return catalogCache()->getDatabase(txn, dbName); - } - - return statusCreateDb; - } - - return status; -} - bool Grid::allowLocalHost() const { return _allowLocalShard; } @@ -87,45 +69,6 @@ void Grid::setAllowLocalHost(bool allow) { _allowLocalShard = allow; } -/* - * Returns whether balancing is enabled, with optional namespace "ns" parameter for balancing on a - * particular collection. - */ -bool Grid::shouldBalance(const SettingsType& balancerSettings) const { - if (balancerSettings.isBalancerStoppedSet() && balancerSettings.getBalancerStopped()) { - return false; - } - - if (balancerSettings.isBalancerActiveWindowSet()) { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - return balancerSettings.inBalancingWindow(now); - } - - return true; -} - -bool Grid::getConfigShouldBalance(OperationContext* txn) const { - auto balSettingsResult = - grid.catalogManager(txn)->getGlobalSettings(txn, SettingsType::BalancerDocKey); - if (!balSettingsResult.isOK()) { - if (balSettingsResult == ErrorCodes::NoMatchingDocument) { - // Settings document for balancer does not exist, default to balancing allowed. - return true; - } - - warning() << balSettingsResult.getStatus(); - return false; - } - SettingsType balSettings = balSettingsResult.getValue(); - - if (!balSettings.isKeySet()) { - // Balancer settings doc does not exist. Default to yes. - return true; - } - - return shouldBalance(balSettings); -} - void Grid::advanceConfigOpTime(repl::OpTime opTime) { stdx::lock_guard<stdx::mutex> lk(_mutex); if (_configOpTime < opTime) { @@ -133,15 +76,12 @@ void Grid::advanceConfigOpTime(repl::OpTime opTime) { } } +// Note: shardRegistry->shutdown() must be called before this method is called. void Grid::clearForUnitTests() { _catalogManager.reset(); _catalogCache.reset(); - - _shardRegistry->shutdown(); _shardRegistry.reset(); - _cursorManager.reset(); - _configOpTime = repl::OpTime(); } diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h index bd67e00bf6b..4e0fa38728b 100644 --- a/src/mongo/s/grid.h +++ b/src/mongo/s/grid.h @@ -28,24 +28,17 @@ #pragma once -#include <string> -#include <vector> +#include <memory> -#include "mongo/s/catalog/catalog_manager.h" -#include "mongo/s/query/cluster_cursor_manager.h" -#include "mongo/stdx/memory.h" +#include "mongo/db/repl/optime.h" namespace mongo { -class BSONObj; class CatalogCache; -class DBConfig; +class CatalogManager; +class ClusterCursorManager; class OperationContext; -class SettingsType; class ShardRegistry; -template <typename T> -class StatusWith; - /** * Holds the global sharding context. Single instance exists for a running server. Exists on @@ -63,16 +56,11 @@ public: * state using clearForUnitTests. */ void init(std::unique_ptr<CatalogManager> catalogManager, + std::unique_ptr<CatalogCache> catalogCache, std::unique_ptr<ShardRegistry> shardRegistry, std::unique_ptr<ClusterCursorManager> cursorManager); /** - * Implicitly creates the specified database as non-sharded. - */ - StatusWith<std::shared_ptr<DBConfig>> implicitCreateDb(OperationContext* txn, - const std::string& dbName); - - /** * @return true if shards and config servers are allowed to use 'localhost' in address */ bool allowLocalHost() const; @@ -83,17 +71,6 @@ public: void setAllowLocalHost(bool allow); /** - * Returns true if the balancer should be running. Caller is responsible - * for making sure settings has the balancer key. - */ - bool shouldBalance(const SettingsType& balancerSettings) const; - - /** - * Returns true if the config server settings indicate that the balancer should be active. - */ - bool getConfigShouldBalance(OperationContext* txn) const; - - /** * Returns a pointer to a CatalogManager to use for accessing catalog data stored on the config * servers. */ diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 5f91ad1f0d8..ef399c3844e 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -70,6 +70,7 @@ #include "mongo/s/request.h" #include "mongo/s/sharding_initialization.h" #include "mongo/s/version_mongos.h" +#include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/thread.h" #include "mongo/util/admin_access.h" diff --git a/src/mongo/s/sharding_egress_metadata_hook.cpp b/src/mongo/s/sharding_egress_metadata_hook.cpp index b35097c7062..a4cf3594201 100644 --- a/src/mongo/s/sharding_egress_metadata_hook.cpp +++ b/src/mongo/s/sharding_egress_metadata_hook.cpp @@ -41,6 +41,7 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/s/sharding_egress_metadata_hook.h" +#include "mongo/util/net/hostandport.h" namespace mongo { diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp index 8dccfd5af76..410c2c6c581 100644 --- a/src/mongo/s/sharding_initialization.cpp +++ b/src/mongo/s/sharding_initialization.cpp @@ -29,6 +29,7 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding #include "mongo/platform/basic.h" +#include "mongo/platform/random.h" #include "mongo/s/sharding_initialization.h" @@ -52,9 +53,11 @@ #include "mongo/s/grid.h" #include "mongo/s/sharding_egress_metadata_hook_for_mongos.h" #include "mongo/db/s/sharding_egress_metadata_hook_for_mongod.h" +#include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/catalog/replset/catalog_manager_replica_set.h" #include "mongo/s/catalog/replset/dist_lock_catalog_impl.h" #include "mongo/s/catalog/replset/replset_dist_lock_manager.h" +#include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/stdx/memory.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" @@ -159,6 +162,7 @@ Status initializeGlobalShardingState(OperationContext* txn, shardRegistry->startup(); grid.init(std::move(catalogManager), + stdx::make_unique<CatalogCache>(), std::move(shardRegistry), stdx::make_unique<ClusterCursorManager>( getGlobalServiceContext()->getPreciseClockSource())); diff --git a/src/mongo/s/sharding_test_fixture.cpp b/src/mongo/s/sharding_test_fixture.cpp index 9af49ce4d8e..0121c22762a 100644 --- a/src/mongo/s/sharding_test_fixture.cpp +++ b/src/mongo/s/sharding_test_fixture.cpp @@ -46,6 +46,7 @@ #include "mongo/executor/thread_pool_task_executor_test_fixture.h" #include "mongo/rpc/metadata/repl_set_metadata.h" #include "mongo/rpc/metadata/server_selection_metadata.h" +#include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/catalog/dist_lock_manager_mock.h" #include "mongo/s/catalog/replset/catalog_manager_replica_set.h" #include "mongo/s/catalog/type_changelog.h" @@ -53,6 +54,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" +#include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/s/set_shard_version_request.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" @@ -132,13 +134,13 @@ void ShardingTestFixture::setUp() { // For now initialize the global grid object. All sharding objects will be accessible // from there until we get rid of it. grid.init(std::move(cm), + stdx::make_unique<CatalogCache>(), std::move(shardRegistry), stdx::make_unique<ClusterCursorManager>(_service->getPreciseClockSource())); } void ShardingTestFixture::tearDown() { - // This call will shut down the shard registry, which will terminate the underlying executor - // and its threads. + grid.shardRegistry()->shutdown(); grid.clearForUnitTests(); _opCtx.reset(); diff --git a/src/mongo/s/sharding_test_fixture.h b/src/mongo/s/sharding_test_fixture.h index 55c33f561e9..ecfa1a9e3b3 100644 --- a/src/mongo/s/sharding_test_fixture.h +++ b/src/mongo/s/sharding_test_fixture.h @@ -38,6 +38,7 @@ namespace mongo { class BSONObj; +class CatalogCache; class CatalogManager; class CatalogManagerReplicaSet; struct ChunkVersion; diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp index e80b48f267f..465bbe10b61 100644 --- a/src/mongo/s/strategy.cpp +++ b/src/mongo/s/strategy.cpp @@ -63,6 +63,7 @@ #include "mongo/s/chunk_version.h" #include "mongo/s/config.h" #include "mongo/s/grid.h" +#include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/s/query/cluster_find.h" #include "mongo/s/request.h" #include "mongo/s/stale_exception.h" |