diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2019-01-16 16:50:03 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2019-01-20 16:39:28 -0500 |
commit | e4f26d25632f94a6577028ccefd32069550628b6 (patch) | |
tree | 22ec8bcbe00cc655b8da8d054254228bf40d2471 /src | |
parent | 1055387f2d7f4df6836b435c92aa3874e5aaed73 (diff) | |
download | mongo-e4f26d25632f94a6577028ccefd32069550628b6.tar.gz |
SERVER-9043/SERVER-31156 Link flushRouterConfig on MongoD and make it accept a namespace argument
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/client/replica_set_monitor.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/auth/authz_session_external_state_s.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/cloner.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_server_status.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 11 | ||||
-rw-r--r-- | src/mongo/s/catalog_cache.h | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/flush_router_config_cmd.cpp (renamed from src/mongo/s/commands/cluster_flush_router_config_cmd.cpp) | 55 | ||||
-rw-r--r-- | src/mongo/s/commands/get_shard_map_cmd.cpp (renamed from src/mongo/s/commands/cluster_get_shard_map_cmd.cpp) | 0 | ||||
-rw-r--r-- | src/mongo/s/grid.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/grid.h | 9 | ||||
-rw-r--r-- | src/mongo/s/is_mongos.cpp | 19 | ||||
-rw-r--r-- | src/mongo/s/is_mongos.h | 20 |
16 files changed, 103 insertions, 44 deletions
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp index 41c59fa9800..2d0ceeaefb5 100644 --- a/src/mongo/client/replica_set_monitor.cpp +++ b/src/mongo/client/replica_set_monitor.cpp @@ -45,7 +45,6 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/bson_extract_optime.h" #include "mongo/db/server_options.h" -#include "mongo/s/grid.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" diff --git a/src/mongo/db/auth/authz_session_external_state_s.cpp b/src/mongo/db/auth/authz_session_external_state_s.cpp index 9afec17a546..52ffd990334 100644 --- a/src/mongo/db/auth/authz_session_external_state_s.cpp +++ b/src/mongo/db/auth/authz_session_external_state_s.cpp @@ -36,7 +36,6 @@ #include "mongo/base/status.h" #include "mongo/db/jsobj.h" -#include "mongo/s/grid.h" namespace mongo { diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 6a782ac4df7..4b56491555e 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -54,10 +54,6 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/db/views/view_catalog.h" -#include "mongo/s/catalog/type_collection.h" -#include "mongo/s/client/shard_registry.h" -#include "mongo/s/grid.h" -#include "mongo/s/sharding_initialization.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 340a08e4252..3d1ebdec71d 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -63,7 +63,6 @@ #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_options.h" -#include "mongo/s/grid.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 5e1f2ed131d..7b4759d3a35 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -386,7 +386,7 @@ void Balancer::_mainThread() { ShardingLogging::get(opCtx.get()) ->logAction(opCtx.get(), "balancer.round", "", roundDetails.toBSON()) - .transitional_ignore(); + .ignore(); } LOG(1) << "*** End of balancing round"; diff --git a/src/mongo/db/s/sharding_server_status.cpp b/src/mongo/db/s/sharding_server_status.cpp index 03510548fb8..c1f40bc4909 100644 --- a/src/mongo/db/s/sharding_server_status.cpp +++ b/src/mongo/db/s/sharding_server_status.cpp @@ -34,19 +34,15 @@ #include "mongo/db/s/active_migrations_registry.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_statistics.h" -#include "mongo/db/server_options.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" +#include "mongo/s/is_mongos.h" namespace mongo { namespace { -bool isClusterNode() { - return serverGlobalParams.clusterRole != ClusterRole::None; -} - class ShardingServerStatus final : public ServerStatusSection { public: ShardingServerStatus() : ServerStatusSection("sharding") {} diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 0ec9c6b6f00..30e1b7057ba 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -470,7 +470,9 @@ env.Library( source=[ 'is_mongos.cpp', ], - LIBDEPS=[], + LIBDEPS=[ + '$BUILD_DIR/mongo/db/server_options_core', + ], ) env.CppUnitTest( diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index 741cec85fd2..c8d7e2ac61a 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -423,6 +423,17 @@ void CatalogCache::invalidateShardedCollection(const NamespaceString& nss) { itDb->second[nss.ns()]->needsRefresh = true; } +void CatalogCache::purgeCollection(const NamespaceString& nss) { + stdx::lock_guard<stdx::mutex> lg(_mutex); + + auto itDb = _collectionsByDb.find(nss.db()); + if (itDb == _collectionsByDb.end()) { + return; + } + + itDb->second.erase(nss.ns()); +} + void CatalogCache::purgeDatabase(StringData dbName) { stdx::lock_guard<stdx::mutex> lg(_mutex); _databases.erase(dbName); diff --git a/src/mongo/s/catalog_cache.h b/src/mongo/s/catalog_cache.h index 7dd03763160..49b63628247 100644 --- a/src/mongo/s/catalog_cache.h +++ b/src/mongo/s/catalog_cache.h @@ -228,6 +228,12 @@ public: void invalidateShardedCollection(const NamespaceString& nss); /** + * Non-blocking method, which removes the entire specified collection from the cache (resulting + * in full refresh on subsequent access) + */ + void purgeCollection(const NamespaceString& nss); + + /** * Non-blocking method, which removes the entire specified database (including its collections) * from the cache. */ diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript index a686336430c..a936e139902 100644 --- a/src/mongo/s/commands/SConscript +++ b/src/mongo/s/commands/SConscript @@ -9,7 +9,8 @@ env = env.Clone() env.Library( target='shared_cluster_commands', source=[ - 'cluster_get_shard_map_cmd.cpp', + 'flush_router_config_cmd.cpp', + 'get_shard_map_cmd.cpp', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/commands', @@ -47,7 +48,6 @@ env.Library( 'cluster_filemd5_cmd.cpp', 'cluster_find_and_modify_cmd.cpp', 'cluster_find_cmd.cpp', - 'cluster_flush_router_config_cmd.cpp', 'cluster_fsync_cmd.cpp', 'cluster_ftdc_commands.cpp', 'cluster_get_last_error_cmd.cpp', diff --git a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp b/src/mongo/s/commands/flush_router_config_cmd.cpp index ee4f6947264..aa8ef21ed43 100644 --- a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp +++ b/src/mongo/s/commands/flush_router_config_cmd.cpp @@ -28,11 +28,14 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding + #include "mongo/platform/basic.h" #include "mongo/db/commands.h" -#include "mongo/s/catalog_cache.h" #include "mongo/s/grid.h" +#include "mongo/s/is_mongos.h" +#include "mongo/util/log.h" namespace mongo { namespace { @@ -45,32 +48,58 @@ public: return AllowedOnSecondary::kAlways; } - virtual bool adminOnly() const { + bool adminOnly() const override { return true; } - - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } std::string help() const override { - return "flush all router config"; + return "Flushes the cached routing information for a single collection, entire database " + "(and its collections) or all databases, which would cause full reload from the " + "config server on the next access.\n" + "Usage:\n" + "{flushRouterConfig: 1} flushes all databases\n" + "{flushRouterConfig: 'db'} flushes only the given database (and its collections)\n" + "{flushRouterconfig: 'db.coll'} flushes only the given collection"; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) const { + void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) const override { ActionSet actions; actions.addAction(ActionType::flushRouterConfig); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* opCtx, - const std::string& dbname, - const BSONObj& cmdObj, - BSONObjBuilder& result) { - Grid::get(opCtx)->catalogCache()->purgeAllDatabases(); + bool run(OperationContext* opCtx, + const std::string& dbname, + const BSONObj& cmdObj, + BSONObjBuilder& result) override { + auto const grid = Grid::get(opCtx); + uassert(ErrorCodes::ShardingStateNotInitialized, + "Sharding is not enabled", + grid->isShardingInitialized()); + + auto const catalogCache = grid->catalogCache(); + + const auto argumentElem = cmdObj.firstElement(); + if (argumentElem.isNumber() || argumentElem.isBoolean()) { + LOG(0) << "Routing metadata flushed for all databases"; + catalogCache->purgeAllDatabases(); + } else { + const auto ns = argumentElem.checkAndGetStringData(); + if (nsIsDbOnly(ns)) { + LOG(0) << "Routing metadata flushed for database " << ns; + catalogCache->purgeDatabase(ns); + } else { + const NamespaceString nss(ns); + LOG(0) << "Routing metadata flushed for collection " << nss; + catalogCache->purgeCollection(nss); + } + } result.appendBool("flushed", true); return true; diff --git a/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp b/src/mongo/s/commands/get_shard_map_cmd.cpp index 45413d2969b..45413d2969b 100644 --- a/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp +++ b/src/mongo/s/commands/get_shard_map_cmd.cpp diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp index cd9544670ce..25b90d5ede4 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -45,11 +45,9 @@ #include "mongo/util/log.h" namespace mongo { - namespace { -// Global grid instance const auto grid = ServiceContext::declareDecoration<Grid>(); -} +} // namespace Grid::Grid() = default; diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h index 7dbc69ab025..ba43a066980 100644 --- a/src/mongo/s/grid.h +++ b/src/mongo/s/grid.h @@ -32,6 +32,7 @@ #include "mongo/db/repl/optime.h" #include "mongo/s/catalog/sharding_catalog_client.h" +#include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" #include "mongo/stdx/functional.h" #include "mongo/stdx/memory.h" @@ -40,7 +41,6 @@ namespace mongo { class BalancerConfiguration; -class CatalogCache; class ClusterCursorManager; class OperationContext; class ServiceContext; @@ -52,8 +52,7 @@ class TaskExecutorPool; } // namespace executor /** - * Holds the global sharding context. Single instance exists for a running server. Exists on - * both MongoD and MongoS. + * Contains the sharding context for a running server. Exists on both MongoD and MongoS. */ class Grid { public: @@ -121,10 +120,6 @@ public: return _catalogClient.get(); } - /** - * Can return nullptr. For example, if this is a mongod that is not a shard server. This is - * always present on mongos after startup. - */ CatalogCache* catalogCache() const { return _catalogCache.get(); } diff --git a/src/mongo/s/is_mongos.cpp b/src/mongo/s/is_mongos.cpp index 2a4ebb2f53e..1855e475081 100644 --- a/src/mongo/s/is_mongos.cpp +++ b/src/mongo/s/is_mongos.cpp @@ -28,18 +28,31 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/s/is_mongos.h" +#include "mongo/db/server_options.h" + namespace mongo { namespace { bool mongosState = false; } // namespace -} // namespace mongo -bool mongo::isMongos() { +bool isMongos() { return mongosState; } -void mongo::setMongos(const bool state) { +void setMongos(const bool state) { mongosState = state; } + +bool isClusterNode() { + return serverGlobalParams.clusterRole != ClusterRole::None; +} + +bool isClusterNodeOrRouter() { + return isClusterNode() || isMongos(); +} + +} // namespace mongo diff --git a/src/mongo/s/is_mongos.h b/src/mongo/s/is_mongos.h index 2567f7ba6d9..90184105c8f 100644 --- a/src/mongo/s/is_mongos.h +++ b/src/mongo/s/is_mongos.h @@ -31,9 +31,25 @@ #pragma once namespace mongo { -/** Returns true when the running process is `mongos` and false otherwise. */ + +/** + * 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. */ +/** + * Set the global state flag indicating whether the running process is `mongos` or not. + */ void setMongos(const bool state = true); + +/** + * Returns whether this node is config server or a shard. + */ +bool isClusterNode(); + +/** + * Returns whether this node is config server, shard or mongos. + */ +bool isClusterNodeOrRouter(); + } // namespace mongo |