diff options
| author | Allison Easton <allison.easton@mongodb.com> | 2024-08-16 22:38:43 +0200 |
|---|---|---|
| committer | MongoDB Bot <mongo-bot@mongodb.com> | 2024-08-16 21:28:31 +0000 |
| commit | bb94f26c22e9e0bd6869349df74c0cd698e069b4 (patch) | |
| tree | 17d7ecff2f54e21f91148720df430f4e488c031c | |
| parent | fe2c46714056f8ccaeadc7632992f23e4fb0266b (diff) | |
Revert "SERVER-82221: listCollections requests up to date information from the collection_catalog" (#26238)r8.0.0-rc18
GitOrigin-RevId: b7d9ec86f5429e1f7319465f42a70b58367edf05
| -rw-r--r-- | src/mongo/db/commands/list_collections.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index 5db8dc3e37a..1cb490877d6 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -391,12 +391,6 @@ public: auto ws = std::make_unique<WorkingSet>(); auto root = std::make_unique<QueuedDataStage>(expCtx.get(), ws.get()); - auto readTimestamp = - shard_role_details::getRecoveryUnit(opCtx)->getPointInTimeReadTimestamp(opCtx); - tassert(9089302, - "point in time catalog lookup for a collection list is not supported", - RecoveryUnit::ReadSource::kNoTimestamp == - shard_role_details::getRecoveryUnit(opCtx)->getTimestampReadSource()); if (DatabaseHolder::get(opCtx)->dbExists(opCtx, dbName)) { if (auto collNames = _getExactNameMatches(matcher.get())) { @@ -411,21 +405,26 @@ public: continue; } + // In case lock-free reads are disabled, we must be able to take a + // collection lock. + boost::optional<Lock::CollectionLock> clk; + if (!opCtx->isLockFreeReadsOp()) { + clk.emplace(opCtx, nss, MODE_IS); + } + auto collBson = [&] { - const Collection* collection = - catalog->establishConsistentCollection( - opCtx, nss, readTimestamp); - if (collection != nullptr) { + if (auto collection = + CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( + opCtx, nss)) { return buildCollectionBson( opCtx, collection, includePendingDrops, nameOnly); } - std::shared_ptr<const ViewDefinition> view = - catalog->lookupView(opCtx, nss); + auto view = catalog->lookupViewWithoutValidatingDurable(opCtx, nss); if (view && view->timeseries()) { - if (auto bucketsCollection = - catalog->establishConsistentCollection( - opCtx, view->viewOn(), readTimestamp)) { + if (auto bucketsCollection = CollectionCatalog::get(opCtx) + ->lookupCollectionByNamespace( + opCtx, view->viewOn())) { return buildTimeseriesBson(bucketsCollection, nameOnly); } else { // The buckets collection does not exist, so the time-series @@ -444,7 +443,7 @@ public: } } else { auto perCollectionWork = [&](const Collection* collection) { - if (collection->getTimeseriesOptions() && + if (collection && collection->getTimeseriesOptions() && !collection->ns().isDropPendingNamespace()) { auto viewNss = collection->ns().getTimeseriesViewNamespace(); auto view = @@ -479,10 +478,17 @@ public: return true; }; - std::vector<const Collection*> collections = - catalog->establishConsistentCollections(opCtx, dbName, readTimestamp); - for (const auto& collection : collections) { - perCollectionWork(collection); + // If we are lock-free we can just iterate over our collection catalog + // without + // needing to yield as we don't take any locks. + if (opCtx->isLockFreeReadsOp()) { + auto collectionCatalog = CollectionCatalog::get(opCtx); + for (auto&& coll : collectionCatalog->range(dbName)) { + perCollectionWork(coll); + } + } else { + mongo::catalog::forEachCollectionFromDb( + opCtx, dbName, MODE_IS, perCollectionWork); } } |
