summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/commands/cluster_plan_cache_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_plan_cache_cmd.cpp224
1 files changed, 110 insertions, 114 deletions
diff --git a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
index bb66ce55998..1411f5bc3b1 100644
--- a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
+++ b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
@@ -38,141 +38,137 @@
namespace mongo {
- using std::string;
- using std::stringstream;
- using std::vector;
+using std::string;
+using std::stringstream;
+using std::vector;
- /**
- * Base class for mongos plan cache commands.
- * Cluster plan cache commands don't do much more than
- * forwarding the commands to all shards and combining the results.
- */
- class ClusterPlanCacheCmd : public Command {
+/**
+ * Base class for mongos plan cache commands.
+ * Cluster plan cache commands don't do much more than
+ * forwarding the commands to all shards and combining the results.
+ */
+class ClusterPlanCacheCmd : public Command {
MONGO_DISALLOW_COPYING(ClusterPlanCacheCmd);
- public:
- virtual ~ClusterPlanCacheCmd() {
- }
+public:
+ virtual ~ClusterPlanCacheCmd() {}
- bool slaveOk() const {
- return false;
- }
-
- bool slaveOverrideOk() const {
- return true;
- }
+ bool slaveOk() const {
+ return false;
+ }
- virtual bool isWriteCommandForConfigServer() const { return false; }
+ bool slaveOverrideOk() const {
+ return true;
+ }
- void help(stringstream& ss) const {
- ss << _helpText;
- }
+ virtual bool isWriteCommandForConfigServer() const {
+ return false;
+ }
- Status checkAuthForCommand( ClientBasic* client,
- const std::string& dbname,
- const BSONObj& cmdObj ) {
- AuthorizationSession* authzSession = AuthorizationSession::get(client);
- ResourcePattern pattern = parseResourcePattern(dbname, cmdObj);
+ void help(stringstream& ss) const {
+ ss << _helpText;
+ }
- if (authzSession->isAuthorizedForActionsOnResource(pattern, _actionType)) {
- return Status::OK();
- }
+ Status checkAuthForCommand(ClientBasic* client,
+ const std::string& dbname,
+ const BSONObj& cmdObj) {
+ AuthorizationSession* authzSession = AuthorizationSession::get(client);
+ ResourcePattern pattern = parseResourcePattern(dbname, cmdObj);
- return Status(ErrorCodes::Unauthorized, "unauthorized");
+ if (authzSession->isAuthorizedForActionsOnResource(pattern, _actionType)) {
+ return Status::OK();
}
- // 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.
- */
- ClusterPlanCacheCmd( const std::string& name, const std::string& helpText,
- ActionType actionType ) :
- Command( name ), _helpText( helpText ), _actionType( actionType ) {
- }
+ 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);
- private:
-
- std::string _helpText;
- ActionType _actionType;
- };
-
- //
- // Cluster plan cache command implementation(s) below
- //
-
- bool ClusterPlanCacheCmd::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 plan cache
- // 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.
- string shardName = cmdResult.shardTargetId;
- result.append(shardName, cmdResult.result);
+public:
+ /**
+ * Instantiates a command that can be invoked by "name", which will be described by
+ * "helpText", and will require privilege "actionType" to run.
+ */
+ ClusterPlanCacheCmd(const std::string& name, const std::string& helpText, ActionType actionType)
+ : Command(name), _helpText(helpText), _actionType(actionType) {}
+
+private:
+ std::string _helpText;
+ ActionType _actionType;
+};
+
+//
+// Cluster plan cache command implementation(s) below
+//
+
+bool ClusterPlanCacheCmd::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 plan cache
+ // 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.
+ string shardName = cmdResult.shardTargetId;
+ result.append(shardName, cmdResult.result);
}
- //
- // Register plan cache commands at startup
- //
+ return clusterCmdResult;
+}
- namespace {
+//
+// Register plan cache commands at startup
+//
- MONGO_INITIALIZER(RegisterPlanCacheCommands)(InitializerContext* context) {
- // Leaked intentionally: a Command registers itself when constructed.
+namespace {
- new ClusterPlanCacheCmd(
- "planCacheListQueryShapes",
- "Displays all query shapes in a collection.",
- ActionType::planCacheRead );
+MONGO_INITIALIZER(RegisterPlanCacheCommands)(InitializerContext* context) {
+ // Leaked intentionally: a Command registers itself when constructed.
- new ClusterPlanCacheCmd(
- "planCacheClear",
- "Drops one or all cached queries in a collection.",
- ActionType::planCacheWrite );
+ new ClusterPlanCacheCmd("planCacheListQueryShapes",
+ "Displays all query shapes in a collection.",
+ ActionType::planCacheRead);
- new ClusterPlanCacheCmd(
- "planCacheListPlans",
- "Displays the cached plans for a query shape.",
- ActionType::planCacheRead );
+ new ClusterPlanCacheCmd("planCacheClear",
+ "Drops one or all cached queries in a collection.",
+ ActionType::planCacheWrite);
- return Status::OK();
- }
+ new ClusterPlanCacheCmd("planCacheListPlans",
+ "Displays the cached plans for a query shape.",
+ ActionType::planCacheRead);
+
+ return Status::OK();
+}
- } // namespace
+} // namespace
-} // namespace mongo
+} // namespace mongo