summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2022-01-04 22:12:09 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-04 23:12:47 +0000
commitfdca8a8d628d5480e3f552f86ce89aa0d234741f (patch)
treea15c2cd694b904f7ec6b8be69f3e11317c9fe988
parentf7ab9b6b8825cb09ce92ed4797b0ee75a49b5e22 (diff)
downloadmongo-fdca8a8d628d5480e3f552f86ce89aa0d234741f.tar.gz
SERVER-62101 Check whether the database was dropped before accessing the ViewCatalog in the aggregate command; and use a lock-free compatible collection lookup in ViewCatalog::resolveView()
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp13
-rw-r--r--src/mongo/db/views/view_catalog.cpp5
2 files changed, 14 insertions, 4 deletions
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index eba958157e3..ba8214138b8 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -696,9 +696,16 @@ Status runAggregate(OperationContext* opCtx,
// views, we use the request's collation.
auto timeSeriesCollator =
ctx->getView()->timeseries() ? request.getCollation() : boost::none;
- auto resolvedView = uassertStatusOK(DatabaseHolder::get(opCtx)
- ->getViewCatalog(opCtx, nss.db())
- ->resolveView(opCtx, nss, timeSeriesCollator));
+
+ // Check that the database/view catalog still exist, in case this is a lock-free
+ // operation. It's possible for a view to disappear after we release locks below, so
+ // it's safe to quit early if the view disappears while running lock-free.
+ auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, nss.db());
+ uassert(ErrorCodes::NamespaceNotFound,
+ str::stream() << "Namespace '" << nss << "' no longer exists",
+ viewCatalog);
+ auto resolvedView =
+ uassertStatusOK(viewCatalog->resolveView(opCtx, nss, timeSeriesCollator));
// With the view & collation resolved, we can relinquish locks.
ctx.reset();
diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp
index 57697266e3a..8558896cdf2 100644
--- a/src/mongo/db/views/view_catalog.cpp
+++ b/src/mongo/db/views/view_catalog.cpp
@@ -769,8 +769,11 @@ StatusWith<ResolvedView> ViewCatalog::resolveView(
resolvedNss = &view->viewOn();
if (view->timeseries()) {
+ // Use the lock-free collection lookup, to ensure compatibility with lock-free read
+ // operations.
auto tsCollection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, *resolvedNss);
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForRead(opCtx,
+ *resolvedNss);
uassert(6067201,
str::stream() << "expected time-series buckets collection " << *resolvedNss
<< " to exist",