SERVER-105085 Avoid copying batch in received CursorResponse (#36156)

GitOrigin-RevId: 58297c66c6bef8dd65df4b5d04ded076f74e8fb1
This commit is contained in:
Jan 2025-05-15 18:38:30 +02:00 committed by MongoDB Bot
parent cbdca5bdac
commit c92c4464a4
3 changed files with 9 additions and 7 deletions

View File

@ -69,6 +69,9 @@ structs:
description:
The response after establishing a cursor on the remote shard, including
the first batch.
# Non-const getter is needed here so we can move the batch of BSONObjs out of
# the response if needed.
non_const_getter: true
AsyncResultsMergerParams:
description: The parameters needed to establish an AsyncResultsMerger.

View File

@ -72,7 +72,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
auto result = storePossibleCursor(opCtx,
remoteCursor->getShardId().toString(),
remoteCursor->getHostAndPort(),
remoteCursor->getCursorResponse(),
std::move(remoteCursor->getCursorResponse()),
requestedNss,
executorPool->getArbitraryExecutor(),
Grid::get(opCtx)->getCursorManager(),
@ -104,7 +104,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
return incomingCursorResponse.getStatus();
}
const auto& response = incomingCursorResponse.getValue();
auto& response = incomingCursorResponse.getValue();
if (const auto& cursorMetrics = response.getCursorMetrics()) {
CurOp::get(opCtx)->debug().additiveMetrics.aggregateCursorMetrics(*cursorMetrics);
}
@ -112,7 +112,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
return storePossibleCursor(opCtx,
shardId,
server,
response,
std::move(response),
requestedNss,
std::move(executor),
cursorManager,
@ -124,7 +124,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
const ShardId& shardId,
const HostAndPort& server,
const CursorResponse& incomingCursorResponse,
CursorResponse&& incomingCursorResponse,
const NamespaceString& requestedNss,
std::shared_ptr<executor::TaskExecutor> executor,
ClusterCursorManager* cursorManager,
@ -199,7 +199,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
CursorResponse outgoingCursorResponse(requestedNss,
clusterCursorId.getValue(),
incomingCursorResponse.getBatch(),
incomingCursorResponse.releaseBatch(),
incomingCursorResponse.getAtClusterTime(),
incomingCursorResponse.getPostBatchResumeToken());
return outgoingCursorResponse.toBSON(CursorResponse::ResponseType::InitialResponse);

View File

@ -38,7 +38,6 @@
#include "mongo/db/auth/privilege.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/query/tailable_mode.h"
#include "mongo/db/query/tailable_mode_gen.h"
#include "mongo/db/shard_id.h"
#include "mongo/executor/task_executor.h"
@ -106,7 +105,7 @@ StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
StatusWith<BSONObj> storePossibleCursor(OperationContext* opCtx,
const ShardId& shardId,
const HostAndPort& server,
const CursorResponse& incomingCursorResponse,
CursorResponse&& incomingCursorResponse,
const NamespaceString& requestedNss,
std::shared_ptr<executor::TaskExecutor> executor,
ClusterCursorManager* cursorManager,