diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2022-02-10 17:36:36 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-10 18:25:19 +0000 |
commit | 724d7f8cd512d3afde931d3d34220e7eb05e5a2d (patch) | |
tree | 99397b45f1892a3e012d8fa01394ccdf0a126a34 /src/mongo/db/query | |
parent | d8ff665343ad29cf286ee2cf4a1960d29371937b (diff) | |
download | mongo-724d7f8cd512d3afde931d3d34220e7eb05e5a2d.tar.gz |
SERVER-62531 Add ability for TaskExecutorCursor to parse multiple cursors
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r-- | src/mongo/db/query/cursor_response.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/query/cursor_response.h | 6 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/mongo/db/query/cursor_response.cpp b/src/mongo/db/query/cursor_response.cpp index d31b6ab9274..b4042f559b1 100644 --- a/src/mongo/db/query/cursor_response.cpp +++ b/src/mongo/db/query/cursor_response.cpp @@ -159,7 +159,7 @@ std::vector<StatusWith<CursorResponse>> CursorResponse::parseFromBSONMany( << "Cursors array element contains non-object element: " << elt}); } else { - cursors.push_back(parseFromBSON(elt.Obj())); + cursors.push_back(parseFromBSON(elt.Obj(), &cmdResponse)); } } } @@ -167,7 +167,8 @@ std::vector<StatusWith<CursorResponse>> CursorResponse::parseFromBSONMany( return cursors; } -StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdResponse) { +StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdResponse, + const BSONObj* ownedObj) { Status cmdStatus = getStatusFromCommandResult(cmdResponse); if (!cmdStatus.isOK()) { return cmdStatus; @@ -231,8 +232,16 @@ StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdRespo batch.push_back(elt.Obj()); } + tassert(6253102, + "Must own one of the two arguments if there are documents in the batch", + batch.size() == 0 || cmdResponse.isOwned() || (ownedObj && ownedObj->isOwned())); + for (auto& doc : batch) { - doc.shareOwnershipWith(cmdResponse); + if (ownedObj) { + doc.shareOwnershipWith(*ownedObj); + } else { + doc.shareOwnershipWith(cmdResponse); + } } auto postBatchResumeTokenElem = cursorObj[kPostBatchResumeTokenField]; diff --git a/src/mongo/db/query/cursor_response.h b/src/mongo/db/query/cursor_response.h index ce1950fe104..ca81974e78b 100644 --- a/src/mongo/db/query/cursor_response.h +++ b/src/mongo/db/query/cursor_response.h @@ -179,9 +179,11 @@ public: static std::vector<StatusWith<CursorResponse>> parseFromBSONMany(const BSONObj& cmdResponse); /** - * Constructs a CursorResponse from the command BSON response. + * Constructs a CursorResponse from the command BSON response. If 'cmdResponse' is not owned, + * the second argument should be the object that owns the response. */ - static StatusWith<CursorResponse> parseFromBSON(const BSONObj& cmdResponse); + static StatusWith<CursorResponse> parseFromBSON(const BSONObj& cmdResponse, + const BSONObj* ownedObj = nullptr); /** * A throwing version of 'parseFromBSON'. |