summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/list_databases.cpp
diff options
context:
space:
mode:
authorYuhong Zhang <danielzhangyh@gmail.com>2021-10-07 20:58:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-07 23:13:12 +0000
commit749d18149e33b9bb1df781505daf6fdea6f34ce0 (patch)
tree7514dbe64e67d3e994cd8742b52e2e858d5cf024 /src/mongo/db/commands/list_databases.cpp
parenta8c4b5bbf7b838a639b7133cfcad5a92a65041cc (diff)
downloadmongo-749d18149e33b9bb1df781505daf6fdea6f34ce0.tar.gz
SERVER-57357 Make `listDatabases` a lock-free operation
Diffstat (limited to 'src/mongo/db/commands/list_databases.cpp')
-rw-r--r--src/mongo/db/commands/list_databases.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index e328ebc5237..8196241368f 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -30,12 +30,14 @@
#include "mongo/platform/basic.h"
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/list_databases_gen.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop_failpoint_helpers.h"
+#include "mongo/db/db_raii.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context.h"
@@ -138,7 +140,7 @@ public:
for (const auto& itemName : dbNames) {
if (authorizedDatabases &&
!as->isAuthorizedForAnyActionOnAnyResourceInDB(itemName)) {
- // We don't have listDatabases on the cluser or find on this database.
+ // We don't have listDatabases on the cluster or find on this database.
continue;
}
@@ -151,9 +153,9 @@ public:
continue;
}
- AutoGetDb autoDb(opCtx, itemName, MODE_IS);
- auto* const db = autoDb.getDb();
- if (!db) {
+ AutoGetDbForReadMaybeLockFree lockFreeReadBlock(opCtx, itemName);
+ // The database could have been dropped since we called 'listDatabases()' above.
+ if (!DatabaseHolder::get(opCtx)->dbExists(opCtx, itemName)) {
continue;
}