summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.h
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2018-04-20 15:58:46 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2018-05-01 10:31:16 -0400
commit2ed975c6d96dfe0b61bea703ea4f9086b1cee24e (patch)
tree7992d2faf077b4ba15251d41cc5733f451562f47 /src/mongo/db/commands.h
parentbf76453a0dcb0e4309f5b249cfe30cffe101b1b4 (diff)
downloadmongo-2ed975c6d96dfe0b61bea703ea4f9086b1cee24e.tar.gz
SERVER-34596 remove Command::parseNs
Diffstat (limited to 'src/mongo/db/commands.h')
-rw-r--r--src/mongo/db/commands.h57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 564c1d1ef75..dbdaf8153a4 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -51,6 +51,7 @@
namespace mongo {
class Command;
+class CommandInvocation;
class OperationContext;
namespace mutablebson {
@@ -71,6 +72,22 @@ struct CommandHelpers {
static NamespaceStringOrUUID parseNsOrUUID(StringData dbname, const BSONObj& cmdObj);
+ /**
+ * Return the namespace for the command. If the first field in 'cmdObj' is of type
+ * mongo::String, then that field is interpreted as the collection name, and is
+ * appended to 'dbname' after a '.' character. If the first field is not of type
+ * mongo::String, then 'dbname' is returned unmodified.
+ */
+ static std::string parseNsFromCommand(StringData dbname, const BSONObj& cmdObj);
+
+ /**
+ * Utility that returns a ResourcePattern for the namespace returned from
+ * BasicCommand::parseNs(dbname, cmdObj). This will be either an exact namespace resource
+ * pattern or a database resource pattern, depending on whether parseNs returns a fully qualifed
+ * collection name or just a database name.
+ */
+ static ResourcePattern resourcePatternForNamespace(const std::string& ns);
+
static Command* findCommand(StringData name);
// Helper for setting errmsg and ok field in command result object.
@@ -188,7 +205,7 @@ struct CommandHelpers {
static BSONObj runCommandDirectly(OperationContext* opCtx, const OpMsgRequest& request);
static void logAuthViolation(OperationContext* opCtx,
- const Command* command,
+ const CommandInvocation* invocation,
const OpMsgRequest& request,
ErrorCodes::Error err);
@@ -197,8 +214,6 @@ struct CommandHelpers {
static constexpr StringData kHelpFieldName = "help"_sd;
};
-class CommandInvocation;
-
/**
* Serves as a base for server commands. See the constructor for more details.
*/
@@ -230,23 +245,6 @@ public:
}
/**
- * Return the namespace for the command. If the first field in 'cmdObj' is of type
- * mongo::String, then that field is interpreted as the collection name, and is
- * appended to 'dbname' after a '.' character. If the first field is not of type
- * mongo::String, then 'dbname' is returned unmodified.
- */
- virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const;
-
- /**
- * Utility that returns a ResourcePattern for the namespace returned from
- * parseNs(dbname, cmdObj). This will be either an exact namespace resource pattern
- * or a database resource pattern, depending on whether parseNs returns a fully qualifed
- * collection name or just a database name.
- */
- virtual ResourcePattern parseResourcePattern(const std::string& dbname,
- const BSONObj& cmdObj) const;
-
- /**
* Used by command implementations to hint to the rpc system how much space they will need in
* their replies.
*/
@@ -359,14 +357,14 @@ public:
/**
* Increment counter for how many times this command has executed.
*/
- void incrementCommandsExecuted() {
+ void incrementCommandsExecuted() const {
_commandsExecuted.increment();
}
/**
* Increment counter for how many times this command has failed.
*/
- void incrementCommandsFailed() {
+ void incrementCommandsFailed() const {
_commandsFailed.increment();
}
@@ -379,13 +377,12 @@ public:
const Command& command);
private:
- // Counters for how many times this command has been executed and failed
- Counter64 _commandsExecuted;
- Counter64 _commandsFailed;
-
// The full name of the command
const std::string _name;
+ // Counters for how many times this command has been executed and failed
+ mutable Counter64 _commandsExecuted;
+ mutable Counter64 _commandsFailed;
// Pointers to hold the metrics tree references
ServerStatusMetricField<Counter64> _commandsExecutedMetric;
ServerStatusMetricField<Counter64> _commandsFailedMetric;
@@ -562,6 +559,14 @@ private:
public:
using Command::Command;
+ virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const {
+ return CommandHelpers::parseNsFromCommand(dbname, cmdObj);
+ }
+
+ ResourcePattern parseResourcePattern(const std::string& dbname, const BSONObj& cmdObj) const {
+ return CommandHelpers::resourcePatternForNamespace(parseNs(dbname, cmdObj));
+ }
+
//
// Interface for subclasses to implement
//