diff options
Diffstat (limited to 'src/mongo/db/commands/getmore_cmd.cpp')
| -rw-r--r-- | src/mongo/db/commands/getmore_cmd.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index 8d7510a7e2f..b3c00996ec6 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -431,6 +431,7 @@ public: auto&& [stats, _] = explainer.getWinningPlanStats(ExplainOptions::Verbosity::kExecStats); LOGV2_WARNING(20478, + "getMore command executor error: {error}, stats: {stats}, cmd: {cmd}", "getMore command executor error", "error"_attr = exception.toStatus(), "stats"_attr = redact(stats), @@ -616,6 +617,7 @@ public: options.atClusterTime = repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime(); } CursorResponseBuilder nextBatch(reply, options); + BSONObj obj; std::uint64_t numResults = 0; ResourceConsumption::DocumentUnitCounter docUnitsReturned; @@ -632,7 +634,9 @@ public: // Use the commit point of the last batch for exhaust cursors. lastKnownCommittedOpTime = cursorPin->getLastKnownCommittedOpTime(); } - clientsLastKnownCommittedOpTime(opCtx) = lastKnownCommittedOpTime; + if (lastKnownCommittedOpTime) { + clientsLastKnownCommittedOpTime(opCtx) = lastKnownCommittedOpTime.get(); + } awaitDataState(opCtx).shouldWaitForInserts = true; } @@ -695,19 +699,10 @@ public: cursorPin->setLeftoverMaxTimeMicros(opCtx->getRemainingMaxTimeMicros()); - if (opCtx->isExhaust() && clientsLastKnownCommittedOpTime(opCtx)) { - // Update the cursor's lastKnownCommittedOpTime to the current - // lastCommittedOpTime. The lastCommittedOpTime now may be staler than the - // actual lastCommittedOpTime returned in the metadata of this latest batch (see - // appendReplyMetadata). As a result, we may sometimes return more empty - // batches than we need to. But it is fine to be conservative in this. + if (opCtx->isExhaust() && !clientsLastKnownCommittedOpTime(opCtx).isNull()) { + // Set the commit point of the latest batch. auto replCoord = repl::ReplicationCoordinator::get(opCtx); - auto myLastCommittedOpTime = replCoord->getLastCommittedOpTime(); - auto clientsLastKnownCommittedOpTime = cursorPin->getLastKnownCommittedOpTime(); - if (!clientsLastKnownCommittedOpTime.has_value() || - clientsLastKnownCommittedOpTime.value() < myLastCommittedOpTime) { - cursorPin->setLastKnownCommittedOpTime(myLastCommittedOpTime); - } + cursorPin->setLastKnownCommittedOpTime(replCoord->getLastCommittedOpTime()); } } else { curOp->debug().cursorExhausted = true; @@ -719,9 +714,12 @@ public: // documents. auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); metricsCollector.incrementDocUnitsReturned(docUnitsReturned); - curOp->debug().additiveMetrics.nBatches = 1; - curOp->setEndOfOpMetrics(numResults); - collectQueryStatsMongod(opCtx, cursorPin); + cursorPin->incNReturnedSoFar(numResults); + cursorPin->incNBatches(); + + // Ensure log and profiler include the number of results returned in this getMore's + // response batch. + curOp->debug().nreturned = numResults; if (respondWithId) { cursorDeleter.dismiss(); |
