diff options
Diffstat (limited to 'src/mongo/db/query')
40 files changed, 473 insertions, 449 deletions
diff --git a/src/mongo/db/query/README.md b/src/mongo/db/query/README.md index ffb98c9fe7a..ec3e0c203e4 100644 --- a/src/mongo/db/query/README.md +++ b/src/mongo/db/query/README.md @@ -86,7 +86,7 @@ commands: count: description: "Parser for the 'count' command." command_name: count - cpp_name: CountCommand + cpp_name: CountCommandRequest strict: true namespace: concatenate_with_db_or_uuid fields: @@ -111,7 +111,7 @@ we don't have to write any code to handle that. The generated file will have methods to get and set all the members, and will return a boost::optional for optional fields. In the example above, -it will generate a CountCommand::getQuery() method, among others. +it will generate a CountCommandRequest::getQuery() method, among others. ### Other actions performed during this stage @@ -215,9 +215,9 @@ Once we have parsed the command and checked authorization, we move on to parsing parts of the query. Once again, we will focus on the find and aggregate commands. ### Find command parsing -The find command is parsed entirely by the IDL. Initially the IDL parser creates a FindCommand. As -mentioned above, the IDL parser does all of the required type checking and stores all options for -the query. The FindCommand is then turned into a CanonicalQuery. The CanonicalQuery +The find command is parsed entirely by the IDL. The IDL parser first creates a FindCommandRequest. +As mentioned above, the IDL parser does all of the required type checking and stores all options for +the query. The FindCommandRequest is then turned into a CanonicalQuery. The CanonicalQuery parses the collation and the filter while just holding the rest of the IDL parsed fields. The parsing of the collation is straightforward: for each field that is allowed to be in the object, we check for that field and then build the collation from the parsed fields. @@ -270,7 +270,7 @@ give a summary of how each is parsed, but not get into the same level of detail. * count : Parsed by IDL and then turned into a CountStage which can be executed in a similar way to a find command. * distinct : The distinct specific arguments are parsed by IDL, and the generic command arguments - are parsed by custom code. They are then combined into a FindCommand (mentioned above), + are parsed by custom code. They are then combined into a FindCommandRequest (mentioned above), canonicalized, packaged into a ParsedDistinct, which is eventually turned into an executable stage. * mapReduce : Parsed by IDL and then turned into an equivalent aggregation command. diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 2b24dac9f9a..99771b5f043 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -66,7 +66,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( const ExtensionsCallback& extensionsCallback, MatchExpressionParser::AllowedFeatureSet allowedFeatures) { bool explain = false; - // Make FindCommand. + // Make FindCommandRequest. auto status = query_request_helper::fromLegacyQueryMessage(qm, &explain); if (!status.isOK()) { return status.getStatus(); @@ -79,13 +79,13 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( OperationContext* opCtx, - std::unique_ptr<FindCommand> findCommand, + std::unique_ptr<FindCommandRequest> findCommand, bool explain, const boost::intrusive_ptr<ExpressionContext>& expCtx, const ExtensionsCallback& extensionsCallback, MatchExpressionParser::AllowedFeatureSet allowedFeatures, const ProjectionPolicies& projectionPolicies) { - auto status = query_request_helper::validateFindCommand(*findCommand); + auto status = query_request_helper::validateFindCommandRequest(*findCommand); if (!status.isOK()) { return status; } @@ -111,7 +111,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( findCommand->getLet()); } else { newExpCtx = expCtx; - // A collator can enter through both the FindCommand and ExpressionContext arguments. + // A collator can enter through both the FindCommandRequest and ExpressionContext arguments. // This invariant ensures that both collators are the same because downstream we // pull the collator from only one of the ExpressionContext carrier. if (collator.get() && expCtx->getCollator()) { @@ -158,14 +158,14 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( // static StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( OperationContext* opCtx, const CanonicalQuery& baseQuery, MatchExpression* root) { - auto findCommand = std::make_unique<FindCommand>(baseQuery.nss()); + auto findCommand = std::make_unique<FindCommandRequest>(baseQuery.nss()); BSONObjBuilder builder; root->serialize(&builder, true); findCommand->setFilter(builder.obj()); - findCommand->setProjection(baseQuery.getFindCommand().getProjection().getOwned()); - findCommand->setSort(baseQuery.getFindCommand().getSort().getOwned()); - findCommand->setCollation(baseQuery.getFindCommand().getCollation().getOwned()); - auto status = query_request_helper::validateFindCommand(*findCommand); + findCommand->setProjection(baseQuery.getFindCommandRequest().getProjection().getOwned()); + findCommand->setSort(baseQuery.getFindCommandRequest().getSort().getOwned()); + findCommand->setCollation(baseQuery.getFindCommandRequest().getCollation().getOwned()); + auto status = query_request_helper::validateFindCommandRequest(*findCommand); if (!status.isOK()) { return status; } @@ -188,7 +188,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( Status CanonicalQuery::init(OperationContext* opCtx, boost::intrusive_ptr<ExpressionContext> expCtx, - std::unique_ptr<FindCommand> findCommand, + std::unique_ptr<FindCommandRequest> findCommand, bool canHaveNoopMatchNodes, std::unique_ptr<MatchExpression> root, const ProjectionPolicies& projectionPolicies) { @@ -342,7 +342,7 @@ bool hasNodeInSubtree(MatchExpression* root, } StatusWith<QueryMetadataBitSet> CanonicalQuery::isValid(MatchExpression* root, - const FindCommand& findCommand) { + const FindCommandRequest& findCommand) { QueryMetadataBitSet unavailableMetadata{}; // There can only be one TEXT. If there is a TEXT, it cannot appear inside a NOR. diff --git a/src/mongo/db/query/canonical_query.h b/src/mongo/db/query/canonical_query.h index 4b148557710..e6d3d8c2171 100644 --- a/src/mongo/db/query/canonical_query.h +++ b/src/mongo/db/query/canonical_query.h @@ -77,7 +77,7 @@ public: */ static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize( OperationContext* opCtx, - std::unique_ptr<FindCommand> findCommand, + std::unique_ptr<FindCommandRequest> findCommand, bool explain = false, const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr, const ExtensionsCallback& extensionsCallback = ExtensionsCallbackNoop(), @@ -118,7 +118,7 @@ public: * error. */ static StatusWith<QueryMetadataBitSet> isValid(MatchExpression* root, - const FindCommand& findCommand); + const FindCommandRequest& findCommand); const NamespaceString nss() const { invariant(_findCommand->getNamespaceOrUUID().nss()); @@ -137,7 +137,7 @@ public: const BSONObj& getQueryObj() const { return _findCommand->getFilter(); } - const FindCommand& getFindCommand() const { + const FindCommandRequest& getFindCommandRequest() const { return *_findCommand; } @@ -237,7 +237,7 @@ private: Status init(OperationContext* opCtx, boost::intrusive_ptr<ExpressionContext> expCtx, - std::unique_ptr<FindCommand> findCommand, + std::unique_ptr<FindCommandRequest> findCommand, bool canHaveNoopMatchNodes, std::unique_ptr<MatchExpression> root, const ProjectionPolicies& projectionPolicies); @@ -250,7 +250,7 @@ private: boost::intrusive_ptr<ExpressionContext> _expCtx; - std::unique_ptr<FindCommand> _findCommand; + std::unique_ptr<FindCommandRequest> _findCommand; std::unique_ptr<MatchExpression> _root; diff --git a/src/mongo/db/query/canonical_query_encoder.cpp b/src/mongo/db/query/canonical_query_encoder.cpp index 41e7af395f8..c9821b90440 100644 --- a/src/mongo/db/query/canonical_query_encoder.cpp +++ b/src/mongo/db/query/canonical_query_encoder.cpp @@ -478,9 +478,8 @@ void encodeKeyForMatch(const MatchExpression* tree, StringBuilder* keyBuilder) { } /** - * Encodes sort order into cache key. - * Sort order is normalized because it provided by - * FindCommand. + * Encodes sort order into cache key. Sort order is normalized because it provided by + * FindCommandRequest. */ void encodeKeyForSort(const BSONObj& sortObj, StringBuilder* keyBuilder) { if (sortObj.isEmpty()) { @@ -567,7 +566,7 @@ namespace canonical_query_encoder { CanonicalQuery::QueryShapeString encode(const CanonicalQuery& cq) { StringBuilder keyBuilder; encodeKeyForMatch(cq.root(), &keyBuilder); - encodeKeyForSort(cq.getFindCommand().getSort(), &keyBuilder); + encodeKeyForSort(cq.getFindCommandRequest().getSort(), &keyBuilder); encodeKeyForProj(cq.getProj(), &keyBuilder); encodeCollation(cq.getCollator(), &keyBuilder); diff --git a/src/mongo/db/query/canonical_query_encoder_test.cpp b/src/mongo/db/query/canonical_query_encoder_test.cpp index f54f7b7398b..2a5020ff6d0 100644 --- a/src/mongo/db/query/canonical_query_encoder_test.cpp +++ b/src/mongo/db/query/canonical_query_encoder_test.cpp @@ -55,7 +55,7 @@ unique_ptr<CanonicalQuery> canonicalize(BSONObj query, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query.getOwned()); findCommand->setSort(sort.getOwned()); findCommand->setProjection(proj.getOwned()); diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index 2f0f2e02d4a..3d5f27431a9 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -179,7 +179,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson(queryStr)); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), @@ -199,7 +199,7 @@ std::unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson(queryStr)); findCommand->setSort(fromjson(sortStr)); findCommand->setProjection(fromjson(projStr)); @@ -282,11 +282,12 @@ TEST(CanonicalQueryTest, CanonicalizeFromBaseQuery) { BSONObjBuilder expectedFilter; firstClauseExpr->serialize(&expectedFilter); - ASSERT_BSONOBJ_EQ(childCq->getFindCommand().getFilter(), expectedFilter.obj()); + ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getFilter(), expectedFilter.obj()); - ASSERT_BSONOBJ_EQ(childCq->getFindCommand().getProjection(), - baseCq->getFindCommand().getProjection()); - ASSERT_BSONOBJ_EQ(childCq->getFindCommand().getSort(), baseCq->getFindCommand().getSort()); + ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getProjection(), + baseCq->getFindCommandRequest().getProjection()); + ASSERT_BSONOBJ_EQ(childCq->getFindCommandRequest().getSort(), + baseCq->getFindCommandRequest().getSort()); ASSERT_TRUE(childCq->getExplain()); } @@ -294,7 +295,7 @@ TEST(CanonicalQueryTest, CanonicalQueryFromQRWithNoCollation) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); auto cq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); ASSERT_TRUE(cq->getCollator() == nullptr); } @@ -303,7 +304,7 @@ TEST(CanonicalQueryTest, CanonicalQueryFromQRWithCollation) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setCollation(BSON("locale" << "reverse")); auto cq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); @@ -315,7 +316,7 @@ TEST(CanonicalQueryTest, CanonicalQueryFromBaseQueryWithNoCollation) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson("{$or:[{a:1,b:1},{a:1,c:1}]}")); auto baseCq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); MatchExpression* firstClauseExpr = baseCq->root()->getChild(0); @@ -328,7 +329,7 @@ TEST(CanonicalQueryTest, CanonicalQueryFromBaseQueryWithCollation) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson("{$or:[{a:1,b:1},{a:1,c:1}]}")); findCommand->setCollation(BSON("locale" << "reverse")); @@ -344,7 +345,7 @@ TEST(CanonicalQueryTest, SettingCollatorUpdatesCollatorAndMatchExpression) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson("{a: 'foo', b: {$in: ['bar', 'baz']}}")); auto cq = assertGet(CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand))); ASSERT_EQUALS(2U, cq->root()->numChildren()); @@ -398,7 +399,7 @@ void assertValidSortOrder(BSONObj sort, BSONObj filter = BSONObj{}) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(filter); findCommand->setSort(sort); auto statusWithCQ = @@ -424,7 +425,7 @@ void assertInvalidSortOrder(BSONObj sort) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setSort(sort); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand)); ASSERT_NOT_OK(statusWithCQ.getStatus()); diff --git a/src/mongo/db/query/classic_stage_builder.cpp b/src/mongo/db/query/classic_stage_builder.cpp index c26e0777765..bc9a9ab756b 100644 --- a/src/mongo/db/query/classic_stage_builder.cpp +++ b/src/mongo/db/query/classic_stage_builder.cpp @@ -161,30 +161,33 @@ std::unique_ptr<PlanStage> ClassicStageBuilder::build(const QuerySolutionNode* r case STAGE_PROJECTION_DEFAULT: { auto pn = static_cast<const ProjectionNodeDefault*>(root); auto childStage = build(pn->children[0]); - return std::make_unique<ProjectionStageDefault>(_cq.getExpCtx(), - _cq.getFindCommand().getProjection(), - _cq.getProj(), - _ws, - std::move(childStage)); + return std::make_unique<ProjectionStageDefault>( + _cq.getExpCtx(), + _cq.getFindCommandRequest().getProjection(), + _cq.getProj(), + _ws, + std::move(childStage)); } case STAGE_PROJECTION_COVERED: { auto pn = static_cast<const ProjectionNodeCovered*>(root); auto childStage = build(pn->children[0]); - return std::make_unique<ProjectionStageCovered>(_cq.getExpCtxRaw(), - _cq.getFindCommand().getProjection(), - _cq.getProj(), - _ws, - std::move(childStage), - pn->coveredKeyObj); + return std::make_unique<ProjectionStageCovered>( + _cq.getExpCtxRaw(), + _cq.getFindCommandRequest().getProjection(), + _cq.getProj(), + _ws, + std::move(childStage), + pn->coveredKeyObj); } case STAGE_PROJECTION_SIMPLE: { auto pn = static_cast<const ProjectionNodeSimple*>(root); auto childStage = build(pn->children[0]); - return std::make_unique<ProjectionStageSimple>(_cq.getExpCtxRaw(), - _cq.getFindCommand().getProjection(), - _cq.getProj(), - _ws, - std::move(childStage)); + return std::make_unique<ProjectionStageSimple>( + _cq.getExpCtxRaw(), + _cq.getFindCommandRequest().getProjection(), + _cq.getProj(), + _ws, + std::move(childStage)); } case STAGE_LIMIT: { const LimitNode* ln = static_cast<const LimitNode*>(root); diff --git a/src/mongo/db/query/classic_stage_builder_test.cpp b/src/mongo/db/query/classic_stage_builder_test.cpp index b7761ef474f..4e8f87140b7 100644 --- a/src/mongo/db/query/classic_stage_builder_test.cpp +++ b/src/mongo/db/query/classic_stage_builder_test.cpp @@ -68,7 +68,7 @@ public: * Builds a PlanStage using the given WorkingSet and QuerySolution. */ std::unique_ptr<PlanStage> buildPlanStage(std::unique_ptr<QuerySolution> querySolution) { - auto findCommand = std::make_unique<FindCommand>(kNss); + auto findCommand = std::make_unique<FindCommandRequest>(kNss); auto expCtx = make_intrusive<ExpressionContext>(opCtx(), nullptr, kNss); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx(), std::move(findCommand), false, expCtx); diff --git a/src/mongo/db/query/count_command.idl b/src/mongo/db/query/count_command.idl index df55cddcea0..85e6579555d 100644 --- a/src/mongo/db/query/count_command.idl +++ b/src/mongo/db/query/count_command.idl @@ -58,7 +58,7 @@ commands: count: description: "Parser for the 'count' command." command_name: count - cpp_name: CountCommand + cpp_name: CountCommandRequest strict: true namespace: concatenate_with_db_or_uuid api_version: "" diff --git a/src/mongo/db/query/count_command_as_aggregation_command.cpp b/src/mongo/db/query/count_command_as_aggregation_command.cpp index 668baeb7c6b..b719ab77c86 100644 --- a/src/mongo/db/query/count_command_as_aggregation_command.cpp +++ b/src/mongo/db/query/count_command_as_aggregation_command.cpp @@ -47,7 +47,7 @@ const char kMaxTimeMSField[] = "maxTimeMS"; const char kReadConcernField[] = "readConcern"; } // namespace -StatusWith<BSONObj> countCommandAsAggregationCommand(const CountCommand& cmd, +StatusWith<BSONObj> countCommandAsAggregationCommand(const CountCommandRequest& cmd, const NamespaceString& nss) { BSONObjBuilder aggregationBuilder; aggregationBuilder.append("aggregate", nss.coll()); diff --git a/src/mongo/db/query/count_command_as_aggregation_command.h b/src/mongo/db/query/count_command_as_aggregation_command.h index 05583f36e5a..05233278765 100644 --- a/src/mongo/db/query/count_command_as_aggregation_command.h +++ b/src/mongo/db/query/count_command_as_aggregation_command.h @@ -36,9 +36,9 @@ namespace mongo { /** - * Converts this CountCommand into an aggregation. + * Converts this CountCommandRequest into an aggregation. */ -StatusWith<BSONObj> countCommandAsAggregationCommand(const CountCommand& cmd, +StatusWith<BSONObj> countCommandAsAggregationCommand(const CountCommandRequest& cmd, const NamespaceString& nss); } // namespace mongo diff --git a/src/mongo/db/query/count_command_test.cpp b/src/mongo/db/query/count_command_test.cpp index 5792ee2e12b..c0039f46a3d 100644 --- a/src/mongo/db/query/count_command_test.cpp +++ b/src/mongo/db/query/count_command_test.cpp @@ -51,7 +51,7 @@ TEST(CountCommandTest, ParserDealsWithMissingFieldsCorrectly) { << "$db" << "TestDB" << "query" << BSON("a" << BSON("$lte" << 10))); - auto countCmd = CountCommand::parse(ctxt, commandObj); + auto countCmd = CountCommandRequest::parse(ctxt, commandObj); ASSERT_BSONOBJ_EQ(countCmd.getQuery(), fromjson("{ a : { '$lte' : 10 } }")); @@ -81,7 +81,7 @@ TEST(CountCommandTest, ParserParsesCommandWithAllFieldsCorrectly) { << "comment" << "aComment" << "maxTimeMS" << 10000); - const auto countCmd = CountCommand::parse(ctxt, commandObj); + const auto countCmd = CountCommandRequest::parse(ctxt, commandObj); ASSERT_BSONOBJ_EQ(countCmd.getQuery(), fromjson("{ a : { '$gte' : 11 } }")); ASSERT_EQ(countCmd.getLimit().get(), 100); @@ -100,7 +100,7 @@ TEST(CountCommandTest, ParsingNegativeLimitGivesPositiveLimit) { << "$db" << "TestDB" << "limit" << -100); - const auto countCmd = CountCommand::parse(ctxt, commandObj); + const auto countCmd = CountCommandRequest::parse(ctxt, commandObj); ASSERT_EQ(countCmd.getLimit().get(), 100); } @@ -114,42 +114,42 @@ TEST(CountCommandTest, LimitCannotBeMinLong) { << std::numeric_limits<long long>::min()); ASSERT_THROWS_CODE( - CountCommand::parse(ctxt, commandObj), AssertionException, ErrorCodes::BadValue); + CountCommandRequest::parse(ctxt, commandObj), AssertionException, ErrorCodes::BadValue); } TEST(CountCommandTest, FailParseBadSkipValue) { - ASSERT_THROWS_CODE( - CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "$db" - << "TestDB" - << "query" << BSON("a" << BSON("$gte" << 11)) << "skip" << -1000)), - AssertionException, - ErrorCodes::FailedToParse); + ASSERT_THROWS_CODE(CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "$db" + << "TestDB" + << "query" << BSON("a" << BSON("$gte" << 11)) + << "skip" << -1000)), + AssertionException, + ErrorCodes::FailedToParse); } TEST(CountCommandTest, FailParseBadCollationType) { ASSERT_THROWS_CODE( - CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "$db" - << "TestDB" - << "query" << BSON("a" << BSON("$gte" << 11)) << "collation" - << "en_US")), + CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "$db" + << "TestDB" + << "query" << BSON("a" << BSON("$gte" << 11)) << "collation" + << "en_US")), AssertionException, ErrorCodes::TypeMismatch); } TEST(CountCommandTest, FailParseUnknownField) { - ASSERT_THROWS_CODE(CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "$db" - << "TestDB" - << "foo" - << "bar")), + ASSERT_THROWS_CODE(CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "$db" + << "TestDB" + << "foo" + << "bar")), AssertionException, 40415); } @@ -160,7 +160,7 @@ TEST(CountCommandTest, ConvertToAggregationWithHint) { << "$db" << "TestDB" << "hint" << BSON("x" << 1)); - auto countCmd = CountCommand::parse(ctxt, commandObj); + auto countCmd = CountCommandRequest::parse(ctxt, commandObj); auto agg = uassertStatusOK(countCommandAsAggregationCommand(countCmd, testns)); auto cmdObj = OpMsgRequest::fromDBAndBody(testns.db(), agg).body; @@ -182,7 +182,7 @@ TEST(CountCommandTest, ConvertToAggregationWithQueryAndFilterAndLimit) { << "$db" << "TestDB" << "limit" << 200 << "skip" << 300 << "query" << BSON("x" << 7)); - auto countCmd = CountCommand::parse(ctxt, commandObj); + auto countCmd = CountCommandRequest::parse(ctxt, commandObj); auto agg = uassertStatusOK(countCommandAsAggregationCommand(countCmd, testns)); auto cmdObj = OpMsgRequest::fromDBAndBody(testns.db(), agg).body; @@ -204,11 +204,11 @@ TEST(CountCommandTest, ConvertToAggregationWithQueryAndFilterAndLimit) { } TEST(CountCommandTest, ConvertToAggregationWithMaxTimeMS) { - auto countCmd = CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "maxTimeMS" << 100 << "$db" - << "TestDB")); + auto countCmd = CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "maxTimeMS" << 100 << "$db" + << "TestDB")); auto agg = uassertStatusOK(countCommandAsAggregationCommand(countCmd, testns)); auto cmdObj = OpMsgRequest::fromDBAndBody(testns.db(), agg).body; @@ -225,11 +225,11 @@ TEST(CountCommandTest, ConvertToAggregationWithMaxTimeMS) { } TEST(CountCommandTest, ConvertToAggregationWithQueryOptions) { - auto countCmd = CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "$db" - << "TestDB")); + auto countCmd = CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "$db" + << "TestDB")); countCmd.setQueryOptions(BSON("readPreference" << "secondary")); auto agg = uassertStatusOK(countCommandAsAggregationCommand(countCmd, testns)); @@ -250,11 +250,11 @@ TEST(CountCommandTest, ConvertToAggregationWithQueryOptions) { } TEST(CountCommandTest, ConvertToAggregationWithReadConcern) { - auto countCmd = CountCommand::parse(ctxt, - BSON("count" - << "TestColl" - << "$db" - << "TestDB")); + auto countCmd = CountCommandRequest::parse(ctxt, + BSON("count" + << "TestColl" + << "$db" + << "TestDB")); countCmd.setReadConcern(BSON("level" << "linearizable")); auto agg = uassertStatusOK(countCommandAsAggregationCommand(countCmd, testns)); diff --git a/src/mongo/db/query/count_request.h b/src/mongo/db/query/count_request.h index e80ec9a259c..6f118d3144a 100644 --- a/src/mongo/db/query/count_request.h +++ b/src/mongo/db/query/count_request.h @@ -36,19 +36,19 @@ namespace mongo { namespace count_request { /** - * Parses a limit for a CountCommand. If the limit is negative, returns the absolute value. + * Parses a limit for a CountCommandRequest. If the limit is negative, returns the absolute value. * Throws on invalid values. */ long long countParseLimit(const BSONElement& element); /** - * Parses a skip for a CountCommand. Errors if the value passed is negative. + * Parses a skip for a CountCommandRequest. Errors if the value passed is negative. * Throws on invalid values. */ long long countParseSkip(const BSONElement& element); /** - * Parses a maxTimeMS for a CountCommand. Errors if the value passed is negative. + * Parses a maxTimeMS for a CountCommandRequest. Errors if the value passed is negative. * Throws on invalid values. */ long long countParseMaxTime(const BSONElement& element); diff --git a/src/mongo/db/query/distinct_command.idl b/src/mongo/db/query/distinct_command.idl index 8d9750df6fd..668ff5b48d3 100644 --- a/src/mongo/db/query/distinct_command.idl +++ b/src/mongo/db/query/distinct_command.idl @@ -36,7 +36,7 @@ commands: distinct: description: "Parser for the 'distinct' command." command_name: distinct - cpp_name: DistinctCommand + cpp_name: DistinctCommandRequest namespace: concatenate_with_db_or_uuid api_version: "" strict: true diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 355858e2ccf..299d7a97480 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -85,7 +85,7 @@ bool shouldSaveCursor(OperationContext* opCtx, const CollectionPtr& collection, PlanExecutor::ExecState finalState, PlanExecutor* exec) { - const FindCommand& findCommand = exec->getCanonicalQuery()->getFindCommand(); + const FindCommandRequest& findCommand = exec->getCanonicalQuery()->getFindCommandRequest(); if (findCommand.getSingleBatch()) { return false; } @@ -631,7 +631,7 @@ bool runQuery(OperationContext* opCtx, opCtx, nss, secondaryOk)); } - const FindCommand& findCommand = cq->getFindCommand(); + const FindCommandRequest& findCommand = cq->getFindCommandRequest(); // Get the execution plan for the query. constexpr auto verbosity = ExplainOptions::Verbosity::kExecAllPlans; const bool isExplain = cq->getExplain(); diff --git a/src/mongo/db/query/find_command.idl b/src/mongo/db/query/find_command.idl index c6ccaf9661f..af76c9abde8 100644 --- a/src/mongo/db/query/find_command.idl +++ b/src/mongo/db/query/find_command.idl @@ -67,7 +67,7 @@ types: commands: find: - cpp_name: FindCommand + cpp_name: FindCommandRequest command_name: find description: "A struct representing the find command" strict: true diff --git a/src/mongo/db/query/find_common.cpp b/src/mongo/db/query/find_common.cpp index 02191c367eb..4f34e0b1cf4 100644 --- a/src/mongo/db/query/find_common.cpp +++ b/src/mongo/db/query/find_common.cpp @@ -58,7 +58,7 @@ MONGO_FAIL_POINT_DEFINE(failGetMoreAfterCursorCheckout); const OperationContext::Decoration<AwaitDataState> awaitDataState = OperationContext::declareDecoration<AwaitDataState>(); -bool FindCommon::enoughForFirstBatch(const FindCommand& findCommand, long long numDocs) { +bool FindCommon::enoughForFirstBatch(const FindCommandRequest& findCommand, long long numDocs) { auto effectiveBatchSize = findCommand.getBatchSize() ? findCommand.getBatchSize() : findCommand.getNtoreturn(); if (!effectiveBatchSize) { diff --git a/src/mongo/db/query/find_common.h b/src/mongo/db/query/find_common.h index 3fc2b9b0e76..14118cdea03 100644 --- a/src/mongo/db/query/find_common.h +++ b/src/mongo/db/query/find_common.h @@ -54,7 +54,7 @@ extern const OperationContext::Decoration<AwaitDataState> awaitDataState; class BSONObj; class CanonicalQuery; -class FindCommand; +class FindCommandRequest; // Failpoint for making find hang. extern FailPoint waitInFindBeforeMakingBatch; @@ -101,7 +101,7 @@ public: * * If 'qr' does not have a batchSize, the default batchSize is respected. */ - static bool enoughForFirstBatch(const FindCommand& findCommand, long long numDocs); + static bool enoughForFirstBatch(const FindCommandRequest& findCommand, long long numDocs); /** * Returns true if the batchSize for the getMore has been satisfied. diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 87f8b82213a..c4536c8b654 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -149,7 +149,7 @@ bool turnIxscanIntoCount(QuerySolution* soln); * Returns 'true' if 'query' on the given 'collection' can be answered using a special IDHACK plan. */ bool isIdHackEligibleQuery(const CollectionPtr& collection, const CanonicalQuery& query) { - const auto& findCommand = query.getFindCommand(); + const auto& findCommand = query.getFindCommandRequest(); return !findCommand.getShowRecordId() && findCommand.getHint().isEmpty() && findCommand.getMin().isEmpty() && findCommand.getMax().isEmpty() && !findCommand.getSkip() && CanonicalQuery::isSimpleIdQuery(findCommand.getFilter()) && @@ -353,7 +353,7 @@ void fillOutPlannerParams(OperationContext* opCtx, plannerParams->options |= QueryPlannerParams::SPLIT_LIMITED_SORT; if (shouldWaitForOplogVisibility( - opCtx, collection, canonicalQuery->getFindCommand().getTailable())) { + opCtx, collection, canonicalQuery->getFindCommandRequest().getTailable())) { plannerParams->options |= QueryPlannerParams::OPLOG_SCAN_WAIT_FOR_VISIBLE; } } @@ -580,8 +580,8 @@ public: // If the canonical query does not have a user-specified collation and no one has given the // CanonicalQuery a collation already, set it from the collection default. - if (_cq->getFindCommand().getCollation().isEmpty() && _cq->getCollator() == nullptr && - _collection->getDefaultCollator()) { + if (_cq->getFindCommandRequest().getCollation().isEmpty() && + _cq->getCollator() == nullptr && _collection->getDefaultCollator()) { _cq->setCollator(_collection->getDefaultCollator()->clone()); } @@ -600,7 +600,7 @@ public: } // Tailable: If the query requests tailable the collection must be capped. - if (_cq->getFindCommand().getTailable() && !_collection->isCapped()) { + if (_cq->getFindCommandRequest().getTailable() && !_collection->isCapped()) { return Status(ErrorCodes::BadValue, str::stream() << "error processing query: " << _cq->toString() << " tailable cursor requested on non capped collection"); @@ -801,10 +801,10 @@ protected: // Add a SortKeyGeneratorStage if the query requested sortKey metadata. if (_cq->metadataDeps()[DocumentMetadataFields::kSortKey]) { stage = std::make_unique<SortKeyGeneratorStage>( - _cq->getExpCtxRaw(), std::move(stage), _ws, _cq->getFindCommand().getSort()); + _cq->getExpCtxRaw(), std::move(stage), _ws, _cq->getFindCommandRequest().getSort()); } - if (_cq->getFindCommand().getReturnKey()) { + if (_cq->getFindCommandRequest().getReturnKey()) { // If returnKey was requested, add ReturnKeyStage to return only the index keys in // the resulting documents. If a projection was also specified, it will be ignored, // with the exception the $meta sortKey projection, which can be used along with the @@ -822,19 +822,19 @@ protected: // simple inclusion fast path. // Stuff the right data into the params depending on what proj impl we use. if (!cqProjection->isSimple()) { - stage = - std::make_unique<ProjectionStageDefault>(_cq->getExpCtxRaw(), - _cq->getFindCommand().getProjection(), - _cq->getProj(), - _ws, - std::move(stage)); + stage = std::make_unique<ProjectionStageDefault>( + _cq->getExpCtxRaw(), + _cq->getFindCommandRequest().getProjection(), + _cq->getProj(), + _ws, + std::move(stage)); } else { - stage = - std::make_unique<ProjectionStageSimple>(_cq->getExpCtxRaw(), - _cq->getFindCommand().getProjection(), - _cq->getProj(), - _ws, - std::move(stage)); + stage = std::make_unique<ProjectionStageSimple>( + _cq->getExpCtxRaw(), + _cq->getFindCommandRequest().getProjection(), + _cq->getProj(), + _ws, + std::move(stage)); } } @@ -928,7 +928,7 @@ protected: !_cq->metadataDeps()[DocumentMetadataFields::kSortKey]); // For the return key case, we use the common path. - if (_cq->getFindCommand().getReturnKey()) { + if (_cq->getFindCommandRequest().getReturnKey()) { return nullptr; } @@ -1848,7 +1848,7 @@ bool getDistinctNodeIndex(const std::vector<IndexEntry>& indices, StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorCount( const boost::intrusive_ptr<ExpressionContext>& expCtx, const CollectionPtr* coll, - const CountCommand& request, + const CountCommandRequest& request, bool explain, const NamespaceString& nss) { const auto& collection = *coll; @@ -1856,7 +1856,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorCoun OperationContext* opCtx = expCtx->opCtx; std::unique_ptr<WorkingSet> ws = std::make_unique<WorkingSet>(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(request.getQuery()); auto collation = request.getCollation().value_or(BSONObj()); findCommand->setCollation(collation); @@ -2138,7 +2138,7 @@ QueryPlannerParams fillOutPlannerParamsForDistinct(OperationContext* opCtx, const bool mayUnwindArrays = !(plannerOptions & QueryPlannerParams::STRICT_DISTINCT_ONLY); std::unique_ptr<IndexCatalog::IndexIterator> ii = collection->getIndexCatalog()->getIndexIterator(opCtx, false); - auto query = parsedDistinct.getQuery()->getFindCommand().getFilter(); + auto query = parsedDistinct.getQuery()->getFindCommandRequest().getFilter(); while (ii->more()) { const IndexCatalogEntry* ice = ii->next(); const IndexDescriptor* desc = ice->descriptor(); @@ -2183,7 +2183,7 @@ QueryPlannerParams fillOutPlannerParamsForDistinct(OperationContext* opCtx, } const CanonicalQuery* canonicalQuery = parsedDistinct.getQuery(); - const BSONObj& hint = canonicalQuery->getFindCommand().getHint(); + const BSONObj& hint = canonicalQuery->getFindCommandRequest().getHint(); applyIndexFilters(collection, *canonicalQuery, &plannerParams); @@ -2223,7 +2223,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorForS // If there's no query, we can just distinct-scan one of the indices. Not every index in // plannerParams.indices may be suitable. Refer to getDistinctNodeIndex(). size_t distinctNodeIndex = 0; - if (!parsedDistinct->getQuery()->getFindCommand().getFilter().isEmpty() || + if (!parsedDistinct->getQuery()->getFindCommandRequest().getFilter().isEmpty() || parsedDistinct->getQuery()->getSortPattern() || !getDistinctNodeIndex( plannerParams.indices, parsedDistinct->getKey(), collator, &distinctNodeIndex)) { @@ -2344,7 +2344,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorWith size_t plannerOptions) { const auto& collection = *coll; - auto findCommand = std::make_unique<FindCommand>(cq->getFindCommand()); + auto findCommand = std::make_unique<FindCommandRequest>(cq->getFindCommandRequest()); findCommand->setProjection(BSONObj()); const boost::intrusive_ptr<ExpressionContext> expCtx; diff --git a/src/mongo/db/query/get_executor.h b/src/mongo/db/query/get_executor.h index 00ed169447c..92c8cf60f6c 100644 --- a/src/mongo/db/query/get_executor.h +++ b/src/mongo/db/query/get_executor.h @@ -176,9 +176,9 @@ bool turnIxscanIntoDistinctIxscan(QuerySolution* soln, * A $group stage on a single field behaves similarly to a distinct command. If it has no * accumulators or only $first accumulators, the $group command only needs to visit one document for * each distinct value of the grouped-by (_id) field to compute its result. When there is a sort - * order specified in parsedDistinct->getQuery()->getFindCommand().getSort(), the DISTINCT_SCAN will - * follow that sort order, ensuring that it chooses the correct document from each group to compute - * any $first accumulators. + * order specified in parsedDistinct->getQuery()->getFindCommandRequest().getSort(), DISTINCT_SCAN + * will follow that sort order, ensuring that it chooses the correct document from each group to + * compute any $first accumulators. * * Specify the QueryPlannerParams::STRICT_DISTINCT_ONLY flag in the 'params' argument to ensure that * any resulting plan _guarantees_ it will return exactly one document per value of the distinct @@ -216,7 +216,7 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDist StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorCount( const boost::intrusive_ptr<ExpressionContext>& expCtx, const CollectionPtr* collection, - const CountCommand& request, + const CountCommandRequest& request, bool explain, const NamespaceString& nss); diff --git a/src/mongo/db/query/get_executor_test.cpp b/src/mongo/db/query/get_executor_test.cpp index e3ac2411131..a0e86069d28 100644 --- a/src/mongo/db/query/get_executor_test.cpp +++ b/src/mongo/db/query/get_executor_test.cpp @@ -74,7 +74,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson(queryStr)); findCommand->setSort(fromjson(sortStr)); findCommand->setProjection(fromjson(projStr)); diff --git a/src/mongo/db/query/getmore_command.idl b/src/mongo/db/query/getmore_command.idl index 5ee61175118..c68cba81feb 100644 --- a/src/mongo/db/query/getmore_command.idl +++ b/src/mongo/db/query/getmore_command.idl @@ -38,7 +38,7 @@ imports: commands: getMore: - cpp_name: GetMoreCommand + cpp_name: GetMoreCommandRequest command_name: getMore description: "Parser for the getMore command." strict: true diff --git a/src/mongo/db/query/kill_cursors.idl b/src/mongo/db/query/kill_cursors.idl index 2563cd5a5d1..f9baa16bc63 100644 --- a/src/mongo/db/query/kill_cursors.idl +++ b/src/mongo/db/query/kill_cursors.idl @@ -44,7 +44,7 @@ types: deserializer: "mongo::BSONElement::_numberLong" structs: - KillCursorsReply: + KillCursorsCommandReply: description: 'Response from killCursors command' strict: false fields: @@ -66,6 +66,8 @@ commands: killCursors: description: "Kills a specified set of cursors by ID." command_name: killCursors + cpp_name: KillCursorsCommandRequest + reply_type: KillCursorsCommandReply api_version: "1" access_check: complex: @@ -79,8 +81,6 @@ commands: - privilege: resource_pattern: exact_namespace action_type: killAnyCursor - reply_type: KillCursorsReply - cpp_name: KillCursorsRequest strict: true namespace: concatenate_with_db fields: diff --git a/src/mongo/db/query/killcursors_request_test.cpp b/src/mongo/db/query/killcursors_request_test.cpp index 5535fa2c56f..692a76831e6 100644 --- a/src/mongo/db/query/killcursors_request_test.cpp +++ b/src/mongo/db/query/killcursors_request_test.cpp @@ -45,7 +45,7 @@ TEST(KillCursorsRequestTest, parseSuccess) { << "coll" << "cursors" << BSON_ARRAY(CursorId(123) << CursorId(456)) << "$db" << "db"); - KillCursorsRequest request = KillCursorsRequest::parse(ctxt, bsonObj); + KillCursorsCommandRequest request = KillCursorsCommandRequest::parse(ctxt, bsonObj); ASSERT_EQ(request.getNamespace().ns(), "db.coll"); ASSERT_EQ(request.getCursorIds().size(), 2U); ASSERT_EQ(request.getCursorIds()[0], CursorId(123)); @@ -57,7 +57,7 @@ TEST(KillCursorsRequestTest, parseCursorsFieldEmptyArray) { << "coll" << "cursors" << BSONArray() << "$db" << "db"); - KillCursorsRequest request = KillCursorsRequest::parse(ctxt, bsonObj); + KillCursorsCommandRequest request = KillCursorsCommandRequest::parse(ctxt, bsonObj); ASSERT_EQ(request.getCursorIds().size(), 0U); } @@ -66,14 +66,14 @@ TEST(KillCursorsRequestTest, parseFirstFieldNotString) { BSON("killCursors" << 99 << "cursors" << BSON_ARRAY(CursorId(123) << CursorId(456)) << "$db" << "db"); ASSERT_THROWS_CODE( - KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::BadValue); + KillCursorsCommandRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::BadValue); } TEST(KillCursorsRequestTest, parseInvalidNamespace) { auto bsonObj = BSON("killCursors" << "coll" << "cursors" << BSON_ARRAY(CursorId(123) << CursorId(456))); - ASSERT_THROWS_CODE(KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, 40414); + ASSERT_THROWS_CODE(KillCursorsCommandRequest::parse(ctxt, bsonObj), AssertionException, 40414); } TEST(KillCursorsRequestTest, parseCursorsFieldMissing) { @@ -81,7 +81,7 @@ TEST(KillCursorsRequestTest, parseCursorsFieldMissing) { << "coll" << "$db" << "db"); - ASSERT_THROWS_CODE(KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, 40414); + ASSERT_THROWS_CODE(KillCursorsCommandRequest::parse(ctxt, bsonObj), AssertionException, 40414); } TEST(KillCursorsRequestTest, parseCursorFieldNotArray) { @@ -89,8 +89,9 @@ TEST(KillCursorsRequestTest, parseCursorFieldNotArray) { << "coll" << "cursors" << CursorId(123) << "$db" << "db"); - ASSERT_THROWS_CODE( - KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::TypeMismatch); + ASSERT_THROWS_CODE(KillCursorsCommandRequest::parse(ctxt, bsonObj), + AssertionException, + ErrorCodes::TypeMismatch); } TEST(KillCursorsRequestTest, parseCursorFieldArrayWithNonCursorIdValue) { @@ -98,14 +99,15 @@ TEST(KillCursorsRequestTest, parseCursorFieldArrayWithNonCursorIdValue) { << "coll" << "cursors" << BSON_ARRAY(CursorId(123) << "String value") << "$db" << "db"); - ASSERT_THROWS_CODE( - KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::TypeMismatch); + ASSERT_THROWS_CODE(KillCursorsCommandRequest::parse(ctxt, bsonObj), + AssertionException, + ErrorCodes::TypeMismatch); } TEST(KillCursorsRequestTest, toBSON) { const NamespaceString nss("db.coll"); std::vector<CursorId> cursorIds = {CursorId(123)}; - KillCursorsRequest request(nss, cursorIds); + KillCursorsCommandRequest request(nss, cursorIds); BSONObj requestObj = request.toBSON(BSONObj{}); BSONObj expectedObj = BSON("killCursors" << "coll" diff --git a/src/mongo/db/query/parsed_distinct.cpp b/src/mongo/db/query/parsed_distinct.cpp index e797f9650c2..59c15f39f7b 100644 --- a/src/mongo/db/query/parsed_distinct.cpp +++ b/src/mongo/db/query/parsed_distinct.cpp @@ -171,7 +171,7 @@ StatusWith<BSONObj> ParsedDistinct::asAggregationCommand() const { BSONObjBuilder aggregationBuilder; invariant(_query); - const FindCommand& findCommand = _query->getFindCommand(); + const FindCommandRequest& findCommand = _query->getFindCommandRequest(); aggregationBuilder.append( "aggregate", findCommand.getNamespaceOrUUID().nss().value_or(NamespaceString()).coll()); @@ -257,14 +257,14 @@ StatusWith<ParsedDistinct> ParsedDistinct::parse(OperationContext* opCtx, const CollatorInterface* defaultCollator) { IDLParserErrorContext ctx("distinct"); - DistinctCommand parsedDistinct(nss); + DistinctCommandRequest parsedDistinct(nss); try { - parsedDistinct = DistinctCommand::parse(ctx, cmdObj); + parsedDistinct = DistinctCommandRequest::parse(ctx, cmdObj); } catch (...) { return exceptionToStatus(); } - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); if (parsedDistinct.getKey().find('\0') != std::string::npos) { return Status(ErrorCodes::Error(31032), "Key field cannot contain an embedded null byte"); @@ -325,7 +325,7 @@ StatusWith<ParsedDistinct> ParsedDistinct::parse(OperationContext* opCtx, return cq.getStatus(); } - if (cq.getValue()->getFindCommand().getCollation().isEmpty() && defaultCollator) { + if (cq.getValue()->getFindCommandRequest().getCollation().isEmpty() && defaultCollator) { cq.getValue()->setCollator(defaultCollator->clone()); } diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp index 6a78e017dee..b1bdb1f1ef5 100644 --- a/src/mongo/db/query/plan_cache.cpp +++ b/src/mongo/db/query/plan_cache.cpp @@ -121,7 +121,7 @@ StringBuilder& operator<<(StringBuilder& builder, const PlanCacheKey& key) { // bool PlanCache::shouldCacheQuery(const CanonicalQuery& query) { - const FindCommand& findCommand = query.getFindCommand(); + const FindCommandRequest& findCommand = query.getFindCommandRequest(); const MatchExpression* expr = query.root(); // Collection scan @@ -157,7 +157,7 @@ bool PlanCache::shouldCacheQuery(const CanonicalQuery& query) { } // Tailable cursors won't get cached, just turn into collscans. - if (query.getFindCommand().getTailable()) { + if (query.getFindCommandRequest().getTailable()) { return false; } @@ -204,7 +204,7 @@ std::unique_ptr<PlanCacheEntry> PlanCacheEntry::create( if (includeDebugInfo) { // Strip projections on $-prefixed fields, as these are added by internal callers of the // system and are not considered part of the user projection. - const FindCommand& findCommand = query.getFindCommand(); + const FindCommandRequest& findCommand = query.getFindCommandRequest(); BSONObjBuilder projBuilder; for (auto elem : findCommand.getProjection()) { if (elem.fieldName()[0] == '$') { diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp index 6d2bb24bd0a..d719c911d0e 100644 --- a/src/mongo/db/query/plan_cache_test.cpp +++ b/src/mongo/db/query/plan_cache_test.cpp @@ -74,7 +74,7 @@ unique_ptr<CanonicalQuery> canonicalize(const BSONObj& queryObj) { QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(queryObj); const boost::intrusive_ptr<ExpressionContext> expCtx; auto statusWithCQ = @@ -100,7 +100,7 @@ unique_ptr<CanonicalQuery> canonicalize(BSONObj query, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query); findCommand->setSort(sort); findCommand->setProjection(proj); @@ -136,7 +136,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson(queryStr)); findCommand->setSort(fromjson(sortStr)); findCommand->setProjection(fromjson(projStr)); @@ -173,7 +173,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(fromjson(queryStr)); findCommand->setSort(fromjson(sortStr)); findCommand->setProjection(fromjson(projStr)); @@ -1017,7 +1017,7 @@ protected: // Clean up any previous state from a call to runQueryFull or runQueryAsCommand. solns.clear(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query); findCommand->setSort(sort); findCommand->setProjection(proj); @@ -1052,7 +1052,7 @@ protected: solns.clear(); const bool isExplain = false; - std::unique_ptr<FindCommand> findCommand( + std::unique_ptr<FindCommandRequest> findCommand( query_request_helper::makeFromFindCommandForTests(cmdObj)); const boost::intrusive_ptr<ExpressionContext> expCtx; @@ -1125,7 +1125,7 @@ protected: QueryTestServiceContext serviceContext; auto opCtx = serviceContext.makeOperationContext(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query); findCommand->setSort(sort); findCommand->setProjection(proj); diff --git a/src/mongo/db/query/plan_executor_impl.cpp b/src/mongo/db/query/plan_executor_impl.cpp index 3d89b63a4ce..7c5f5dd4871 100644 --- a/src/mongo/db/query/plan_executor_impl.cpp +++ b/src/mongo/db/query/plan_executor_impl.cpp @@ -145,7 +145,8 @@ PlanExecutorImpl::PlanExecutorImpl(OperationContext* opCtx, _nss = collection->ns(); } else { invariant(_cq); - _nss = _cq->getFindCommand().getNamespaceOrUUID().nss().value_or(NamespaceString()); + _nss = + _cq->getFindCommandRequest().getNamespaceOrUUID().nss().value_or(NamespaceString()); } } diff --git a/src/mongo/db/query/plan_insert_listener.cpp b/src/mongo/db/query/plan_insert_listener.cpp index 8591004401f..0d86c76c9e7 100644 --- a/src/mongo/db/query/plan_insert_listener.cpp +++ b/src/mongo/db/query/plan_insert_listener.cpp @@ -45,8 +45,9 @@ MONGO_FAIL_POINT_DEFINE(planExecutorHangWhileYieldedInWaitForInserts); } bool shouldListenForInserts(OperationContext* opCtx, CanonicalQuery* cq) { - return cq && cq->getFindCommand().getTailable() && cq->getFindCommand().getAwaitData() && - awaitDataState(opCtx).shouldWaitForInserts && opCtx->checkForInterruptNoAssert().isOK() && + return cq && cq->getFindCommandRequest().getTailable() && + cq->getFindCommandRequest().getAwaitData() && awaitDataState(opCtx).shouldWaitForInserts && + opCtx->checkForInterruptNoAssert().isOK() && awaitDataState(opCtx).waitForInsertsDeadline > opCtx->getServiceContext()->getPreciseClockSource()->now(); } diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp index fb20b0c6939..9e7855a44c7 100644 --- a/src/mongo/db/query/planner_access.cpp +++ b/src/mongo/db/query/planner_access.cpp @@ -224,7 +224,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::makeCollectionScan( params.options & QueryPlannerParams::OPLOG_SCAN_WAIT_FOR_VISIBLE; // If the hint is {$natural: +-1} this changes the direction of the collection scan. - const BSONObj& hint = query.getFindCommand().getHint(); + const BSONObj& hint = query.getFindCommandRequest().getHint(); if (!hint.isEmpty()) { BSONElement natural = hint[query_request_helper::kNaturalSortField]; if (natural) { @@ -235,13 +235,13 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::makeCollectionScan( // If the client requested a resume token and we are scanning the oplog, prepare // the collection scan to return timestamp-based tokens. Otherwise, we should // return generic RecordId-based tokens. - if (query.getFindCommand().getRequestResumeToken()) { + if (query.getFindCommandRequest().getRequestResumeToken()) { csn->shouldTrackLatestOplogTimestamp = query.nss().isOplog(); csn->requestResumeToken = !query.nss().isOplog(); } // Extract and assign the RecordId from the 'resumeAfter' token, if present. - const BSONObj& resumeAfterObj = query.getFindCommand().getResumeAfter(); + const BSONObj& resumeAfterObj = query.getFindCommandRequest().getResumeAfter(); if (!resumeAfterObj.isEmpty()) { BSONElement recordIdElem = resumeAfterObj["$recordId"]; switch (recordIdElem.type()) { @@ -1304,7 +1304,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedAnd( for (size_t i = 0; i < andResult->children.size(); ++i) { andResult->children[i]->computeProperties(); if (andResult->children[i]->providedSorts().contains( - query.getFindCommand().getSort())) { + query.getFindCommandRequest().getSort())) { std::swap(andResult->children[i], andResult->children.back()); break; } @@ -1403,7 +1403,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedOr( // If all ixscanNodes can provide the sort, shouldReverseScan is populated with which // scans to reverse. shouldReverseScan = - canProvideSortWithMergeSort(ixscanNodes, query.getFindCommand().getSort()); + canProvideSortWithMergeSort(ixscanNodes, query.getFindCommandRequest().getSort()); } if (!shouldReverseScan.empty()) { @@ -1417,7 +1417,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedOr( } auto msn = std::make_unique<MergeSortNode>(); - msn->sort = query.getFindCommand().getSort(); + msn->sort = query.getFindCommandRequest().getSort(); msn->addChildren(std::move(ixscanNodes)); orResult = std::move(msn); } else { diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp index a0de5bd01bd..71892e12b51 100644 --- a/src/mongo/db/query/planner_analysis.cpp +++ b/src/mongo/db/query/planner_analysis.cpp @@ -372,7 +372,7 @@ std::unique_ptr<QuerySolutionNode> addSortKeyGeneratorStageIfNeeded( const CanonicalQuery& query, bool hasSortStage, std::unique_ptr<QuerySolutionNode> solnRoot) { if (!hasSortStage && query.metadataDeps()[DocumentMetadataFields::kSortKey]) { auto keyGenNode = std::make_unique<SortKeyGeneratorNode>(); - keyGenNode->sortSpec = query.getFindCommand().getSort(); + keyGenNode->sortSpec = query.getFindCommandRequest().getSort(); keyGenNode->children.push_back(solnRoot.release()); return keyGenNode; } @@ -539,8 +539,8 @@ std::unique_ptr<QuerySolutionNode> tryPushdownProjectBeneathSort( bool canUseSimpleSort(const QuerySolutionNode& solnRoot, const CanonicalQuery& cq, const QueryPlannerParams& plannerParams) { - const bool splitLimitedSortEligible = cq.getFindCommand().getNtoreturn() && - !cq.getFindCommand().getSingleBatch() && + const bool splitLimitedSortEligible = cq.getFindCommandRequest().getNtoreturn() && + !cq.getFindCommandRequest().getSingleBatch() && plannerParams.options & QueryPlannerParams::SPLIT_LIMITED_SORT; // The simple sort stage discards any metadata other than sort key metadata. It can only be used @@ -622,7 +622,7 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query, // Find explodable nodes in the subtree rooted at 'toReplace'. getExplodableNodes(toReplace, &explodableNodes); - const BSONObj& desiredSort = query.getFindCommand().getSort(); + const BSONObj& desiredSort = query.getFindCommandRequest().getSort(); // How many scan leaves will result from our expansion? size_t totalNumScans = 0; @@ -764,7 +764,7 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query bool* blockingSortOut) { *blockingSortOut = false; - const FindCommand& findCommand = query.getFindCommand(); + const FindCommandRequest& findCommand = query.getFindCommandRequest(); const BSONObj& sortObj = findCommand.getSort(); if (sortObj.isEmpty()) { @@ -974,7 +974,7 @@ std::unique_ptr<QuerySolution> QueryPlannerAnalysis::analyzeDataAccess( bool hasAndHashStage = solnRoot->hasNode(STAGE_AND_HASH); soln->hasBlockingStage = hasSortStage || hasAndHashStage; - const FindCommand& findCommand = query.getFindCommand(); + const FindCommandRequest& findCommand = query.getFindCommandRequest(); if (findCommand.getSkip()) { auto skip = std::make_unique<SkipNode>(); diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp index fb902758eb5..ab803e03254 100644 --- a/src/mongo/db/query/query_planner.cpp +++ b/src/mongo/db/query/query_planner.cpp @@ -341,7 +341,8 @@ std::unique_ptr<QuerySolution> buildWholeIXSoln(const IndexEntry& index, } bool providesSort(const CanonicalQuery& query, const BSONObj& kp) { - return query.getFindCommand().getSort().isPrefixOf(kp, SimpleBSONElementComparator::kInstance); + return query.getFindCommandRequest().getSort().isPrefixOf( + kp, SimpleBSONElementComparator::kInstance); } StatusWith<std::unique_ptr<PlanCacheIndexTree>> QueryPlanner::cacheDataFromTaggedTree( @@ -609,7 +610,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( } const bool canTableScan = !(params.options & QueryPlannerParams::NO_TABLE_SCAN); - const bool isTailable = query.getFindCommand().getTailable(); + const bool isTailable = query.getFindCommandRequest().getTailable(); // If the query requests a tailable cursor, the only solution is a collscan + filter with // tailable set on the collscan. @@ -632,16 +633,16 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // The hint can be {$natural: +/-1}. If this happens, output a collscan. We expect any $natural // sort to have been normalized to a $natural hint upstream. - if (!query.getFindCommand().getHint().isEmpty()) { - const BSONObj& hintObj = query.getFindCommand().getHint(); + if (!query.getFindCommandRequest().getHint().isEmpty()) { + const BSONObj& hintObj = query.getFindCommandRequest().getHint(); if (hintObj[query_request_helper::kNaturalSortField]) { LOGV2_DEBUG(20969, 5, "Forcing a table scan due to hinted $natural"); if (!canTableScan) { return Status(ErrorCodes::NoQueryExecutionPlans, "hint $natural is not allowed, because 'notablescan' is enabled"); } - if (!query.getFindCommand().getMin().isEmpty() || - !query.getFindCommand().getMax().isEmpty()) { + if (!query.getFindCommandRequest().getMin().isEmpty() || + !query.getFindCommandRequest().getMax().isEmpty()) { return Status(ErrorCodes::NoQueryExecutionPlans, "min and max are incompatible with $natural"); } @@ -661,7 +662,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // requested in the query. BSONObj hintedIndex; if (!params.indexFiltersApplied) { - hintedIndex = query.getFindCommand().getHint(); + hintedIndex = query.getFindCommandRequest().getHint(); } // Either the list of indices passed in by the caller, or the list of indices filtered according @@ -717,15 +718,16 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // Deal with the .min() and .max() query options. If either exist we can only use an index // that matches the object inside. - if (!query.getFindCommand().getMin().isEmpty() || !query.getFindCommand().getMax().isEmpty()) { + if (!query.getFindCommandRequest().getMin().isEmpty() || + !query.getFindCommandRequest().getMax().isEmpty()) { if (!hintedIndexEntry) { return Status(ErrorCodes::Error(51173), "When using min()/max() a hint of which index to use must be provided"); } - BSONObj minObj = query.getFindCommand().getMin(); - BSONObj maxObj = query.getFindCommand().getMax(); + BSONObj minObj = query.getFindCommandRequest().getMin(); + BSONObj maxObj = query.getFindCommandRequest().getMax(); if ((!minObj.isEmpty() && !indexCompatibleMaxMin(minObj, query.getCollator(), *hintedIndexEntry)) || @@ -787,7 +789,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan( // // TEXT and GEO_NEAR are special because they require the use of a text/geo index in order // to be evaluated correctly. Stripping these "mandatory assignments" is therefore invalid. - if (query.getFindCommand().getProjection().isEmpty() && + if (query.getFindCommandRequest().getProjection().isEmpty() && !QueryPlannerCommon::hasNode(query.root(), MatchExpression::GEO_NEAR) && !QueryPlannerCommon::hasNode(query.root(), MatchExpression::TEXT)) { QueryPlannerIXSelect::stripUnneededAssignments(query.root(), relevantIndices); diff --git a/src/mongo/db/query/query_planner_options_test.cpp b/src/mongo/db/query/query_planner_options_test.cpp index 3ff3392fcae..c83f920ada9 100644 --- a/src/mongo/db/query/query_planner_options_test.cpp +++ b/src/mongo/db/query/query_planner_options_test.cpp @@ -828,7 +828,7 @@ TEST_F(QueryPlannerTest, CacheDataFromTaggedTreeFailsOnBadInput) { // No relevant index matching the index tag. relevantIndices.push_back(buildSimpleIndexEntry(BSON("a" << 1), "a_1")); - auto findCommand = std::make_unique<FindCommand>(NamespaceString("test.collection")); + auto findCommand = std::make_unique<FindCommandRequest>(NamespaceString("test.collection")); findCommand->setFilter(BSON("a" << 3)); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand)); ASSERT_OK(statusWithCQ.getStatus()); @@ -842,7 +842,7 @@ TEST_F(QueryPlannerTest, CacheDataFromTaggedTreeFailsOnBadInput) { TEST_F(QueryPlannerTest, TagAccordingToCacheFailsOnBadInput) { const NamespaceString nss("test.collection"); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(BSON("a" << 3)); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(findCommand)); ASSERT_OK(statusWithCQ.getStatus()); @@ -871,7 +871,7 @@ TEST_F(QueryPlannerTest, TagAccordingToCacheFailsOnBadInput) { ASSERT_OK(s); // Regenerate canonical query in order to clear tags. - auto newQR = std::make_unique<FindCommand>(nss); + auto newQR = std::make_unique<FindCommandRequest>(nss); newQR->setFilter(BSON("a" << 3)); statusWithCQ = CanonicalQuery::canonicalize(opCtx.get(), std::move(newQR)); ASSERT_OK(statusWithCQ.getStatus()); diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp index 4abe9524abf..b9e25876ad6 100644 --- a/src/mongo/db/query/query_planner_test_fixture.cpp +++ b/src/mongo/db/query/query_planner_test_fixture.cpp @@ -326,7 +326,7 @@ void QueryPlannerTest::runQueryFull(const BSONObj& query, const BSONObj& maxObj) { clearState(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query); findCommand->setSort(sort); findCommand->setProjection(proj); @@ -407,7 +407,7 @@ void QueryPlannerTest::runInvalidQueryFull(const BSONObj& query, const BSONObj& maxObj) { clearState(); - auto findCommand = std::make_unique<FindCommand>(nss); + auto findCommand = std::make_unique<FindCommandRequest>(nss); findCommand->setFilter(query); findCommand->setSort(sort); findCommand->setProjection(proj); @@ -450,7 +450,7 @@ void QueryPlannerTest::runQueryAsCommand(const BSONObj& cmdObj) { // If there is no '$db', append it. auto cmd = OpMsgRequest::fromDBAndBody(nss.db(), cmdObj).body; - std::unique_ptr<FindCommand> findCommand( + std::unique_ptr<FindCommandRequest> findCommand( query_request_helper::makeFromFindCommandForTests(cmd, nss)); auto statusWithCQ = @@ -477,7 +477,7 @@ void QueryPlannerTest::runInvalidQueryAsCommand(const BSONObj& cmdObj) { // If there is no '$db', append it. auto cmd = OpMsgRequest::fromDBAndBody(nss.db(), cmdObj).body; - std::unique_ptr<FindCommand> findCommand( + std::unique_ptr<FindCommandRequest> findCommand( query_request_helper::makeFromFindCommandForTests(cmd, nss)); auto statusWithCQ = diff --git a/src/mongo/db/query/query_request_helper.cpp b/src/mongo/db/query/query_request_helper.cpp index 90b98665c75..a7637728603 100644 --- a/src/mongo/db/query/query_request_helper.cpp +++ b/src/mongo/db/query/query_request_helper.cpp @@ -49,7 +49,7 @@ namespace { * * This contains flags such as tailable, exhaust, and noCursorTimeout. */ -void initFromInt(int options, FindCommand* findCommand) { +void initFromInt(int options, FindCommandRequest* findCommand) { bool tailable = (options & QueryOption_CursorTailable) != 0; bool awaitData = (options & QueryOption_AwaitData) != 0; if (awaitData) { @@ -70,7 +70,7 @@ void initFromInt(int options, FindCommand* findCommand) { /** * Updates the projection object with a $meta projection for the showRecordId option. */ -void addShowRecordIdMetaProj(FindCommand* findCommand) { +void addShowRecordIdMetaProj(FindCommandRequest* findCommand) { if (findCommand->getProjection()["$recordId"]) { // There's already some projection on $recordId. Don't overwrite it. return; @@ -86,13 +86,13 @@ void addShowRecordIdMetaProj(FindCommand* findCommand) { /** * Add the meta projection to this object if needed. */ -void addMetaProjection(FindCommand* findCommand) { +void addMetaProjection(FindCommandRequest* findCommand) { if (findCommand->getShowRecordId()) { addShowRecordIdMetaProj(findCommand); } } -Status initFullQuery(const BSONObj& top, FindCommand* findCommand, bool* explain) { +Status initFullQuery(const BSONObj& top, FindCommandRequest* findCommand, bool* explain) { BSONObjIterator i(top); while (i.more()) { @@ -185,14 +185,14 @@ Status initFullQuery(const BSONObj& top, FindCommand* findCommand, bool* explain return Status::OK(); } -Status initFindCommand(int ntoskip, - int ntoreturn, - int queryOptions, - const BSONObj& queryObj, - const BSONObj& proj, - bool fromQueryMessage, - FindCommand* findCommand, - bool* explain) { +Status initFindCommandRequest(int ntoskip, + int ntoreturn, + int queryOptions, + const BSONObj& queryObj, + const BSONObj& proj, + bool fromQueryMessage, + FindCommandRequest* findCommand, + bool* explain) { if (!proj.isEmpty()) { findCommand->setProjection(proj.getOwned()); } @@ -244,7 +244,7 @@ Status initFindCommand(int ntoskip, findCommand->setFilter(queryObj.getOwned()); } - return validateFindCommand(*findCommand); + return validateFindCommandRequest(*findCommand); } } // namespace @@ -265,7 +265,7 @@ Status validateGetMoreCollectionName(StringData collectionName) { return Status::OK(); } -Status validateFindCommand(const FindCommand& findCommand) { +Status validateFindCommandRequest(const FindCommandRequest& findCommand) { // Min and Max objects must have the same fields. if (!findCommand.getMin().isEmpty() && !findCommand.getMax().isEmpty()) { if (!findCommand.getMin().isFieldNamePrefixOf(findCommand.getMax()) || @@ -327,7 +327,7 @@ Status validateFindCommand(const FindCommand& findCommand) { return Status::OK(); } -void refreshNSS(const NamespaceString& nss, FindCommand* findCommand) { +void refreshNSS(const NamespaceString& nss, FindCommandRequest* findCommand) { if (findCommand->getNamespaceOrUUID().uuid()) { auto& nssOrUUID = findCommand->getNamespaceOrUUID(); nssOrUUID.setNss(nss); @@ -335,12 +335,12 @@ void refreshNSS(const NamespaceString& nss, FindCommand* findCommand) { invariant(findCommand->getNamespaceOrUUID().nss()); } -std::unique_ptr<FindCommand> makeFromFindCommand(const BSONObj& cmdObj, - boost::optional<NamespaceString> nss, - bool apiStrict) { +std::unique_ptr<FindCommandRequest> makeFromFindCommand(const BSONObj& cmdObj, + boost::optional<NamespaceString> nss, + bool apiStrict) { - auto findCommand = std::make_unique<FindCommand>( - FindCommand::parse(IDLParserErrorContext("FindCommand", apiStrict), cmdObj)); + auto findCommand = std::make_unique<FindCommandRequest>( + FindCommandRequest::parse(IDLParserErrorContext("FindCommandRequest", apiStrict), cmdObj)); // If there is an explicit namespace specified overwite it. if (nss) { @@ -356,14 +356,13 @@ std::unique_ptr<FindCommand> makeFromFindCommand(const BSONObj& cmdObj, if (findCommand->getLimit() && *findCommand->getLimit() == 0) { findCommand->setLimit(boost::none); } - uassertStatusOK(validateFindCommand(*findCommand)); + uassertStatusOK(validateFindCommandRequest(*findCommand)); return findCommand; } -std::unique_ptr<FindCommand> makeFromFindCommandForTests(const BSONObj& cmdObj, - boost::optional<NamespaceString> nss, - bool apiStrict) { +std::unique_ptr<FindCommandRequest> makeFromFindCommandForTests( + const BSONObj& cmdObj, boost::optional<NamespaceString> nss, bool apiStrict) { return makeFromFindCommand(cmdObj, nss, apiStrict); } @@ -395,7 +394,7 @@ bool isTextScoreMeta(BSONElement elt) { return true; } -void setTailableMode(TailableModeEnum tailableMode, FindCommand* findCommand) { +void setTailableMode(TailableModeEnum tailableMode, FindCommandRequest* findCommand) { if (tailableMode == TailableModeEnum::kTailableAndAwaitData) { findCommand->setAwaitData(true); findCommand->setTailable(true); @@ -404,7 +403,7 @@ void setTailableMode(TailableModeEnum tailableMode, FindCommand* findCommand) { } } -TailableModeEnum getTailableMode(const FindCommand& findCommand) { +TailableModeEnum getTailableMode(const FindCommandRequest& findCommand) { return uassertStatusOK( tailableModeFromBools(findCommand.getTailable(), findCommand.getAwaitData())); } @@ -419,18 +418,18 @@ void validateCursorResponse(const BSONObj& outputAsBson) { // Old QueryRequest parsing code: SOON TO BE DEPRECATED. // -StatusWith<std::unique_ptr<FindCommand>> fromLegacyQueryMessage(const QueryMessage& qm, - bool* explain) { - auto findCommand = std::make_unique<FindCommand>(NamespaceString(qm.ns)); - - Status status = initFindCommand(qm.ntoskip, - qm.ntoreturn, - qm.queryOptions, - qm.query, - qm.fields, - true, - findCommand.get(), - explain); +StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQueryMessage(const QueryMessage& qm, + bool* explain) { + auto findCommand = std::make_unique<FindCommandRequest>(NamespaceString(qm.ns)); + + Status status = initFindCommandRequest(qm.ntoskip, + qm.ntoreturn, + qm.queryOptions, + qm.query, + qm.fields, + true, + findCommand.get(), + explain); if (!status.isOK()) { return status; } @@ -438,16 +437,16 @@ StatusWith<std::unique_ptr<FindCommand>> fromLegacyQueryMessage(const QueryMessa return std::move(findCommand); } -StatusWith<std::unique_ptr<FindCommand>> fromLegacyQuery(NamespaceStringOrUUID nssOrUuid, - const BSONObj& queryObj, - const BSONObj& proj, - int ntoskip, - int ntoreturn, - int queryOptions, - bool* explain) { - auto findCommand = std::make_unique<FindCommand>(std::move(nssOrUuid)); +StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQuery(NamespaceStringOrUUID nssOrUuid, + const BSONObj& queryObj, + const BSONObj& proj, + int ntoskip, + int ntoreturn, + int queryOptions, + bool* explain) { + auto findCommand = std::make_unique<FindCommandRequest>(std::move(nssOrUuid)); - Status status = initFindCommand( + Status status = initFindCommandRequest( ntoskip, ntoreturn, queryOptions, queryObj, proj, true, findCommand.get(), explain); if (!status.isOK()) { return status; @@ -456,28 +455,28 @@ StatusWith<std::unique_ptr<FindCommand>> fromLegacyQuery(NamespaceStringOrUUID n return std::move(findCommand); } -StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand) { +StatusWith<BSONObj> asAggregationCommand(const FindCommandRequest& findCommand) { BSONObjBuilder aggregationBuilder; // First, check if this query has options that are not supported in aggregation. if (!findCommand.getMin().isEmpty()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kMinFieldName + str::stream() << "Option " << FindCommandRequest::kMinFieldName << " not supported in aggregation."}; } if (!findCommand.getMax().isEmpty()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kMaxFieldName + str::stream() << "Option " << FindCommandRequest::kMaxFieldName << " not supported in aggregation."}; } if (findCommand.getReturnKey()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kReturnKeyFieldName + str::stream() << "Option " << FindCommandRequest::kReturnKeyFieldName << " not supported in aggregation."}; } if (findCommand.getShowRecordId()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kShowRecordIdFieldName + str::stream() << "Option " << FindCommandRequest::kShowRecordIdFieldName << " not supported in aggregation."}; } if (findCommand.getTailable()) { @@ -486,12 +485,12 @@ StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand) { } if (findCommand.getNoCursorTimeout()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kNoCursorTimeoutFieldName + str::stream() << "Option " << FindCommandRequest::kNoCursorTimeoutFieldName << " not supported in aggregation."}; } if (findCommand.getAllowPartialResults()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kAllowPartialResultsFieldName + str::stream() << "Option " << FindCommandRequest::kAllowPartialResultsFieldName << " not supported in aggregation."}; } if (findCommand.getNtoreturn()) { @@ -507,30 +506,31 @@ StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand) { // special exception if 'limit' is set to 1. if (findCommand.getSingleBatch() && findCommand.getLimit().value_or(0) != 1LL) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kSingleBatchFieldName + str::stream() << "Option " << FindCommandRequest::kSingleBatchFieldName << " not supported in aggregation."}; } if (findCommand.getReadOnce()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kReadOnceFieldName + str::stream() << "Option " << FindCommandRequest::kReadOnceFieldName << " not supported in aggregation."}; } if (findCommand.getAllowSpeculativeMajorityRead()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kAllowSpeculativeMajorityReadFieldName + str::stream() << "Option " + << FindCommandRequest::kAllowSpeculativeMajorityReadFieldName << " not supported in aggregation."}; } if (findCommand.getRequestResumeToken()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kRequestResumeTokenFieldName + str::stream() << "Option " << FindCommandRequest::kRequestResumeTokenFieldName << " not supported in aggregation."}; } if (!findCommand.getResumeAfter().isEmpty()) { return {ErrorCodes::InvalidPipelineOperator, - str::stream() << "Option " << FindCommand::kResumeAfterFieldName + str::stream() << "Option " << FindCommandRequest::kResumeAfterFieldName << " not supported in aggregation."}; } @@ -572,7 +572,8 @@ StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand) { // The aggregation 'cursor' option is always set, regardless of the presence of batchSize. BSONObjBuilder batchSizeBuilder(aggregationBuilder.subobjStart("cursor")); if (findCommand.getBatchSize()) { - batchSizeBuilder.append(FindCommand::kBatchSizeFieldName, *findCommand.getBatchSize()); + batchSizeBuilder.append(FindCommandRequest::kBatchSizeFieldName, + *findCommand.getBatchSize()); } batchSizeBuilder.doneFast(); @@ -583,27 +584,27 @@ StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand) { aggregationBuilder.append(cmdOptionMaxTimeMS, maxTimeMS); } if (!findCommand.getHint().isEmpty()) { - aggregationBuilder.append(FindCommand::kHintFieldName, findCommand.getHint()); + aggregationBuilder.append(FindCommandRequest::kHintFieldName, findCommand.getHint()); } if (findCommand.getReadConcern()) { aggregationBuilder.append("readConcern", *findCommand.getReadConcern()); } if (!findCommand.getUnwrappedReadPref().isEmpty()) { - aggregationBuilder.append(FindCommand::kUnwrappedReadPrefFieldName, + aggregationBuilder.append(FindCommandRequest::kUnwrappedReadPrefFieldName, findCommand.getUnwrappedReadPref()); } if (findCommand.getAllowDiskUse()) { - aggregationBuilder.append(FindCommand::kAllowDiskUseFieldName, + aggregationBuilder.append(FindCommandRequest::kAllowDiskUseFieldName, static_cast<bool>(findCommand.getAllowDiskUse())); } if (findCommand.getLegacyRuntimeConstants()) { BSONObjBuilder rtcBuilder( - aggregationBuilder.subobjStart(FindCommand::kLegacyRuntimeConstantsFieldName)); + aggregationBuilder.subobjStart(FindCommandRequest::kLegacyRuntimeConstantsFieldName)); findCommand.getLegacyRuntimeConstants()->serialize(&rtcBuilder); rtcBuilder.doneFast(); } if (findCommand.getLet()) { - aggregationBuilder.append(FindCommand::kLetFieldName, *findCommand.getLet()); + aggregationBuilder.append(FindCommandRequest::kLetFieldName, *findCommand.getLet()); } return StatusWith<BSONObj>(aggregationBuilder.obj()); } diff --git a/src/mongo/db/query/query_request_helper.h b/src/mongo/db/query/query_request_helper.h index 974269d16c5..2617c9231d4 100644 --- a/src/mongo/db/query/query_request_helper.h +++ b/src/mongo/db/query/query_request_helper.h @@ -68,36 +68,36 @@ Status validateGetMoreCollectionName(StringData collectionName); * value) or if there is a bad combination of options (e.g. awaitData is illegal without * tailable). */ -Status validateFindCommand(const FindCommand& findCommand); +Status validateFindCommandRequest(const FindCommandRequest& findCommand); /** * Parses a find command object, 'cmdObj'. Caller must indicate whether or not this lite * parsed query is an explained query or not via 'isExplain'. Accepts a NSS with which - * to initialize the FindCommand if there is no UUID in cmdObj. + * to initialize the FindCommandRequest if there is no UUID in cmdObj. * - * Returns a heap allocated FindCommand on success or an error if 'cmdObj' is not well + * Returns a heap allocated FindCommandRequest on success or an error if 'cmdObj' is not well * formed. */ -std::unique_ptr<FindCommand> makeFromFindCommand(const BSONObj& cmdObj, - boost::optional<NamespaceString> nss, - bool apiStrict); +std::unique_ptr<FindCommandRequest> makeFromFindCommand(const BSONObj& cmdObj, + boost::optional<NamespaceString> nss, + bool apiStrict); -std::unique_ptr<FindCommand> makeFromFindCommandForTests( +std::unique_ptr<FindCommandRequest> makeFromFindCommandForTests( const BSONObj& cmdObj, boost::optional<NamespaceString> nss = boost::none, bool apiStrict = false); /** - * If _uuid exists for this FindCommand, update the value of _nss. + * If _uuid exists for this FindCommandRequest, update the value of _nss. */ -void refreshNSS(const NamespaceString& nss, FindCommand* findCommand); +void refreshNSS(const NamespaceString& nss, FindCommandRequest* findCommand); /** - * Converts this FindCommand into an aggregation using $match. If this FindCommand has options - * that cannot be satisfied by aggregation, a non-OK status is returned and 'cmdBuilder' is not - * modified. + * Converts this FindCommandRequest into an aggregation using $match. If this FindCommandRequest has + * options that cannot be satisfied by aggregation, a non-OK status is returned and 'cmdBuilder' is + * not modified. */ -StatusWith<BSONObj> asAggregationCommand(const FindCommand& findCommand); +StatusWith<BSONObj> asAggregationCommand(const FindCommandRequest& findCommand); /** * Helper function to identify text search sort key @@ -134,9 +134,9 @@ static constexpr auto kMaxTimeMSOpOnlyMaxPadding = 100LL; static constexpr auto kDefaultBatchSize = 101ll; -void setTailableMode(TailableModeEnum tailableMode, FindCommand* findCommand); +void setTailableMode(TailableModeEnum tailableMode, FindCommandRequest* findCommand); -TailableModeEnum getTailableMode(const FindCommand& findCommand); +TailableModeEnum getTailableMode(const FindCommandRequest& findCommand); /** * Asserts whether the cursor response adhere to the format defined in IDL. @@ -148,29 +148,22 @@ void validateCursorResponse(const BSONObj& outputAsBson); // /** - * Parse the provided QueryMessage and return a heap constructed FindCommand, which + * Parse the provided QueryMessage and return a heap constructed FindCommandRequest, which * represents it or an error. */ -StatusWith<std::unique_ptr<FindCommand>> fromLegacyQueryMessage(const QueryMessage& qm, - bool* explain); +StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQueryMessage(const QueryMessage& qm, + bool* explain); /** - * Parse the provided legacy query object and parameters to construct a FindCommand. + * Parse the provided legacy query object and parameters to construct a FindCommandRequest. */ -StatusWith<std::unique_ptr<FindCommand>> fromLegacyQuery(NamespaceStringOrUUID nsOrUuid, - const BSONObj& queryObj, - const BSONObj& proj, - int ntoskip, - int ntoreturn, - int queryOptions, - bool* explain); - -StatusWith<std::unique_ptr<FindCommand>> fromLegacyQueryFindCommand(NamespaceStringOrUUID nsOrUuid, - const BSONObj& queryObj, - const BSONObj& proj, - int ntoskip, - int ntoreturn, - int queryOptions); +StatusWith<std::unique_ptr<FindCommandRequest>> fromLegacyQuery(NamespaceStringOrUUID nsOrUuid, + const BSONObj& queryObj, + const BSONObj& proj, + int ntoskip, + int ntoreturn, + int queryOptions, + bool* explain); } // namespace query_request_helper } // namespace mongo diff --git a/src/mongo/db/query/query_request_test.cpp b/src/mongo/db/query/query_request_test.cpp index 4b40ed4bbf3..e60a04ff79e 100644 --- a/src/mongo/db/query/query_request_test.cpp +++ b/src/mongo/db/query/query_request_test.cpp @@ -53,137 +53,137 @@ using unittest::assertGet; static const NamespaceString testns("testdb.testcoll"); TEST(QueryRequestTest, LimitWithNToReturn) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setLimit(1); findCommand.setNtoreturn(0); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, BatchSizeWithNToReturn) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setBatchSize(0); findCommand.setNtoreturn(0); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, NegativeSkip) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); ASSERT_THROWS_CODE(findCommand.setSkip(-1), DBException, 51024); } TEST(QueryRequestTest, ZeroSkip) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSkip(0); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, PositiveSkip) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSkip(1); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, NegativeLimit) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); ASSERT_THROWS_CODE(findCommand.setLimit(-1), DBException, 51024); } TEST(QueryRequestTest, ZeroLimit) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setLimit(0); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, PositiveLimit) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setLimit(1); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, NegativeBatchSize) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); ASSERT_THROWS_CODE(findCommand.setBatchSize(-1), DBException, 51024); } TEST(QueryRequestTest, ZeroBatchSize) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setBatchSize(0); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, PositiveBatchSize) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setBatchSize(1); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, NegativeNToReturn) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); ASSERT_THROWS_CODE(findCommand.setNtoreturn(-1), DBException, 51024); } TEST(QueryRequestTest, ZeroNToReturn) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setNtoreturn(0); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, PositiveNToReturn) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setNtoreturn(1); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, NegativeMaxTimeMS) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); ASSERT_THROWS_CODE(findCommand.setMaxTimeMS(-1), DBException, 51024); } TEST(QueryRequestTest, ZeroMaxTimeMS) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMaxTimeMS(0); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, PositiveMaxTimeMS) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMaxTimeMS(1); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ValidSortOrder) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSort(fromjson("{a: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, DoesNotErrorOnInvalidSortPattern) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSort(fromjson("{a: \"\"}")); - // FindCommand isn't responsible for validating the sort pattern, so it is considered valid - // even though the sort pattern {a: ""} is not well-formed. - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + // FindCommandRequest isn't responsible for validating the sort pattern, so it is considered + // valid even though the sort pattern {a: ""} is not well-formed. + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, MinFieldsNotPrefixOfMax) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMin(fromjson("{a: 1}")); findCommand.setMax(fromjson("{b: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, MinFieldsMoreThanMax) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMin(fromjson("{a: 1, b: 1}")); findCommand.setMax(fromjson("{a: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, MinFieldsLessThanMax) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMin(fromjson("{a: 1}")); findCommand.setMax(fromjson("{a: 1, b: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ForbidTailableWithNonNaturalSort) { @@ -224,122 +224,122 @@ TEST(QueryRequestTest, AllowTailableWithNaturalSort) { // TEST(QueryRequestTest, ValidSortProj) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setProjection(fromjson("{a: 1}")); findCommand.setSort(fromjson("{a: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); - FindCommand metaFC(testns); + FindCommandRequest metaFC(testns); metaFC.setProjection(fromjson("{a: {$meta: \"textScore\"}}")); metaFC.setSort(fromjson("{a: {$meta: \"textScore\"}}")); - ASSERT_OK(query_request_helper::validateFindCommand(metaFC)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(metaFC)); } TEST(QueryRequestTest, TextScoreMetaSortOnFieldDoesNotRequireMetaProjection) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setProjection(fromjson("{b: 1}")); findCommand.setSort(fromjson("{a: {$meta: 'textScore'}}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, TextScoreMetaProjectionDoesNotRequireTextScoreMetaSort) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setProjection(fromjson("{a: {$meta: \"textScore\"}}")); findCommand.setSort(fromjson("{b: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, RequestResumeTokenWithHint) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setRequestResumeToken(true); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setHint(fromjson("{a: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, RequestResumeTokenWithSort) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setRequestResumeToken(true); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setSort(fromjson("{a: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setSort(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, InvalidResumeAfterWrongRecordIdType) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1); findCommand.setResumeAfter(resumeAfter); findCommand.setRequestResumeToken(true); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); resumeAfter = BSON("$recordId" << 1LL); findCommand.setResumeAfter(resumeAfter); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, InvalidResumeAfterExtraField) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1LL << "$extra" << 1); findCommand.setResumeAfter(resumeAfter); findCommand.setRequestResumeToken(true); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ResumeAfterWithHint) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1LL); findCommand.setResumeAfter(resumeAfter); findCommand.setRequestResumeToken(true); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setHint(fromjson("{a: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ResumeAfterWithSort) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1LL); findCommand.setResumeAfter(resumeAfter); findCommand.setRequestResumeToken(true); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setSort(fromjson("{a: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setSort(fromjson("{$natural: 1}")); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ResumeNoSpecifiedRequestResumeToken) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1LL); findCommand.setResumeAfter(resumeAfter); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); - ASSERT_NOT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_NOT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setRequestResumeToken(true); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } TEST(QueryRequestTest, ExplicitEmptyResumeAfter) { - FindCommand findCommand(NamespaceString::kRsOplogNamespace); + FindCommandRequest findCommand(NamespaceString::kRsOplogNamespace); BSONObj resumeAfter = fromjson("{}"); // Hint must be explicitly set for the query request to validate. findCommand.setHint(fromjson("{$natural: 1}")); findCommand.setResumeAfter(resumeAfter); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); findCommand.setRequestResumeToken(true); - ASSERT_OK(query_request_helper::validateFindCommand(findCommand)); + ASSERT_OK(query_request_helper::validateFindCommandRequest(findCommand)); } // @@ -387,7 +387,8 @@ TEST(QueryRequestTest, ParseFromCommandWithOptions) { "projection: {_id: 0, a: 1}," "showRecordId: true, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); // Make sure the values from the command BSON are reflected in the QR. ASSERT(findCommand->getShowRecordId()); @@ -399,7 +400,8 @@ TEST(QueryRequestTest, ParseFromCommandHintAsString) { "filter: {a: 1}," "hint: 'foo_1', '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); BSONObj hintObj = findCommand->getHint(); ASSERT_BSONOBJ_EQ(BSON("$hint" @@ -435,7 +437,8 @@ TEST(QueryRequestTest, ParseFromCommandAllFlagsTrue) { "readOnce: true," "allowSpeculativeMajorityRead: true, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); // Test that all the flags got set to true. ASSERT(findCommand->getTailable()); @@ -465,7 +468,8 @@ TEST(QueryRequestTest, OplogReplayFlagIsAllowedButIgnored) { TEST(QueryRequestTest, ParseFromCommandReadOnceDefaultsToFalse) { BSONObj cmdObj = fromjson("{find: 'testns', '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(!findCommand->getReadOnce()); } @@ -476,7 +480,8 @@ TEST(QueryRequestTest, ParseFromCommandValidMinMax) { "min: {a: 1}," "max: {a: 2}, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); BSONObj expectedMin = BSON("a" << 1); ASSERT_EQUALS(0, expectedMin.woCompare(findCommand->getMin())); BSONObj expectedMax = BSON("a" << 2); @@ -501,7 +506,8 @@ TEST(QueryRequestTest, ParseFromCommandAllNonOptionFields) { "singleBatch: false, '$db': 'test'}") .addField(rtcObj["runtimeConstants"]); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); // Check the values inside the QR. BSONObj expectedQuery = BSON("a" << 1); ASSERT_EQUALS(0, expectedQuery.woCompare(findCommand->getFilter())); @@ -534,7 +540,8 @@ TEST(QueryRequestTest, ParseFromCommandLargeLimit) { "filter: {a: 1}," "limit: 8000000000, '$db': 'test'}"); // 8 * 1000 * 1000 * 1000 - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_EQUALS(8LL * 1000 * 1000 * 1000, *findCommand->getLimit()); } @@ -545,7 +552,8 @@ TEST(QueryRequestTest, ParseFromCommandLargeBatchSize) { "filter: {a: 1}," "batchSize: 8000000000, '$db': 'test'}"); // 8 * 1000 * 1000 * 1000 - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_EQUALS(8LL * 1000 * 1000 * 1000, *findCommand->getBatchSize()); } @@ -556,7 +564,8 @@ TEST(QueryRequestTest, ParseFromCommandLargeSkip) { "filter: {a: 1}," "skip: 8000000000, '$db': 'test'}"); // 8 * 1000 * 1000 * 1000 - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_EQUALS(8LL * 1000 * 1000 * 1000, *findCommand->getSkip()); } @@ -863,7 +872,8 @@ TEST(QueryRequestTest, ParseFromCommandSkipIsZero) { "{find: 'testns'," "skip: 0," "filter: {a: 3}, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_BSONOBJ_EQ(BSON("a" << 3), findCommand->getFilter()); ASSERT_FALSE(findCommand->getSkip()); } @@ -882,7 +892,8 @@ TEST(QueryRequestTest, ParseFromCommandLimitIsZero) { "{find: 'testns'," "limit: 0," "filter: {a: 3}, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_BSONOBJ_EQ(BSON("a" << 3), findCommand->getFilter()); ASSERT_FALSE(findCommand->getLimit()); } @@ -898,7 +909,8 @@ TEST(QueryRequestTest, ParseFromCommandNegativeBatchSizeError) { TEST(QueryRequestTest, ParseFromCommandBatchSizeZero) { BSONObj cmdObj = fromjson("{find: 'testns', batchSize: 0, '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(findCommand->getBatchSize()); ASSERT_EQ(0, *findCommand->getBatchSize()); @@ -907,7 +919,8 @@ TEST(QueryRequestTest, ParseFromCommandBatchSizeZero) { TEST(QueryRequestTest, ParseFromCommandDefaultBatchSize) { BSONObj cmdObj = fromjson("{find: 'testns', '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(!findCommand->getBatchSize()); ASSERT(!findCommand->getLimit()); @@ -920,7 +933,8 @@ TEST(QueryRequestTest, ParseFromCommandRequestResumeToken) { << "$_requestResumeToken" << true << "$db" << "test"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(findCommand->getRequestResumeToken()); } @@ -932,7 +946,8 @@ TEST(QueryRequestTest, ParseFromCommandResumeToken) { << BSON("$recordId" << 1LL) << "$db" << "test"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(!findCommand->getResumeAfter().isEmpty()); ASSERT(findCommand->getRequestResumeToken()); } @@ -946,16 +961,17 @@ TEST(QueryRequestTest, ParseFromCommandEmptyResumeToken) { << "$_requestResumeToken" << true << "$_resumeAfter" << resumeAfter << "$db" << "test"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(findCommand->getRequestResumeToken()); ASSERT(findCommand->getResumeAfter().isEmpty()); } // -// Test FindCommand object ns and uuid variants. +// Test FindCommandRequest object ns and uuid variants. // -TEST(QueryRequestTest, AsFindCommandAllNonOptionFields) { +TEST(QueryRequestTest, AsFindCommandRequestAllNonOptionFields) { BSONObj storage = BSON("runtimeConstants" << (LegacyRuntimeConstants{Date_t::now(), Timestamp(1, 1)}.toBSON())); BSONObj cmdObj = fromjson( @@ -972,11 +988,12 @@ TEST(QueryRequestTest, AsFindCommandAllNonOptionFields) { "readConcern: {e: 1}, '$db': 'test'}") .addField(storage["runtimeConstants"]); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_BSONOBJ_EQ(cmdObj.removeField("$db"), findCommand->toBSON(BSONObj())); } -TEST(QueryRequestTest, AsFindCommandWithUuidAllNonOptionFields) { +TEST(QueryRequestTest, AsFindCommandRequestWithUuidAllNonOptionFields) { BSONObj storage = BSON("runtimeConstants" << (LegacyRuntimeConstants{Date_t::now(), Timestamp(1, 1)}.toBSON())); BSONObj cmdObj = @@ -995,19 +1012,20 @@ TEST(QueryRequestTest, AsFindCommandWithUuidAllNonOptionFields) { "readConcern: {e: 1}, '$db': 'test'}") .addField(storage["runtimeConstants"]); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_BSONOBJ_EQ(cmdObj.removeField("$db"), findCommand->toBSON(BSONObj())); } -TEST(QueryRequestTest, AsFindCommandWithUuidNoAvailableNamespace) { +TEST(QueryRequestTest, AsFindCommandRequestWithUuidNoAvailableNamespace) { BSONObj cmdObj = fromjson("{find: { \"$binary\" : \"ASNFZ4mrze/ty6mHZUMhAQ==\", \"$type\" : \"04\" }}"); - FindCommand findCommand(NamespaceStringOrUUID( + FindCommandRequest findCommand(NamespaceStringOrUUID( "test", UUID::parse("01234567-89ab-cdef-edcb-a98765432101").getValue())); ASSERT_BSONOBJ_EQ(cmdObj.removeField("$db"), findCommand.toBSON(BSONObj())); } -TEST(QueryRequestTest, AsFindCommandWithResumeToken) { +TEST(QueryRequestTest, AsFindCommandRequestWithResumeToken) { BSONObj cmdObj = BSON("find" << "testns" << "sort" << BSON("$natural" << 1) << "hint" << BSON("$natural" << 1) @@ -1015,11 +1033,12 @@ TEST(QueryRequestTest, AsFindCommandWithResumeToken) { << BSON("$recordId" << 1LL) << "$db" << "test"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_BSONOBJ_EQ(cmdObj.removeField("$db"), findCommand->toBSON(BSONObj())); } -TEST(QueryRequestTest, AsFindCommandWithEmptyResumeToken) { +TEST(QueryRequestTest, AsFindCommandRequestWithEmptyResumeToken) { BSONObj resumeAfter = fromjson("{}"); BSONObj cmdObj = BSON("find" @@ -1027,13 +1046,14 @@ TEST(QueryRequestTest, AsFindCommandWithEmptyResumeToken) { << "hint" << BSON("$natural" << 1) << "sort" << BSON("$natural" << 1) << "$_requestResumeToken" << true << "$_resumeAfter" << resumeAfter << "$db" << "test"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT(findCommand->toBSON(BSONObj()).getField("$_resumeAftr").eoo()); } // // -// Errors checked in query_request_helper::validateFindCommand(). +// Errors checked in query_request_helper::validateFindCommandRequest(). // TEST(QueryRequestTest, ParseFromCommandMinMaxDifferentFieldsError) { @@ -1087,7 +1107,8 @@ TEST(QueryRequestTest, ParseCommandForbidExhaust) { TEST(QueryRequestTest, ParseCommandIsFromFindCommand) { BSONObj cmdObj = fromjson("{find: 'testns', '$db': 'test'}"); - unique_ptr<FindCommand> findCommand(query_request_helper::makeFromFindCommandForTests(cmdObj)); + unique_ptr<FindCommandRequest> findCommand( + query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_FALSE(findCommand->getNtoreturn()); } @@ -1114,7 +1135,7 @@ TEST(QueryRequestTest, ParseCommandIgnoreShardVersionField) { TEST(QueryRequestTest, DefaultQueryParametersCorrect) { BSONObj cmdObj = fromjson("{find: 'testns', '$db': 'test'}"); - std::unique_ptr<FindCommand> findCommand( + std::unique_ptr<FindCommandRequest> findCommand( query_request_helper::makeFromFindCommandForTests(cmdObj)); ASSERT_FALSE(findCommand->getSkip()); @@ -1206,7 +1227,7 @@ TEST(QueryRequestTest, ParseMaxTimeMSPositiveInRangeSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg); @@ -1223,7 +1244,7 @@ TEST(QueryRequestTest, ConvertToAggregationSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationOmitsExplain) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg); @@ -1237,7 +1258,7 @@ TEST(QueryRequestTest, ConvertToAggregationOmitsExplain) { } TEST(QueryRequestTest, ConvertToAggregationWithHintSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setHint(fromjson("{a_1: -1}")); const auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg); @@ -1249,94 +1270,94 @@ TEST(QueryRequestTest, ConvertToAggregationWithHintSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationWithMinFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMin(fromjson("{a: 1}")); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithMaxFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMax(fromjson("{a: 1}")); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithSingleBatchFieldFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSingleBatch(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithSingleBatchFieldAndLimitFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSingleBatch(true); findCommand.setLimit(7); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithSingleBatchFieldLimitOneSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setSingleBatch(true); findCommand.setLimit(1); ASSERT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithReturnKeyFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setReturnKey(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithShowRecordIdFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setShowRecordId(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithTailableFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); query_request_helper::setTailableMode(TailableModeEnum::kTailable, &findCommand); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithNoCursorTimeoutFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setNoCursorTimeout(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithAwaitDataFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); query_request_helper::setTailableMode(TailableModeEnum::kTailableAndAwaitData, &findCommand); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithAllowPartialResultsFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowPartialResults(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithNToReturnFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setNtoreturn(7); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithRequestResumeTokenFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setRequestResumeToken(true); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithResumeAfterFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); BSONObj resumeAfter = BSON("$recordId" << 1LL); findCommand.setResumeAfter(resumeAfter); ASSERT_NOT_OK(query_request_helper::asAggregationCommand(findCommand)); } TEST(QueryRequestTest, ConvertToAggregationWithPipeline) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setFilter(BSON("x" << 1)); findCommand.setSort(BSON("y" << -1)); findCommand.setLimit(3); @@ -1368,7 +1389,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithPipeline) { } TEST(QueryRequestTest, ConvertToAggregationWithBatchSize) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setBatchSize(4); auto agg = query_request_helper::asAggregationCommand(findCommand); @@ -1386,7 +1407,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithBatchSize) { } TEST(QueryRequestTest, ConvertToAggregationWithMaxTimeMS) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setMaxTimeMS(9); auto agg = query_request_helper::asAggregationCommand(findCommand); @@ -1407,7 +1428,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithMaxTimeMS) { } TEST(QueryRequestTest, ConvertToAggregationWithCollationSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setCollation(BSON("f" << 1)); auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg); @@ -1425,14 +1446,14 @@ TEST(QueryRequestTest, ConvertToAggregationWithCollationSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationWithReadOnceFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setReadOnce(true); const auto aggCmd = query_request_helper::asAggregationCommand(findCommand); ASSERT_EQ(ErrorCodes::InvalidPipelineOperator, aggCmd.getStatus().code()); } TEST(QueryRequestTest, ConvertToAggregationWithAllowSpeculativeMajorityReadFails) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowSpeculativeMajorityRead(true); const auto aggCmd = query_request_helper::asAggregationCommand(findCommand); ASSERT_EQ(ErrorCodes::InvalidPipelineOperator, aggCmd.getStatus().code()); @@ -1440,7 +1461,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithAllowSpeculativeMajorityReadFails TEST(QueryRequestTest, ConvertToAggregationWithLegacyRuntimeConstantsSucceeds) { LegacyRuntimeConstants rtc{Date_t::now(), Timestamp(1, 1)}; - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setLegacyRuntimeConstants(rtc); auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg); @@ -1454,7 +1475,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithLegacyRuntimeConstantsSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationWithAllowDiskUseTrueSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowDiskUse(true); const auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg.getStatus()); @@ -1466,7 +1487,7 @@ TEST(QueryRequestTest, ConvertToAggregationWithAllowDiskUseTrueSucceeds) { } TEST(QueryRequestTest, ConvertToAggregationWithAllowDiskUseFalseSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowDiskUse(false); const auto agg = query_request_helper::asAggregationCommand(findCommand); ASSERT_OK(agg.getStatus()); @@ -1478,21 +1499,21 @@ TEST(QueryRequestTest, ConvertToAggregationWithAllowDiskUseFalseSucceeds) { } TEST(QueryRequestTest, ConvertToFindWithAllowDiskUseTrueSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowDiskUse(true); const auto findCmd = findCommand.toBSON(BSONObj()); - BSONElement elem = findCmd[FindCommand::kAllowDiskUseFieldName]; + BSONElement elem = findCmd[FindCommandRequest::kAllowDiskUseFieldName]; ASSERT_EQ(true, elem.isBoolean()); ASSERT_EQ(true, elem.Bool()); } TEST(QueryRequestTest, ConvertToFindWithAllowDiskUseFalseSucceeds) { - FindCommand findCommand(testns); + FindCommandRequest findCommand(testns); findCommand.setAllowDiskUse(false); const auto findCmd = findCommand.toBSON(BSONObj()); - ASSERT_FALSE(findCmd[FindCommand::kAllowDiskUseFieldName].booleanSafe()); + ASSERT_FALSE(findCmd[FindCommandRequest::kAllowDiskUseFieldName].booleanSafe()); } TEST(QueryRequestTest, ParseFromLegacyQuery) { @@ -1509,7 +1530,7 @@ TEST(QueryRequestTest, ParseFromLegacyQuery) { })"); bool explain = false; - unique_ptr<FindCommand> findCommand(assertGet(query_request_helper::fromLegacyQuery( + unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( nss, queryObj, BSON("proj" << 1), kSkip, kNToReturn, QueryOption_Exhaust, &explain))); ASSERT_EQ(*findCommand->getNamespaceOrUUID().nss(), nss); @@ -1539,7 +1560,7 @@ TEST(QueryRequestTest, ParseFromLegacyQueryOplogReplayFlagAllowed) { // flag may be set by old clients. auto options = QueryOption_OplogReplay_DEPRECATED; bool explain = false; - unique_ptr<FindCommand> findCommand(assertGet(query_request_helper::fromLegacyQuery( + unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( nss, queryObj, projectionObj, nToSkip, nToReturn, options, &explain))); // Verify that if we reserialize the find command, the 'oplogReplay' field @@ -1561,7 +1582,7 @@ TEST(QueryRequestTest, ParseFromLegacyQueryUnwrapped) { })"); const NamespaceString nss("test.testns"); bool explain = false; - unique_ptr<FindCommand> findCommand(assertGet(query_request_helper::fromLegacyQuery( + unique_ptr<FindCommandRequest> findCommand(assertGet(query_request_helper::fromLegacyQuery( nss, queryObj, BSONObj(), 0, 0, QueryOption_Exhaust, &explain))); ASSERT_EQ(*findCommand->getNamespaceOrUUID().nss(), nss); @@ -1606,7 +1627,7 @@ TEST_F(QueryRequestTest, ParseFromUUID) { NamespaceStringOrUUID nssOrUUID("test", uuid); - FindCommand findCommand(nssOrUUID); + FindCommandRequest findCommand(nssOrUUID); const NamespaceString nss("test.testns"); // Ensure a call to refreshNSS succeeds. query_request_helper::refreshNSS(nss, &findCommand); diff --git a/src/mongo/db/query/query_settings.cpp b/src/mongo/db/query/query_settings.cpp index d3552edd3c0..d0d9e1a9f1a 100644 --- a/src/mongo/db/query/query_settings.cpp +++ b/src/mongo/db/query/query_settings.cpp @@ -101,7 +101,7 @@ std::vector<AllowedIndexEntry> QuerySettings::getAllAllowedIndices() const { void QuerySettings::setAllowedIndices(const CanonicalQuery& canonicalQuery, const BSONObjSet& indexKeyPatterns, const stdx::unordered_set<std::string>& indexNames) { - const FindCommand& findCommand = canonicalQuery.getFindCommand(); + const FindCommandRequest& findCommand = canonicalQuery.getFindCommandRequest(); const BSONObj& query = findCommand.getFilter(); const BSONObj& sort = findCommand.getSort(); const BSONObj& projection = findCommand.getProjection(); diff --git a/src/mongo/db/query/sbe_stage_builder.cpp b/src/mongo/db/query/sbe_stage_builder.cpp index 032510007da..d65a2120f11 100644 --- a/src/mongo/db/query/sbe_stage_builder.cpp +++ b/src/mongo/db/query/sbe_stage_builder.cpp @@ -1854,7 +1854,7 @@ std::pair<std::unique_ptr<sbe::PlanStage>, PlanStageSlots> SlotBasedStageBuilder case STAGE_COLLSCAN: case STAGE_LIMIT: case STAGE_SKIP: - if (_cq.getFindCommand().getTailable() && + if (_cq.getFindCommandRequest().getTailable() && !reqs.getIsBuildingUnionForTailableCollScan()) { auto childReqs = reqs; childReqs.setIsBuildingUnionForTailableCollScan(true); diff --git a/src/mongo/db/query/sbe_stage_builder_test_fixture.cpp b/src/mongo/db/query/sbe_stage_builder_test_fixture.cpp index fad3a4cd63a..36fb19ed215 100644 --- a/src/mongo/db/query/sbe_stage_builder_test_fixture.cpp +++ b/src/mongo/db/query/sbe_stage_builder_test_fixture.cpp @@ -49,7 +49,7 @@ SbeStageBuilderTestFixture::buildPlanStage( std::unique_ptr<QuerySolution> querySolution, bool hasRecordId, std::unique_ptr<ShardFiltererFactoryInterface> shardFiltererInterface) { - auto findCommand = std::make_unique<FindCommand>(_nss); + auto findCommand = std::make_unique<FindCommandRequest>(_nss); const boost::intrusive_ptr<ExpressionContext> expCtx(new ExpressionContextForTest(_nss)); auto statusWithCQ = CanonicalQuery::canonicalize(opCtx(), std::move(findCommand), false, expCtx); |