summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2018-04-24 10:55:56 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2018-04-24 16:48:03 -0400
commit052bc57ebd47a979c72b00828d28a3c7f72e48aa (patch)
treeacf578feef42520de13c71f14573b6c01537f176
parent76bc4f800ba2a103d67fa4600d3946f255927818 (diff)
downloadmongo-052bc57ebd47a979c72b00828d28a3c7f72e48aa.tar.gz
SERVER-34214 TypedCommand for _flushRoutingTableCacheUpdates
-rw-r--r--src/mongo/db/s/flush_routing_table_cache_updates_command.cpp127
-rw-r--r--src/mongo/s/request_types/flush_routing_table_cache_updates.idl2
2 files changed, 59 insertions, 70 deletions
diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
index 2747f16eca2..b006e9a27e3 100644
--- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
+++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
@@ -52,11 +52,15 @@
namespace mongo {
namespace {
-class FlushRoutingTableCacheUpdates : public BasicCommand {
+class FlushRoutingTableCacheUpdatesCmd final
+ : public TypedCommand<FlushRoutingTableCacheUpdatesCmd> {
public:
+ using Request = _flushRoutingTableCacheUpdates;
+
// Support deprecated name 'forceRoutingTableRefresh' for backwards compatibility with 3.6.0.
- FlushRoutingTableCacheUpdates()
- : BasicCommand("_flushRoutingTableCacheUpdates", "forceRoutingTableRefresh") {}
+ FlushRoutingTableCacheUpdatesCmd()
+ : TypedCommand<FlushRoutingTableCacheUpdatesCmd>(Request::kCommandName,
+ "forceRoutingTableRefresh") {}
std::string help() const override {
return "Internal command which waits for any pending routing table cache updates for a "
@@ -75,82 +79,67 @@ public:
return AllowedOnSecondary::kNever;
}
- bool supportsWriteConcern(const BSONObj& cmd) const override {
- return false;
- }
-
- std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override {
- return CommandHelpers::parseNsFullyQualified(cmdObj);
- }
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
- Status checkAuthForCommand(Client* client,
- const std::string& dbname,
- const BSONObj& cmdObj) const override {
- if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
- ResourcePattern::forClusterResource(), ActionType::internal)) {
- return Status(ErrorCodes::Unauthorized, "Unauthorized");
+ bool supportsWriteConcern() const override {
+ return false;
}
- return Status::OK();
- }
-
- void addRequiredPrivileges(const std::string& dbname,
- const BSONObj& cmdObj,
- std::vector<Privilege>* out) const override {
- ActionSet actions;
- actions.addAction(ActionType::internal);
- out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
- }
- bool run(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) override {
- auto const shardingState = ShardingState::get(opCtx);
- uassertStatusOK(shardingState->canAcceptShardedCommands());
-
- uassert(ErrorCodes::IllegalOperation,
- "Can't issue _flushRoutingTableCacheUpdates from 'eval'",
- !opCtx->getClient()->isInDirectClient());
-
- uassert(ErrorCodes::IllegalOperation,
- "Can't call _flushRoutingTableCacheUpdates if in read-only mode",
- !storageGlobalParams.readOnly);
-
- auto& oss = OperationShardingState::get(opCtx);
-
- const NamespaceString nss(parseNs(dbname, cmdObj));
- const auto request = _flushRoutingTableCacheUpdatesRequest::parse(
- IDLParserErrorContext("_FlushRoutingTableCacheUpdatesRequest"), cmdObj);
-
- {
- AutoGetCollection autoColl(opCtx, nss, MODE_IS);
-
- // If the primary is in the critical section, secondaries must wait for the commit to
- // finish on the primary in case a secondary's caller has an afterClusterTime inclusive
- // of the commit (and new writes to the committed chunk) that hasn't yet propagated back
- // to this shard. This ensures the read your own writes causal consistency guarantee.
- auto const css = CollectionShardingState::get(opCtx, nss);
- auto criticalSectionSignal =
- css->getCriticalSectionSignal(ShardingMigrationCriticalSection::kRead);
- if (criticalSectionSignal) {
- oss.setMigrationCriticalSectionSignal(criticalSectionSignal);
- }
+ NamespaceString ns() const override {
+ return request().getNamespace();
}
- oss.waitForMigrationCriticalSectionSignal(opCtx);
-
- if (request.getSyncFromConfig()) {
- LOG(1) << "Forcing remote routing table refresh for " << nss;
- forceShardFilteringMetadataRefresh(opCtx, nss);
+ void doCheckAuthorization(OperationContext* opCtx) const override {
+ uassert(ErrorCodes::Unauthorized,
+ "Unauthorized",
+ AuthorizationSession::get(opCtx->getClient())
+ ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
+ ActionType::internal));
}
- CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, nss);
+ void typedRun(OperationContext* opCtx) {
+ auto const shardingState = ShardingState::get(opCtx);
+ uassertStatusOK(shardingState->canAcceptShardedCommands());
+
+ uassert(ErrorCodes::IllegalOperation,
+ "Can't issue _flushRoutingTableCacheUpdates from 'eval'",
+ !opCtx->getClient()->isInDirectClient());
+
+ uassert(ErrorCodes::IllegalOperation,
+ "Can't call _flushRoutingTableCacheUpdates if in read-only mode",
+ !storageGlobalParams.readOnly);
+
+ auto& oss = OperationShardingState::get(opCtx);
+
+ {
+ AutoGetCollection autoColl(opCtx, ns(), MODE_IS);
+
+ // If the primary is in the critical section, secondaries must wait for the commit to
+ // finish on the primary in case a secondary's caller has an afterClusterTime inclusive
+ // of the commit (and new writes to the committed chunk) that hasn't yet propagated back
+ // to this shard. This ensures the read your own writes causal consistency guarantee.
+ auto const css = CollectionShardingState::get(opCtx, ns());
+ auto criticalSectionSignal =
+ css->getCriticalSectionSignal(ShardingMigrationCriticalSection::kRead);
+ if (criticalSectionSignal) {
+ oss.setMigrationCriticalSectionSignal(criticalSectionSignal);
+ }
+ }
- repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
+ oss.waitForMigrationCriticalSectionSignal(opCtx);
- return true;
- }
+ if (request().getSyncFromConfig()) {
+ LOG(1) << "Forcing remote routing table refresh for " << ns();
+ forceShardFilteringMetadataRefresh(opCtx, ns());
+ }
+
+ CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, ns());
+ repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
+ }
+ };
} _flushRoutingTableCacheUpdatesCmd;
} // namespace
diff --git a/src/mongo/s/request_types/flush_routing_table_cache_updates.idl b/src/mongo/s/request_types/flush_routing_table_cache_updates.idl
index d97a4fe1053..f7be2e02864 100644
--- a/src/mongo/s/request_types/flush_routing_table_cache_updates.idl
+++ b/src/mongo/s/request_types/flush_routing_table_cache_updates.idl
@@ -33,7 +33,7 @@ imports:
- "mongo/idl/basic_types.idl"
commands:
- _flushRoutingTableCacheUpdatesRequest:
+ _flushRoutingTableCacheUpdates:
description: "An internal command to wait for the last routing table cache refresh for a particular namespace to be persisted to disk"
strict: true
namespace: concatenate_with_db