summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands.h')
-rw-r--r--src/mongo/db/commands.h63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index b9953e7cb3d..5d26450a01d 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -1,6 +1,5 @@
-// commands.h
-
-/* Copyright 2009 10gen Inc.
+/**
+ * Copyright (C) 2009-2016 MongoDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -50,8 +49,6 @@ namespace mongo {
class BSONObj;
class BSONObjBuilder;
class Client;
-class CurOp;
-class Database;
class OperationContext;
class Timer;
@@ -63,9 +60,9 @@ namespace rpc {
class ServerSelectionMetadata;
} // namespace rpc
-/** mongodb "commands" (sent via db.$cmd.findOne(...))
- subclass to make a command. define a singleton object for it.
- */
+/**
+ * Serves as a base for server commands. See the constructor for more details.
+ */
class Command {
protected:
// The type of the first field in 'cmdObj' must be mongo::String. The first field is
@@ -79,10 +76,26 @@ protected:
public:
typedef StringMap<Command*> CommandMap;
+ /**
+ * Constructs a new command and causes it to be registered with the global commands list. It is
+ * not safe to construct commands other than when the server is starting up.
+ *
+ * @param webUI expose the command in the web ui as localhost:28017/<name>
+ * @param oldName an optional old, deprecated name for the command
+ */
+ Command(StringData name, bool webUI = false, StringData oldName = StringData());
+
// NOTE: Do not remove this declaration, or relocate it in this class. We
// are using this method to control where the vtable is emitted.
virtual ~Command();
+ /**
+ * Returns the command's name. This value never changes for the lifetime of the command.
+ */
+ const std::string& getName() const {
+ return _name;
+ }
+
// 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
@@ -99,8 +112,6 @@ public:
return 0u;
}
- const std::string name;
-
/* run the given command
implement this...
@@ -119,9 +130,9 @@ public:
* Then we won't need to mutate the command object. At that point we can also make
* this method virtual so commands can override it directly.
*/
- /*virtual*/ bool run(OperationContext* txn,
- const rpc::RequestInterface& request,
- rpc::ReplyBuilderInterface* replyBuilder);
+ bool run(OperationContext* txn,
+ const rpc::RequestInterface& request,
+ rpc::ReplyBuilderInterface* replyBuilder);
/* Return true if only the admin ns has privileges to run this command. */
virtual bool adminOnly() const {
@@ -183,9 +194,7 @@ public:
const BSONObj& cmdObj,
ExplainCommon::Verbosity verbosity,
const rpc::ServerSelectionMetadata& serverSelectionMetadata,
- BSONObjBuilder* out) const {
- return Status(ErrorCodes::IllegalOperation, "Cannot explain cmd: " + name);
- }
+ BSONObjBuilder* out) const;
/**
* Checks if the given client is authorized to run this command on database "dbname"
@@ -242,11 +251,6 @@ public:
return LogicalOp::opCommand;
}
- /** @param webUI expose the command in the web ui as localhost:28017/<name>
- @param oldName an optional old, deprecated name for the command
- */
- Command(StringData _name, bool webUI = false, StringData oldName = StringData());
-
protected:
/**
* Appends to "*out" the privileges required to run this command on database "dbname" with
@@ -268,14 +272,11 @@ protected:
Counter64 _commandsExecuted;
Counter64 _commandsFailed;
- // Pointers to hold the metrics tree references
- ServerStatusMetricField<Counter64> _commandsExecutedMetric;
- ServerStatusMetricField<Counter64> _commandsFailedMetric;
-
public:
static const CommandMap* commandsByBestName() {
return _commandsByBestName;
}
+
static const CommandMap* webCommands() {
return _webCommands;
}
@@ -288,6 +289,7 @@ public:
BSONObj& jsobj,
BSONObjBuilder& anObjBuilder,
int queryOptions = 0);
+
static Command* findCommand(StringData name);
/**
@@ -309,7 +311,7 @@ public:
// of Client. This will happen as part of SERVER-18292
static void execCommandClientBasic(OperationContext* txn,
Command* c,
- ClientBasic& client,
+ Client& client,
int queryOptions,
const char* ns,
BSONObj& cmdObj,
@@ -435,9 +437,16 @@ private:
* authorized.
*/
static Status _checkAuthorization(Command* c,
- ClientBasic* client,
+ Client* client,
const std::string& dbname,
const BSONObj& cmdObj);
+
+ // The full name of the command
+ const std::string _name;
+
+ // Pointers to hold the metrics tree references
+ ServerStatusMetricField<Counter64> _commandsExecutedMetric;
+ ServerStatusMetricField<Counter64> _commandsFailedMetric;
};
} // namespace mongo