From 54364b43839b4b181ed41fb98205f3d7d5831923 Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Mon, 9 Nov 2020 10:39:05 -0500 Subject: SERVER-52698 Protect ViewCatalog with mutex also in rollback handlers --- src/mongo/db/views/view_catalog.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp index 5fd9116f931..98931116973 100644 --- a/src/mongo/db/views/view_catalog.cpp +++ b/src/mongo/db/views/view_catalog.cpp @@ -226,8 +226,12 @@ Status ViewCatalog::_createOrUpdateView(WithLock lk, catalog.addResource(viewRid, viewName.ns()); opCtx->recoveryUnit()->onRollback([this, viewName, opCtx, viewRid]() { - this->_viewMap.erase(viewName.ns()); - this->_viewGraphNeedsRefresh = true; + { + stdx::lock_guard lk(_mutex); + this->_viewMap.erase(viewName.ns()); + this->_viewGraphNeedsRefresh = true; + } + CollectionCatalog& catalog = CollectionCatalog::get(opCtx); catalog.removeResource(viewRid, viewName.ns()); }); @@ -452,7 +456,11 @@ Status ViewCatalog::modifyView(OperationContext* opCtx, ViewDefinition savedDefinition = *viewPtr; opCtx->recoveryUnit()->onRollback([this, viewName, savedDefinition, opCtx]() { - this->_viewMap[viewName.ns()] = std::make_shared(savedDefinition); + auto definition = std::make_shared(savedDefinition); + { + stdx::lock_guard lk(_mutex); + this->_viewMap[viewName.ns()] = std::move(definition); + } auto viewRid = ResourceId(RESOURCE_COLLECTION, viewName.ns()); CollectionCatalog& catalog = CollectionCatalog::get(opCtx); catalog.addResource(viewRid, viewName.ns()); -- cgit v1.2.1