summaryrefslogtreecommitdiff
path: root/src/mongo/db/rs_local_client.cpp
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-02-24 08:53:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-15 12:11:20 +0000
commitd22d0058c4f02c7bcd7337af8b1058cac8e26e45 (patch)
treed0a338f144a375b536c0523591885d7bae4d6608 /src/mongo/db/rs_local_client.cpp
parent0914e8c70f51c10f84cfb0568975e06153901e04 (diff)
downloadmongo-d22d0058c4f02c7bcd7337af8b1058cac8e26e45.tar.gz
SERVER-54874: Ensure reading consistent config.collections and config.chunks when refreshing the CatalogCache
(cherry picked from commit 538cb2ff982aab2a60c4f3ab53eb1ba6d1acfeb9)
Diffstat (limited to 'src/mongo/db/rs_local_client.cpp')
-rw-r--r--src/mongo/db/rs_local_client.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/db/rs_local_client.cpp b/src/mongo/db/rs_local_client.cpp
index b1d8894d57a..975be198be0 100644
--- a/src/mongo/db/rs_local_client.cpp
+++ b/src/mongo/db/rs_local_client.cpp
@@ -156,4 +156,35 @@ StatusWith<Shard::QueryResponse> RSLocalClient::queryOnce(
}
}
+Status RSLocalClient::runAggregation(
+ OperationContext* opCtx,
+ const AggregateCommand& aggRequest,
+ std::function<bool(const std::vector<BSONObj>& batch)> callback) {
+ DBDirectClient client(opCtx);
+ auto cursor = uassertStatusOKWithContext(
+ DBClientCursor::fromAggregationRequest(
+ &client, aggRequest, true /* secondaryOk */, true /* useExhaust */),
+ "Failed to establish a cursor for aggregation");
+
+ while (cursor->more()) {
+ std::vector<BSONObj> batchDocs;
+ batchDocs.reserve(cursor->objsLeftInBatch());
+ while (cursor->moreInCurrentBatch()) {
+ batchDocs.emplace_back(cursor->nextSafe().getOwned());
+ }
+
+ try {
+ if (!callback(batchDocs)) {
+ break;
+ }
+ } catch (const DBException& ex) {
+ return ex
+ .toStatus(str::stream()
+ << "Exception while running aggregation retrieval of results callback");
+ }
+ }
+
+ return Status::OK();
+}
+
} // namespace mongo