summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorAlya Berciu <alyacarina@gmail.com>2021-05-17 18:19:15 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-24 09:10:39 +0000
commit1059d33fa4a0d5c747a1115f0853b5f70e46f112 (patch)
tree8df47fa9cab779c578f9f52057ccccb6c1d46f15 /src/mongo/db/query
parent3f14978f40cfe899b632c43f498117080db42c77 (diff)
downloadmongo-1059d33fa4a0d5c747a1115f0853b5f70e46f112.tar.gz
SERVER-55015 Replace GetMoreRequest with IDL-generated GetMoreCommand
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/SConscript1
-rw-r--r--src/mongo/db/query/getmore_command.idl10
-rw-r--r--src/mongo/db/query/getmore_request.cpp119
-rw-r--r--src/mongo/db/query/getmore_request.h91
-rw-r--r--src/mongo/db/query/getmore_request_test.cpp77
5 files changed, 34 insertions, 264 deletions
diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript
index 7c5b7ad2e25..0fa78436533 100644
--- a/src/mongo/db/query/SConscript
+++ b/src/mongo/db/query/SConscript
@@ -165,7 +165,6 @@ env.Library(
"count_request.cpp",
'cursor_request.cpp',
'cursor_response.cpp',
- 'getmore_request.cpp',
'view_response_formatter.cpp',
'count_command.idl',
'kill_cursors.idl',
diff --git a/src/mongo/db/query/getmore_command.idl b/src/mongo/db/query/getmore_command.idl
index c68cba81feb..abade014f94 100644
--- a/src/mongo/db/query/getmore_command.idl
+++ b/src/mongo/db/query/getmore_command.idl
@@ -53,18 +53,26 @@ commands:
type: string
validator: { callback: "query_request_helper::validateGetMoreCollectionName" }
batchSize:
+ description: >
+ The batch size is optional. If not provided, we will put as many documents into the batch
+ as fit within the byte limit.
type: safeInt64
optional: true
validator: {gte: 0}
maxTimeMS:
- description: "The awaitData timeout."
+ description: >
+ The await data timeout: the number of milliseconds for which a getMore on a tailable,
+ awaitData query should block.
type: safeInt64
optional: true
term:
+ description: >
+ Only internal queries from replication will typically have a term.
type: long
optional: true
unstable: true
lastKnownCommittedOpTime:
+ description: Only internal queries from replication will have a last known committed optime.
type: optime
optional: true
unstable: true
diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp
deleted file mode 100644
index 669c9587213..00000000000
--- a/src/mongo/db/query/getmore_request.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kQuery
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/query/getmore_request.h"
-
-#include <boost/optional.hpp>
-
-#include "mongo/db/api_parameters_gen.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/namespace_string.h"
-#include "mongo/db/repl/bson_extract_optime.h"
-#include "mongo/idl/command_generic_argument.h"
-#include "mongo/util/assert_util.h"
-#include "mongo/util/str.h"
-
-namespace mongo {
-
-namespace {
-
-const char kCollectionField[] = "collection";
-const char kBatchSizeField[] = "batchSize";
-const char kAwaitDataTimeoutField[] = "maxTimeMS";
-const char kTermField[] = "term";
-const char kLastKnownCommittedOpTimeField[] = "lastKnownCommittedOpTime";
-
-} // namespace
-
-const char GetMoreRequest::kGetMoreCommandName[] = "getMore";
-
-GetMoreRequest::GetMoreRequest() : cursorid(0), batchSize(0) {}
-
-GetMoreRequest::GetMoreRequest(NamespaceString namespaceString,
- CursorId id,
- boost::optional<std::int64_t> sizeOfBatch,
- boost::optional<Milliseconds> awaitDataTimeout,
- boost::optional<long long> term,
- boost::optional<repl::OpTime> lastKnownCommittedOpTime)
- : nss(std::move(namespaceString)),
- cursorid(id),
- batchSize(sizeOfBatch),
- awaitDataTimeout(awaitDataTimeout),
- term(term),
- lastKnownCommittedOpTime(lastKnownCommittedOpTime) {}
-
-Status GetMoreRequest::isValid() const {
- if (!nss.isValid()) {
- return Status(ErrorCodes::InvalidNamespace,
- str::stream() << "Invalid namespace for getMore: " << nss.ns());
- }
-
- if (cursorid == 0) {
- return Status(ErrorCodes::BadValue, "Cursor id for getMore must be non-zero");
- }
-
- if (batchSize && *batchSize <= 0) {
- return Status(ErrorCodes::BadValue,
- str::stream() << "Batch size for getMore must be positive, "
- << "but received: " << *batchSize);
- }
-
- return Status::OK();
-}
-
-BSONObj GetMoreRequest::toBSON() const {
- BSONObjBuilder builder;
-
- builder.append(kGetMoreCommandName, cursorid);
- builder.append(kCollectionField, nss.coll());
-
- if (batchSize) {
- builder.append(kBatchSizeField, *batchSize);
- }
-
- if (awaitDataTimeout) {
- builder.append(kAwaitDataTimeoutField, durationCount<Milliseconds>(*awaitDataTimeout));
- }
-
- if (term) {
- builder.append(kTermField, *term);
- }
-
- if (lastKnownCommittedOpTime) {
- lastKnownCommittedOpTime->append(&builder, kLastKnownCommittedOpTimeField);
- }
-
- return builder.obj();
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/query/getmore_request.h b/src/mongo/db/query/getmore_request.h
deleted file mode 100644
index 61efdfcd187..00000000000
--- a/src/mongo/db/query/getmore_request.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <boost/optional.hpp>
-#include <string>
-
-#include "mongo/base/status.h"
-#include "mongo/base/status_with.h"
-#include "mongo/db/clientcursor.h"
-#include "mongo/db/namespace_string.h"
-#include "mongo/util/time_support.h"
-
-namespace mongo {
-
-struct GetMoreRequest {
- static const char kGetMoreCommandName[];
-
- /**
- * Construct an empty request.
- */
- GetMoreRequest();
-
- /**
- * Construct from values for each field.
- */
- GetMoreRequest(NamespaceString namespaceString,
- CursorId id,
- boost::optional<std::int64_t> sizeOfBatch,
- boost::optional<Milliseconds> awaitDataTimeout,
- boost::optional<long long> term,
- boost::optional<repl::OpTime> lastKnownCommittedOpTime);
-
- /**
- * Serializes this object into a BSON representation. Fields that are not set will not be
- * part of the the serialized object.
- */
- BSONObj toBSON() const;
-
- const NamespaceString nss;
- const CursorId cursorid;
-
- // The batch size is optional. If not provided, we will put as many documents into the batch
- // as fit within the byte limit.
- const boost::optional<std::int64_t> batchSize;
-
- // The number of milliseconds for which a getMore on a tailable, awaitData query should block.
- const boost::optional<Milliseconds> awaitDataTimeout;
-
- // Only internal queries from replication will typically have a term.
- const boost::optional<long long> term;
-
- // Only internal queries from replication will have a last known committed optime.
- const boost::optional<repl::OpTime> lastKnownCommittedOpTime;
-
-private:
- /**
- * Returns a non-OK status if there are semantic errors in the parsed request
- * (e.g. a negative batchSize).
- */
- Status isValid() const;
-};
-
-} // namespace mongo
diff --git a/src/mongo/db/query/getmore_request_test.cpp b/src/mongo/db/query/getmore_request_test.cpp
index e698fa9c07f..cf04d5075c8 100644
--- a/src/mongo/db/query/getmore_request_test.cpp
+++ b/src/mongo/db/query/getmore_request_test.cpp
@@ -31,8 +31,9 @@
#include <string>
+#include "mongo/db/cursor_id.h"
#include "mongo/db/jsobj.h"
-#include "mongo/db/query/getmore_request.h"
+#include "mongo/db/query/getmore_command_gen.h"
#include "mongo/db/repl/optime.h"
#include "mongo/unittest/unittest.h"
@@ -41,66 +42,38 @@ namespace {
using namespace mongo;
-TEST(GetMoreRequestTest, toBSONHasBatchSize) {
- GetMoreRequest request(
- NamespaceString("testdb.testcoll"), 123, 99, boost::none, boost::none, boost::none);
- BSONObj requestObj = request.toBSON();
- BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection"
- << "testcoll"
- << "batchSize" << 99);
- ASSERT_BSONOBJ_EQ(requestObj, expectedRequest);
+GetMoreCommandRequest createGetMoreCommandRequest(
+ std::string collection,
+ std::int64_t cursorId,
+ boost::optional<std::int64_t> sizeOfBatch = boost::none,
+ boost::optional<std::int64_t> awaitDataTimeout = boost::none,
+ boost::optional<std::int64_t> term = boost::none,
+ boost::optional<repl::OpTime> lastKnownCommittedOpTime = boost::none) {
+ GetMoreCommandRequest request(cursorId, collection);
+ request.setBatchSize(sizeOfBatch);
+ request.setMaxTimeMS(awaitDataTimeout);
+ request.setTerm(term);
+ request.setLastKnownCommittedOpTime(lastKnownCommittedOpTime);
+ return request;
}
-TEST(GetMoreRequestTest, toBSONMissingMatchSize) {
- GetMoreRequest request(NamespaceString("testdb.testcoll"),
- 123,
- boost::none,
- boost::none,
- boost::none,
- boost::none);
- BSONObj requestObj = request.toBSON();
+TEST(GetMoreRequestTest, toBSONMissingOptionalFields) {
+ GetMoreCommandRequest request = createGetMoreCommandRequest("testcoll", 123);
+ BSONObj requestObj = request.toBSON({});
BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection"
<< "testcoll");
ASSERT_BSONOBJ_EQ(requestObj, expectedRequest);
}
-TEST(GetMoreRequestTest, toBSONHasTerm) {
- GetMoreRequest request(
- NamespaceString("testdb.testcoll"), 123, 99, boost::none, 1, boost::none);
- BSONObj requestObj = request.toBSON();
- BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection"
- << "testcoll"
- << "batchSize" << 99 << "term" << 1);
- ASSERT_BSONOBJ_EQ(requestObj, expectedRequest);
-}
-
-TEST(GetMoreRequestTest, toBSONHasCommitLevel) {
- GetMoreRequest request(NamespaceString("testdb.testcoll"),
- 123,
- 99,
- boost::none,
- 1,
- repl::OpTime(Timestamp(0, 10), 2));
- BSONObj requestObj = request.toBSON();
- BSONObj expectedRequest =
- BSON("getMore" << CursorId(123) << "collection"
- << "testcoll"
- << "batchSize" << 99 << "term" << 1 << "lastKnownCommittedOpTime"
- << BSON("ts" << Timestamp(0, 10) << "t" << 2LL));
- ASSERT_BSONOBJ_EQ(requestObj, expectedRequest);
-}
-
-TEST(GetMoreRequestTest, toBSONHasMaxTimeMS) {
- GetMoreRequest request(NamespaceString("testdb.testcoll"),
- 123,
- boost::none,
- Milliseconds(789),
- boost::none,
- boost::none);
- BSONObj requestObj = request.toBSON();
+TEST(GetMoreRequestTest, toBSONNoMissingFields) {
+ GetMoreCommandRequest request =
+ createGetMoreCommandRequest("testcoll", 123, 99, 789, 1, repl::OpTime(Timestamp(0, 10), 2));
+ BSONObj requestObj = request.toBSON({});
BSONObj expectedRequest = BSON("getMore" << CursorId(123) << "collection"
<< "testcoll"
- << "maxTimeMS" << 789);
+ << "batchSize" << 99 << "maxTimeMS" << 789 << "term"
+ << 1 << "lastKnownCommittedOpTime"
+ << BSON("ts" << Timestamp(0, 10) << "t" << 2LL));
ASSERT_BSONOBJ_EQ(requestObj, expectedRequest);
}