diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2021-03-05 19:42:22 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-06 01:19:47 +0000 |
commit | bd5693121fbe12bee14a83b4527df73c881a2052 (patch) | |
tree | 23a0b17b3daba1be8b4bbde56f7d2a85a6907ae1 /src/mongo/db/query/getmore_request.cpp | |
parent | f0a5b6384340c7b4b06c0e0e0edb32a5c007ae38 (diff) | |
download | mongo-bd5693121fbe12bee14a83b4527df73c881a2052.tar.gz |
SERVER-53149 Finish converting getMore to IDL
Diffstat (limited to 'src/mongo/db/query/getmore_request.cpp')
-rw-r--r-- | src/mongo/db/query/getmore_request.cpp | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp index 30d8c59337b..669c9587213 100644 --- a/src/mongo/db/query/getmore_request.cpp +++ b/src/mongo/db/query/getmore_request.cpp @@ -38,7 +38,6 @@ #include "mongo/db/api_parameters_gen.h" #include "mongo/db/commands.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/query/getmore_command_gen.h" #include "mongo/db/repl/bson_extract_optime.h" #include "mongo/idl/command_generic_argument.h" #include "mongo/util/assert_util.h" @@ -46,6 +45,18 @@ 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, @@ -80,54 +91,29 @@ Status GetMoreRequest::isValid() const { return Status::OK(); } -// static -StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbname, - const BSONObj& cmdObj) try { - for (const auto& fieldName : - std::vector<StringData>{APIParametersFromClient::kApiVersionFieldName, - APIParametersFromClient::kApiStrictFieldName, - APIParametersFromClient::kApiDeprecationErrorsFieldName}) { - uassert(4937600, - str::stream() << "Cannot pass in API parameter field " << fieldName, - !cmdObj.hasField(fieldName)); - } +BSONObj GetMoreRequest::toBSON() const { + BSONObjBuilder builder; + + builder.append(kGetMoreCommandName, cursorid); + builder.append(kCollectionField, nss.coll()); - auto parsed = GetMoreCommand::parse({"getMore"}, cmdObj); - auto maxTimeMS = parsed.getMaxTimeMS(); - - GetMoreRequest request( - NamespaceString(dbname, parsed.getCollection()), - parsed.getCommandParameter(), - parsed.getBatchSize(), - // Treat maxTimeMS=0 the same as none. - (maxTimeMS && *maxTimeMS) ? boost::optional<Milliseconds>(*maxTimeMS) : boost::none, - parsed.getTerm() ? boost::optional<long long>(*parsed.getTerm()) : boost::none, - parsed.getLastKnownCommittedOpTime()); - - Status validStatus = request.isValid(); - if (!validStatus.isOK()) { - return validStatus; + if (batchSize) { + builder.append(kBatchSizeField, *batchSize); } - return request; -} catch (const DBException& exc) { - return exc.toStatus(); -} + if (awaitDataTimeout) { + builder.append(kAwaitDataTimeoutField, durationCount<Milliseconds>(*awaitDataTimeout)); + } -BSONObj GetMoreRequest::toBSON() const { - auto cmd = GetMoreCommand(cursorid); - cmd.setDbName(nss.db()); - cmd.setCollection(nss.coll()); - cmd.setBatchSize(batchSize); - cmd.setLastKnownCommittedOpTime(lastKnownCommittedOpTime); if (term) { - cmd.setTerm(static_cast<int64_t>(*term)); + builder.append(kTermField, *term); } - if (awaitDataTimeout) { - cmd.setMaxTimeMS(durationCount<Milliseconds>(*awaitDataTimeout)); + + if (lastKnownCommittedOpTime) { + lastKnownCommittedOpTime->append(&builder, kLastKnownCommittedOpTimeField); } - return cmd.toBSON({}); + return builder.obj(); } } // namespace mongo |