diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/s/commands/cluster_index_filter_cmd.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/s/commands/cluster_index_filter_cmd.cpp')
-rw-r--r-- | src/mongo/s/commands/cluster_index_filter_cmd.cpp | 220 |
1 files changed, 109 insertions, 111 deletions
diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index 323ad646a33..d3465a4bb48 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -38,137 +38,135 @@ namespace mongo { - using std::string; - using std::stringstream; - using std::vector; +using std::string; +using std::stringstream; +using std::vector; - /** - * Base class for mongos index filter commands. - * Cluster index filter commands don't do much more than - * forwarding the commands to all shards and combining the results. - */ - class ClusterIndexFilterCmd : public Command { +/** + * Base class for mongos index filter commands. + * Cluster index filter commands don't do much more than + * forwarding the commands to all shards and combining the results. + */ +class ClusterIndexFilterCmd : public Command { MONGO_DISALLOW_COPYING(ClusterIndexFilterCmd); - public: - virtual ~ClusterIndexFilterCmd() { - } +public: + virtual ~ClusterIndexFilterCmd() {} - bool slaveOk() const { - return false; - } + bool slaveOk() const { + return false; + } - bool slaveOverrideOk() const { - return true; - } + bool slaveOverrideOk() const { + return true; + } - virtual bool isWriteCommandForConfigServer() const { return false; } + virtual bool isWriteCommandForConfigServer() const { + return false; + } - void help(stringstream& ss) const { - ss << _helpText; - } + void help(stringstream& ss) const { + ss << _helpText; + } - Status checkAuthForCommand( ClientBasic* client, - const std::string& dbname, - const BSONObj& cmdObj ) { - AuthorizationSession* authzSession = AuthorizationSession::get(client); - ResourcePattern pattern = parseResourcePattern(dbname, cmdObj); - - if (authzSession->isAuthorizedForActionsOnResource(pattern, - ActionType::planCacheIndexFilter)) { - return Status::OK(); - } - - return Status(ErrorCodes::Unauthorized, "unauthorized"); - } + Status checkAuthForCommand(ClientBasic* client, + const std::string& dbname, + const BSONObj& cmdObj) { + AuthorizationSession* authzSession = AuthorizationSession::get(client); + ResourcePattern pattern = parseResourcePattern(dbname, cmdObj); - // Cluster plan cache command entry point. - bool run(OperationContext* txn, const std::string& dbname, - BSONObj& cmdObj, - int options, - std::string& errmsg, - BSONObjBuilder& result); - - public: - - /** - * Instantiates a command that can be invoked by "name", which will be described by - * "helpText", and will require privilege "actionType" to run. - */ - ClusterIndexFilterCmd( const std::string& name, const std::string& helpText) : - Command( name ), _helpText( helpText ) { + if (authzSession->isAuthorizedForActionsOnResource(pattern, + ActionType::planCacheIndexFilter)) { + return Status::OK(); } - private: - - std::string _helpText; - }; - - // - // Cluster index filter command implementation(s) below - // - - bool ClusterIndexFilterCmd::run(OperationContext* txn, const std::string& dbName, - BSONObj& cmdObj, - int options, - std::string& errMsg, - BSONObjBuilder& result) { - const std::string fullns = parseNs(dbName, cmdObj); - NamespaceString nss(fullns); - - // Dispatch command to all the shards. - // Targeted shard commands are generally data-dependent but index filter - // commands are tied to query shape (data has no effect on query shape). - vector<Strategy::CommandResult> results; - Strategy::commandOp(dbName, cmdObj, options, nss.ns(), BSONObj(), &results); - - // Set value of first shard result's "ok" field. - bool clusterCmdResult = true; - - for (vector<Strategy::CommandResult>::const_iterator i = results.begin(); - i != results.end(); ++i) { - const Strategy::CommandResult& cmdResult = *i; - - // XXX: In absence of sensible aggregation strategy, - // promote first shard's result to top level. - if (i == results.begin()) { - result.appendElements(cmdResult.result); - clusterCmdResult = cmdResult.result["ok"].trueValue(); - } - - // Append shard result as a sub object. - // Name the field after the shard. - result.append(cmdResult.shardTargetId, cmdResult.result); + return Status(ErrorCodes::Unauthorized, "unauthorized"); + } + + // Cluster plan cache command entry point. + bool run(OperationContext* txn, + const std::string& dbname, + BSONObj& cmdObj, + int options, + std::string& errmsg, + BSONObjBuilder& result); + +public: + /** + * Instantiates a command that can be invoked by "name", which will be described by + * "helpText", and will require privilege "actionType" to run. + */ + ClusterIndexFilterCmd(const std::string& name, const std::string& helpText) + : Command(name), _helpText(helpText) {} + +private: + std::string _helpText; +}; + +// +// Cluster index filter command implementation(s) below +// + +bool ClusterIndexFilterCmd::run(OperationContext* txn, + const std::string& dbName, + BSONObj& cmdObj, + int options, + std::string& errMsg, + BSONObjBuilder& result) { + const std::string fullns = parseNs(dbName, cmdObj); + NamespaceString nss(fullns); + + // Dispatch command to all the shards. + // Targeted shard commands are generally data-dependent but index filter + // commands are tied to query shape (data has no effect on query shape). + vector<Strategy::CommandResult> results; + Strategy::commandOp(dbName, cmdObj, options, nss.ns(), BSONObj(), &results); + + // Set value of first shard result's "ok" field. + bool clusterCmdResult = true; + + for (vector<Strategy::CommandResult>::const_iterator i = results.begin(); i != results.end(); + ++i) { + const Strategy::CommandResult& cmdResult = *i; + + // XXX: In absence of sensible aggregation strategy, + // promote first shard's result to top level. + if (i == results.begin()) { + result.appendElements(cmdResult.result); + clusterCmdResult = cmdResult.result["ok"].trueValue(); } - return clusterCmdResult; + // Append shard result as a sub object. + // Name the field after the shard. + result.append(cmdResult.shardTargetId, cmdResult.result); } - // - // Register index filter commands at startup - // + return clusterCmdResult; +} - namespace { +// +// Register index filter commands at startup +// - MONGO_INITIALIZER(RegisterIndexFilterCommands)(InitializerContext* context) { - // Leaked intentionally: a Command registers itself when constructed. +namespace { - new ClusterIndexFilterCmd( - "planCacheListFilters", - "Displays index filters for all query shapes in a collection." ); +MONGO_INITIALIZER(RegisterIndexFilterCommands)(InitializerContext* context) { + // Leaked intentionally: a Command registers itself when constructed. - new ClusterIndexFilterCmd( - "planCacheClearFilters", - "Clears index filter for a single query shape or, " - "if the query shape is omitted, all filters for the collection." ); + new ClusterIndexFilterCmd("planCacheListFilters", + "Displays index filters for all query shapes in a collection."); - new ClusterIndexFilterCmd( - "planCacheSetFilter", - "Sets index filter for a query shape. Overrides existing index filter." ); + new ClusterIndexFilterCmd("planCacheClearFilters", + "Clears index filter for a single query shape or, " + "if the query shape is omitted, all filters for the collection."); - return Status::OK(); - } + new ClusterIndexFilterCmd( + "planCacheSetFilter", + "Sets index filter for a query shape. Overrides existing index filter."); + + return Status::OK(); +} - } // namespace +} // namespace -} // namespace mongo +} // namespace mongo |