diff options
Diffstat (limited to 'src/mongo/db/commands/getmore_cmd.cpp')
| -rw-r--r-- | src/mongo/db/commands/getmore_cmd.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index b3c00996ec6..c699a3262e7 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -431,7 +431,6 @@ 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), @@ -617,7 +616,6 @@ public: options.atClusterTime = repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime(); } CursorResponseBuilder nextBatch(reply, options); - BSONObj obj; std::uint64_t numResults = 0; ResourceConsumption::DocumentUnitCounter docUnitsReturned; @@ -634,9 +632,7 @@ public: // Use the commit point of the last batch for exhaust cursors. lastKnownCommittedOpTime = cursorPin->getLastKnownCommittedOpTime(); } - if (lastKnownCommittedOpTime) { - clientsLastKnownCommittedOpTime(opCtx) = lastKnownCommittedOpTime.get(); - } + clientsLastKnownCommittedOpTime(opCtx) = lastKnownCommittedOpTime; awaitDataState(opCtx).shouldWaitForInserts = true; } @@ -699,10 +695,19 @@ public: cursorPin->setLeftoverMaxTimeMicros(opCtx->getRemainingMaxTimeMicros()); - if (opCtx->isExhaust() && !clientsLastKnownCommittedOpTime(opCtx).isNull()) { - // Set the commit point of the latest batch. + 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. auto replCoord = repl::ReplicationCoordinator::get(opCtx); - cursorPin->setLastKnownCommittedOpTime(replCoord->getLastCommittedOpTime()); + auto myLastCommittedOpTime = replCoord->getLastCommittedOpTime(); + auto clientsLastKnownCommittedOpTime = cursorPin->getLastKnownCommittedOpTime(); + if (!clientsLastKnownCommittedOpTime.has_value() || + clientsLastKnownCommittedOpTime.value() < myLastCommittedOpTime) { + cursorPin->setLastKnownCommittedOpTime(myLastCommittedOpTime); + } } } else { curOp->debug().cursorExhausted = true; |
