summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Caplinger <christopher.caplinger@mongodb.com>2022-12-19 17:35:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-19 18:04:23 +0000
commitf1acb7641a790d9ef7d34461826c47370d6d2f97 (patch)
tree652177c9697a46db7d073896af8998677894ef33
parentb435e2a16ea387dea6afcac82b75c60c9197d690 (diff)
downloadmongo-f1acb7641a790d9ef7d34461826c47370d6d2f97.tar.gz
SERVER-72110: Use collection cursor directly instead of DBDirectClient
-rw-r--r--src/mongo/idl/SConscript1
-rw-r--r--src/mongo/idl/cluster_server_parameter_initializer.h26
2 files changed, 20 insertions, 7 deletions
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index ffc13c8d153..5f74cb263b0 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -36,6 +36,7 @@ env.Library(
'$BUILD_DIR/mongo/db/dbdirectclient',
'$BUILD_DIR/mongo/db/repl/replica_set_aware_service',
'$BUILD_DIR/mongo/db/server_base',
+ '$BUILD_DIR/mongo/db/shard_role',
],
)
diff --git a/src/mongo/idl/cluster_server_parameter_initializer.h b/src/mongo/idl/cluster_server_parameter_initializer.h
index 1d8597d2242..3b87f56dcd3 100644
--- a/src/mongo/idl/cluster_server_parameter_initializer.h
+++ b/src/mongo/idl/cluster_server_parameter_initializer.h
@@ -31,7 +31,7 @@
#include "mongo/platform/basic.h"
-#include "mongo/db/dbdirectclient.h"
+#include "mongo/db/db_raii.h"
#include "mongo/db/repl/replica_set_aware_service.h"
namespace mongo {
@@ -101,18 +101,30 @@ private:
StringData mode,
OnEntry onEntry,
const boost::optional<TenantId>& tenantId) try {
- std::vector<Status> failures;
- DBDirectClient client(opCtx);
+ // If the RecoveryUnit already had an open snapshot, keep the snapshot open. Otherwise
+ // abandon the snapshot when exiting the function.
+ ScopeGuard scopeGuard([&] { opCtx->recoveryUnit()->abandonSnapshot(); });
+ if (opCtx->recoveryUnit()->isActive()) {
+ scopeGuard.dismiss();
+ }
+
+ AutoGetCollectionForRead coll(opCtx, NamespaceString::makeClusterParametersNSS(tenantId));
+ if (!coll) {
+ return;
+ }
+
+ std::vector<Status> failures;
- FindCommandRequest findRequest{NamespaceString::makeClusterParametersNSS(tenantId)};
- client.find(std::move(findRequest), [&](BSONObj doc) {
+ auto cursor = coll->getCursor(opCtx);
+ for (auto doc = cursor->next(); doc; doc = cursor->next()) {
try {
- onEntry(opCtx, doc, mode, tenantId);
+ onEntry(opCtx, doc.get().data.toBson(), mode, tenantId);
} catch (const DBException& ex) {
failures.push_back(ex.toStatus());
}
- });
+ }
+
if (!failures.empty()) {
StringBuilder msg;
for (const auto& failure : failures) {