diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2018-04-02 17:01:35 -0400 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2018-04-02 20:04:36 -0400 |
commit | a16f90edd5339d3f58bec24e2a1639c0b2fd938e (patch) | |
tree | 1142d5c3bc277ca44b407dd28fa04e8303b8867f /src/mongo | |
parent | c872bdd8d24a7beb9df42cbe227e99d6738ba71e (diff) | |
download | mongo-a16f90edd5339d3f58bec24e2a1639c0b2fd938e.tar.gz |
SERVER-34179 refactor isGenericArgument
Remove the static tables floating around at namespace scope.
break CommandHelpers::isGenericArgument into
command_generic_argument library so it doesn't have to be inline.
Some callers depend on it but would have a circularity if they
actually added db/commands to their LIBDEPS.
Diffstat (limited to 'src/mongo')
27 files changed, 219 insertions, 73 deletions
diff --git a/src/mongo/bson/util/bson_check.h b/src/mongo/bson/util/bson_check.h index 4e290024824..2c1ae510d01 100644 --- a/src/mongo/bson/util/bson_check.h +++ b/src/mongo/bson/util/bson_check.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/base/status.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/jsobj.h" #include "mongo/util/mongoutils/str.h" @@ -91,7 +92,7 @@ Status bsonCheckOnlyHasFieldsForCommand(StringData objectName, const BSONObj& obj, const Container& allowedFields) { return bsonCheckOnlyHasFieldsImpl(objectName, obj, [&](StringData name) { - return CommandHelpers::isGenericArgument(name) || + return isGenericArgument(name) || (std::find(std::begin(allowedFields), std::end(allowedFields), name) != std::end(allowedFields)); }); diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 5382ff524bd..7c0d43768ef 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -536,11 +536,22 @@ env.Library( LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/rpc/rpc', 'audit', + 'command_generic_argument', 'commands/server_status_core', ], ) env.Library( + target='command_generic_argument', + source=[ + 'command_generic_argument.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + ], +) + +env.Library( target='command_can_run_here', source=[ 'command_can_run_here.cpp', diff --git a/src/mongo/db/auth/user_management_commands_parser.cpp b/src/mongo/db/auth/user_management_commands_parser.cpp index 141b74ca07d..3785dea3cf8 100644 --- a/src/mongo/db/auth/user_management_commands_parser.cpp +++ b/src/mongo/db/auth/user_management_commands_parser.cpp @@ -43,6 +43,7 @@ #include "mongo/db/auth/privilege_parser.h" #include "mongo/db/auth/user_document_parser.h" #include "mongo/db/auth/user_name.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/jsobj.h" #include "mongo/stdx/unordered_set.h" @@ -61,8 +62,7 @@ Status _checkNoExtraFields(const BSONObj& cmdObj, // ones. for (BSONObjIterator iter(cmdObj); iter.more(); iter.next()) { StringData fieldName = (*iter).fieldNameStringData(); - if (!CommandHelpers::isGenericArgument(fieldName) && - !validFieldNames.count(fieldName.toString())) { + if (!isGenericArgument(fieldName) && !validFieldNames.count(fieldName.toString())) { return Status(ErrorCodes::BadValue, mongoutils::str::stream() << "\"" << fieldName << "\" is not " "a valid argument to " diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript index 5aa69e986c2..fecc8c6d35c 100644 --- a/src/mongo/db/catalog/SConscript +++ b/src/mongo/db/catalog/SConscript @@ -20,6 +20,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/db/command_generic_argument', '$BUILD_DIR/mongo/db/query/collation/collator_interface', '$BUILD_DIR/mongo/db/server_parameters', ], diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 1bf42f508d8..35a082819fd 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -41,6 +41,7 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/client.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/repl/repl_client_info.h" @@ -89,7 +90,7 @@ StatusWith<CollModRequest> parseCollModRequest(OperationContext* opCtx, BSONForEach(e, cmdObj) { const auto fieldName = e.fieldNameStringData(); - if (CommandHelpers::isGenericArgument(fieldName)) { + if (isGenericArgument(fieldName)) { continue; // Don't add to oplog builder. } else if (fieldName == "collMod") { // no-op diff --git a/src/mongo/db/catalog/collection_options.cpp b/src/mongo/db/catalog/collection_options.cpp index 5cedeab2302..67da1098dd0 100644 --- a/src/mongo/db/catalog/collection_options.cpp +++ b/src/mongo/db/catalog/collection_options.cpp @@ -33,6 +33,7 @@ #include <algorithm> #include "mongo/base/string_data.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/query/collation/collator_factory_interface.h" #include "mongo/db/query/collation/collator_interface.h" @@ -253,7 +254,7 @@ Status CollectionOptions::parse(const BSONObj& options, ParseKind kind) { } idIndex = std::move(tempIdIndex); - } else if (!createdOn24OrEarlier && !CommandHelpers::isGenericArgument(fieldName)) { + } else if (!createdOn24OrEarlier && !mongo::isGenericArgument(fieldName)) { return Status(ErrorCodes::InvalidOptions, str::stream() << "The field '" << fieldName << "' is not a valid collection option. Options: " diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index fa79289254b..950420fa787 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -35,6 +35,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/uuid_catalog.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" @@ -72,7 +73,7 @@ Status createCollection(OperationContext* opCtx, BSONObjBuilder optionsBuilder; while (it.more()) { const auto elem = it.next(); - if (!CommandHelpers::isGenericArgument(elem.fieldNameStringData())) + if (!isGenericArgument(elem.fieldNameStringData())) optionsBuilder.append(elem); if (elem.fieldNameStringData() == "viewOn") { // Views don't have UUIDs so it should always be parsed for command. diff --git a/src/mongo/db/command_generic_argument.cpp b/src/mongo/db/command_generic_argument.cpp new file mode 100644 index 00000000000..ef9530d1cb0 --- /dev/null +++ b/src/mongo/db/command_generic_argument.cpp @@ -0,0 +1,106 @@ +/** + * Copyright (C) 2018 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, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/command_generic_argument.h" + +#include <algorithm> +#include <array> +#include <cstdlib> +#include <iterator> + +namespace mongo { + +namespace { + +struct SpecialArgRecord { + StringData name; + bool isGeneric : 1; + bool stripFromRequest : 1; + bool stripFromReply : 1; +}; + +// Not including "help" since we don't pass help requests through to the command parser. +// If that changes, it should be added. When you add to this list, consider whether you +// should also change the filterCommandRequestForPassthrough() function. +// clang-format off +static constexpr std::array<SpecialArgRecord, 23> specials{{ + // /-isGeneric + // | /-stripFromRequest + // | | /-stripFromReply + {"$audit"_sd, 1, 1, 0}, + {"$client"_sd, 1, 1, 0}, + {"$configServerState"_sd, 1, 1, 1}, + {"$db"_sd, 1, 1, 0}, + {"allowImplicitCollectionCreation"_sd, 1, 1, 0}, + {"$oplogQueryData"_sd, 1, 1, 1}, + {"$queryOptions"_sd, 1, 0, 0}, + {"$readPreference"_sd, 1, 1, 0}, + {"$replData"_sd, 1, 1, 1}, + {"$clusterTime"_sd, 1, 1, 1}, + {"maxTimeMS"_sd, 1, 0, 0}, + {"readConcern"_sd, 1, 0, 0}, + {"databaseVersion"_sd, 1, 1, 0}, + {"shardVersion"_sd, 1, 1, 0}, + {"tracking_info"_sd, 1, 1, 0}, + {"writeConcern"_sd, 1, 0, 0}, + {"lsid"_sd, 1, 0, 0}, + {"txnNumber"_sd, 1, 0, 0}, + {"autocommit"_sd, 1, 1, 0}, + {"stmtId"_sd, 1, 0, 0}, + {"$gleStats"_sd, 0, 0, 1}, + {"operationTime"_sd, 0, 0, 1}, + {"lastCommittedOpTime"_sd, 0, 0, 1}}}; +// clang-format on + +const SpecialArgRecord* findSpecialArg(StringData arg) { + for (const auto& e : specials) + if (e.name == arg) + return &e; + return nullptr; +} + +} // namespace + +bool isGenericArgument(StringData arg) { + auto p = findSpecialArg(arg); + return p && p->isGeneric; +} + +bool isRequestStripArgument(StringData arg) { + auto p = findSpecialArg(arg); + return p && p->stripFromRequest; +} + +bool isReplyStripArgument(StringData arg) { + auto p = findSpecialArg(arg); + return p && p->stripFromReply; +} + +} // namespace mongo diff --git a/src/mongo/db/command_generic_argument.h b/src/mongo/db/command_generic_argument.h new file mode 100644 index 00000000000..df3a96da578 --- /dev/null +++ b/src/mongo/db/command_generic_argument.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2018 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, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/base/string_data.h" + +namespace mongo { + +/** + * Returns true if the provided argument is one that is handled by the command processing layer + * and should generally be ignored by individual command implementations. In particular, + * commands that fail on unrecognized arguments must not fail for any of these. + */ +bool isGenericArgument(StringData arg); + +/** + * Returns true if arg must be stripped from requests that are forwarded to shards. + * Only generic arguments are stripped, and some of them are not. + * See 'CommandHelpers::filterCommandRequestForPassthrough'. + */ +bool isRequestStripArgument(StringData arg); + +/** + * Returns true if arg is not safe to blindly forward from shards to clients. + * See 'CommandHelpers::filterCommandReplyForPassthrough'. + */ +bool isReplyStripArgument(StringData arg); + +} // namespace mongo diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index 6ebd7f38a34..103bd17dbeb 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -44,6 +44,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/client.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/curop.h" #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" @@ -285,18 +286,11 @@ void CommandHelpers::filterCommandRequestForPassthrough(BSONObjIterator* cmdIter const auto name = elem.fieldNameStringData(); if (name == "$readPreference") { BSONObjBuilder(requestBuilder->subobjStart("$queryOptions")).append(elem); - } else if (!isGenericArgument(name) || // - name == "$queryOptions" || // - name == "maxTimeMS" || // - name == "readConcern" || // - name == "writeConcern" || // - name == "lsid" || // - name == "txnNumber" || // - name == "stmtId") { - // This is the whitelist of generic arguments that commands can be trusted to blindly - // forward to the shards. - requestBuilder->append(elem); + continue; } + if (isRequestStripArgument(name)) + continue; + requestBuilder->append(elem); } } @@ -304,15 +298,8 @@ void CommandHelpers::filterCommandReplyForPassthrough(const BSONObj& cmdObj, BSONObjBuilder* output) { for (auto elem : cmdObj) { const auto name = elem.fieldNameStringData(); - if (name == "$configServerState" || // - name == "$gleStats" || // - name == "$clusterTime" || // - name == "$oplogQueryData" || // - name == "$replData" || // - name == "operationTime" || - name == "lastCommittedOpTime") { + if (isReplyStripArgument(name)) continue; - } output->append(elem); } } diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index 0284c852f27..cc69458f5ad 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -115,38 +115,6 @@ struct CommandHelpers { static BSONObj appendMajorityWriteConcern(const BSONObj& cmdObj); /** - * Returns true if the provided argument is one that is handled by the command processing layer - * and should generally be ignored by individual command implementations. In particular, - * commands that fail on unrecognized arguments must not fail for any of these. - */ - static bool isGenericArgument(StringData arg) { - // Not including "help" since we don't pass help requests through to the command parser. - // If that changes, it should be added. When you add to this list, consider whether you - // should also change the filterCommandRequestForPassthrough() function. - return arg == "$audit" || // - arg == "$client" || // - arg == "$configServerState" || // - arg == "$db" || // - arg == "allowImplicitCollectionCreation" || // - arg == "$oplogQueryData" || // - arg == "$queryOptions" || // - arg == "$readPreference" || // - arg == "$replData" || // - arg == "$clusterTime" || // - arg == "maxTimeMS" || // - arg == "readConcern" || // - arg == "databaseVersion" || // - arg == "shardVersion" || // - arg == "tracking_info" || // - arg == "writeConcern" || // - arg == "lsid" || // - arg == "txnNumber" || // - arg == "autocommit" || // - arg == "stmtId" || // - false; // These comments tell clang-format to keep this line-oriented. - } - - /** * Rewrites cmdObj into a format safe to blindly forward to shards. * * This performs 2 transformations: diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 52d64c426c7..206260fd7de 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -68,6 +68,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/db/command_generic_argument', '$BUILD_DIR/mongo/db/namespace_string', ], ) diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 7abb14531b7..1606db4e7c7 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -39,6 +39,7 @@ #include "mongo/db/catalog/index_create.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/client.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -128,8 +129,7 @@ StatusWith<std::vector<BSONObj>> parseAndValidateIndexSpecs( } hasIndexesField = true; - } else if (kCommandName == cmdElemFieldName || - CommandHelpers::isGenericArgument(cmdElemFieldName)) { + } else if (kCommandName == cmdElemFieldName || isGenericArgument(cmdElemFieldName)) { continue; } else { return {ErrorCodes::BadValue, diff --git a/src/mongo/db/commands/current_op_common.cpp b/src/mongo/db/commands/current_op_common.cpp index 7f85aa2952d..35bbadb32a6 100644 --- a/src/mongo/db/commands/current_op_common.cpp +++ b/src/mongo/db/commands/current_op_common.cpp @@ -32,6 +32,7 @@ #include <string> +#include "mongo/db/command_generic_argument.h" #include "mongo/db/namespace_string.h" namespace mongo { @@ -66,7 +67,7 @@ bool CurrentOpCommandBase::run(OperationContext* opCtx, const auto fieldName = elt.fieldNameStringData(); if (0 == idx++ || fieldName == "$all" || fieldName == "$ownOps" || - CommandHelpers::isGenericArgument(fieldName)) { + isGenericArgument(fieldName)) { continue; } diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp index 2a3401a149b..8bac0ea3b4e 100644 --- a/src/mongo/db/commands/dbcheck.cpp +++ b/src/mongo/db/commands/dbcheck.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/health_log.h" #include "mongo/db/catalog/uuid_catalog.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -156,7 +157,7 @@ std::unique_ptr<DbCheckRun> getRun(OperationContext* opCtx, // Get rid of generic command fields. for (const auto& elem : obj) { - if (!CommandHelpers::isGenericArgument(elem.fieldNameStringData())) { + if (!isGenericArgument(elem.fieldNameStringData())) { builder.append(elem); } } diff --git a/src/mongo/db/commands/feature_compatibility_version_command_parser.cpp b/src/mongo/db/commands/feature_compatibility_version_command_parser.cpp index f9a66bd6f34..2e15ce22a91 100644 --- a/src/mongo/db/commands/feature_compatibility_version_command_parser.cpp +++ b/src/mongo/db/commands/feature_compatibility_version_command_parser.cpp @@ -32,6 +32,7 @@ #include "mongo/base/status_with.h" #include "mongo/bson/bsonobj.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/commands/feature_compatibility_version_documentation.h" #include "mongo/db/commands/feature_compatibility_version_parser.h" @@ -65,7 +66,7 @@ StatusWith<std::string> FeatureCompatibilityVersionCommandParser::extractVersion // Ensure that the command does not contain any unrecognized parameters for (const auto& cmdElem : cmdObj) { const auto fieldName = cmdElem.fieldNameStringData(); - if (fieldName == commandName || CommandHelpers::isGenericArgument(fieldName)) { + if (fieldName == commandName || isGenericArgument(fieldName)) { continue; } diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 900434db737..7d8b277e798 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -33,6 +33,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/client.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/curop.h" #include "mongo/db/field_parser.h" @@ -213,7 +214,7 @@ public: BSONObj writeConcernDoc = ([&] { BSONObjBuilder bob; for (auto&& elem : cmdObj) { - if (!CommandHelpers::isGenericArgument(elem.fieldNameStringData())) + if (!isGenericArgument(elem.fieldNameStringData())) bob.append(elem); } return bob.obj(); diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index 29e801a72d8..f21958bfe53 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -38,6 +38,7 @@ #include "mongo/config.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/internal_user_auth.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/server_parameters.h" #include "mongo/db/storage/storage_options.h" @@ -164,7 +165,7 @@ public: while (parameterCheckIterator.more()) { BSONElement parameter = parameterCheckIterator.next(); std::string parameterName = parameter.fieldName(); - if (CommandHelpers::isGenericArgument(parameterName)) + if (isGenericArgument(parameterName)) continue; ServerParameter::Map::const_iterator foundParameter = parameterMap.find(parameterName); diff --git a/src/mongo/db/pipeline/aggregation_request.cpp b/src/mongo/db/pipeline/aggregation_request.cpp index 8eb646a7599..4f86b1c2a81 100644 --- a/src/mongo/db/pipeline/aggregation_request.cpp +++ b/src/mongo/db/pipeline/aggregation_request.cpp @@ -36,6 +36,7 @@ #include "mongo/base/status_with.h" #include "mongo/base/string_data.h" #include "mongo/db/catalog/document_validation.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/value.h" @@ -214,7 +215,7 @@ StatusWith<AggregationRequest> AggregationRequest::parseFromBSON( request.setAllowDiskUse(elem.Bool()); } else if (bypassDocumentValidationCommandOption() == fieldName) { request.setBypassDocumentValidation(elem.trueValue()); - } else if (!CommandHelpers::isGenericArgument(fieldName)) { + } else if (!isGenericArgument(fieldName)) { return {ErrorCodes::FailedToParse, str::stream() << "unrecognized field '" << elem.fieldName() << "'"}; } diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp index 21db56e4274..a6b29ea520b 100644 --- a/src/mongo/db/query/getmore_request.cpp +++ b/src/mongo/db/query/getmore_request.cpp @@ -34,6 +34,7 @@ #include <boost/optional.hpp> +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/bson_extract_optime.h" @@ -158,7 +159,7 @@ StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbna return status; } lastKnownCommittedOpTime = ot; - } else if (!CommandHelpers::isGenericArgument(fieldName)) { + } else if (!isGenericArgument(fieldName)) { return {ErrorCodes::FailedToParse, str::stream() << "Failed to parse: " << cmdObj << ". " << "Unrecognized field '" diff --git a/src/mongo/db/query/query_request.cpp b/src/mongo/db/query/query_request.cpp index 4978aad81f8..6268785c6a6 100644 --- a/src/mongo/db/query/query_request.cpp +++ b/src/mongo/db/query/query_request.cpp @@ -35,6 +35,7 @@ #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/client/dbclientinterface.h" #include "mongo/db/catalog/uuid_catalog.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/dbmessage.h" #include "mongo/db/namespace_string.h" @@ -374,7 +375,7 @@ StatusWith<unique_ptr<QueryRequest>> QueryRequest::parseFromFindCommand(unique_p return status; } qr->_replicationTerm = el._numberLong(); - } else if (!CommandHelpers::isGenericArgument(fieldName)) { + } else if (!isGenericArgument(fieldName)) { return Status(ErrorCodes::FailedToParse, str::stream() << "Failed to parse: " << cmdObj.toString() << ". " << "Unrecognized field '" diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript index 87c5d3c2158..b7fdf916c29 100644 --- a/src/mongo/idl/SConscript +++ b/src/mongo/idl/SConscript @@ -10,6 +10,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/db/command_generic_argument', ] ) diff --git a/src/mongo/idl/idl_parser.cpp b/src/mongo/idl/idl_parser.cpp index a8b591a43db..1ec3ed93459 100644 --- a/src/mongo/idl/idl_parser.cpp +++ b/src/mongo/idl/idl_parser.cpp @@ -33,7 +33,7 @@ #include "mongo/idl/idl_parser.h" #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/commands.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/util/mongoutils/str.h" namespace mongo { @@ -247,7 +247,7 @@ void IDLParserErrorContext::appendGenericCommandArguments( StringData name = element.fieldNameStringData(); // Include a passthrough field as long the IDL class has not defined it. - if (CommandHelpers::isGenericArgument(name) && + if (mongo::isGenericArgument(name) && std::find(knownFields.begin(), knownFields.end(), name) == knownFields.end()) { builder->append(element); } diff --git a/src/mongo/rpc/command_request_builder.cpp b/src/mongo/rpc/command_request_builder.cpp index 051989015d5..68b39a460de 100644 --- a/src/mongo/rpc/command_request_builder.cpp +++ b/src/mongo/rpc/command_request_builder.cpp @@ -31,6 +31,7 @@ #include "mongo/rpc/command_request_builder.h" #include "mongo/client/read_preference.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/util/assert_util.h" @@ -40,7 +41,7 @@ namespace rpc { namespace { // OP_COMMAND put some generic arguments in the metadata and some in the body. bool fieldGoesInMetadata(StringData commandName, StringData field) { - if (!CommandHelpers::isGenericArgument(field)) + if (!isGenericArgument(field)) return false; // All non-generic arguments go to the body. // For some reason this goes in the body only for a single command... diff --git a/src/mongo/s/commands/cluster_explain.cpp b/src/mongo/s/commands/cluster_explain.cpp index 3b455954ca9..1498ea9fe80 100644 --- a/src/mongo/s/commands/cluster_explain.cpp +++ b/src/mongo/s/commands/cluster_explain.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" #include "mongo/bson/bsonmisc.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/client/shard_registry.h" @@ -138,7 +139,7 @@ BSONObj ClusterExplain::wrapAsExplain(const BSONObj& cmdObj, ExplainOptions::Ver // Propagate all generic arguments out of the inner command since the shards will only process // them at the top level. for (auto elem : filtered) { - if (CommandHelpers::isGenericArgument(elem.fieldNameStringData())) { + if (isGenericArgument(elem.fieldNameStringData())) { out.append(elem); } } diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp index 4a8dfc091a6..24254f24054 100644 --- a/src/mongo/s/commands/cluster_explain_cmd.cpp +++ b/src/mongo/s/commands/cluster_explain_cmd.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" #include "mongo/client/dbclientinterface.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/query/explain.h" #include "mongo/s/query/cluster_find.h" @@ -194,7 +195,7 @@ std::unique_ptr<CommandInvocation> ClusterExplainCmd::parse(OperationContext* op // If the argument is in both the inner and outer command, we currently let the // inner version take precedence. const auto name = outerElem.fieldNameStringData(); - if (CommandHelpers::isGenericArgument(name) && !innerObj.hasField(name)) { + if (isGenericArgument(name) && !innerObj.hasField(name)) { bob.append(outerElem); } } diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp index 6fe1d46770f..0650a073fa0 100644 --- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp @@ -38,6 +38,7 @@ #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/client/connpool.h" #include "mongo/db/catalog/document_validation.h" +#include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/commands/mr.h" #include "mongo/db/query/collation/collation_spec.h" @@ -93,7 +94,7 @@ BSONObj fixForShards(const BSONObj& orig, b.append(e); } else if (fn == "out" || fn == "finalize" || fn == "writeConcern") { // We don't want to copy these - } else if (!CommandHelpers::isGenericArgument(fn)) { + } else if (!isGenericArgument(fn)) { badShardedField = fn.toString(); return BSONObj(); } |