diff options
author | Amirsaman Memaripour <amirsaman.memaripour@10gen.com> | 2020-01-23 17:14:41 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-23 17:14:41 +0000 |
commit | 3cd3a6da3fe0b6f022b721094bda0b97c3527d23 (patch) | |
tree | 05a14ef581b1250f81a5cc33c567edc0f4d074f1 /src/mongo/db/commands.h | |
parent | 85f4d7a449d5bb6eb5668ea53f727f591cc820ad (diff) | |
download | mongo-3cd3a6da3fe0b6f022b721094bda0b97c3527d23.tar.gz |
SERVER-45202 Improve command alias infrastructure
Diffstat (limited to 'src/mongo/db/commands.h')
-rw-r--r-- | src/mongo/db/commands.h | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index b993a6b737c..8590d3b9f16 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -228,16 +228,14 @@ struct CommandHelpers { * Checks if the command passed in is in the list of failCommands defined in the fail point. */ static bool shouldActivateFailCommandFailPoint(const BSONObj& data, - StringData cmdName, - Client* client, - const NamespaceString& nss); + const CommandInvocation* invocation, + Client* client); /** * Possibly uasserts according to the "failCommand" fail point. */ static void evaluateFailCommandFailPoint(OperationContext* opCtx, - StringData commandName, - const NamespaceString& nss); + const CommandInvocation* invocation); /** * Handles marking kill on client disconnect. @@ -258,9 +256,15 @@ public: * 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 oldName an optional old, deprecated name for the command + * @param oldName an old, deprecated name for the command */ - Command(StringData name, StringData oldName = StringData()); + Command(StringData name, StringData oldName) + : Command(name, std::vector<StringData>({oldName})) {} + + /** + * @param aliases the optional list of aliases (e.g., old names) for the command + */ + Command(StringData name, std::vector<StringData> aliases = {}); Command(const Command&) = delete; Command& operator=(const Command&) = delete; @@ -430,10 +434,18 @@ public: return true; } + /** + * Checks if the command is also known by the provided alias. + */ + bool hasAlias(const StringData& alias) const; + private: // The full name of the command const std::string _name; + // The list of aliases for the command + const std::vector<StringData> _aliases; + // Counters for how many times this command has been executed and failed mutable Counter64 _commandsExecuted; mutable Counter64 _commandsFailed; @@ -884,7 +896,7 @@ public: return _commands; } - void registerCommand(Command* command, StringData name, StringData oldName); + void registerCommand(Command* command, StringData name, std::vector<StringData> aliases); Command* findCommand(StringData name) const; |