diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-03-22 17:17:21 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-03-28 14:15:11 -0400 |
commit | b5f78884606ba87e5a1742e8dd19bbe2e03f709d (patch) | |
tree | 2678ce8730ccefb31ff756065bf79ade9cb6ecf7 /src/mongo/db/views | |
parent | 00afe420f0eccb4204c5a235049385a1189e9c78 (diff) | |
download | mongo-b5f78884606ba87e5a1742e8dd19bbe2e03f709d.tar.gz |
SERVER-39519 Create/drop view now only takes database IX lock
Diffstat (limited to 'src/mongo/db/views')
-rw-r--r-- | src/mongo/db/views/durable_view_catalog.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/views/view_catalog.cpp | 18 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp index 24a23b928e9..f32283bad27 100644 --- a/src/mongo/db/views/durable_view_catalog.cpp +++ b/src/mongo/db/views/durable_view_catalog.cpp @@ -138,8 +138,12 @@ Status DurableViewCatalogImpl::iterate(OperationContext* opCtx, Callback callbac void DurableViewCatalogImpl::upsert(OperationContext* opCtx, const NamespaceString& name, const BSONObj& view) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_X)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_IX)); + dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); + NamespaceString systemViewsNs(_db->getSystemViewsName()); + dassert(opCtx->lockState()->isCollectionLockedForMode(systemViewsNs, MODE_X)); + Collection* systemViews = _db->getCollection(opCtx, systemViewsNs); invariant(systemViews); @@ -164,8 +168,12 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx, } void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceString& name) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_X)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_IX)); + dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); + Collection* systemViews = _db->getCollection(opCtx, _db->getSystemViewsName()); + dassert(opCtx->lockState()->isCollectionLockedForMode(systemViews->ns(), MODE_X)); + if (!systemViews) return; const bool requireIndex = false; diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp index 08dba9ada81..c932c365983 100644 --- a/src/mongo/db/views/view_catalog.cpp +++ b/src/mongo/db/views/view_catalog.cpp @@ -146,6 +146,11 @@ Status ViewCatalog::_createOrUpdateView(WithLock lk, const NamespaceString& viewOn, const BSONArray& pipeline, std::unique_ptr<CollatorInterface> collator) { + invariant(opCtx->lockState()->isDbLockedForMode(viewName.db(), MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode( + NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); + _requireValidCatalog(lk, opCtx); // Build the BSON definition for this view to be saved in the durable view catalog. If the @@ -329,6 +334,12 @@ Status ViewCatalog::createView(OperationContext* opCtx, const NamespaceString& viewOn, const BSONArray& pipeline, const BSONObj& collation) { + + invariant(opCtx->lockState()->isDbLockedForMode(viewName.db(), MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode( + NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); + stdx::lock_guard<stdx::mutex> lk(_mutex); if (viewName.db() != viewOn.db()) @@ -359,6 +370,8 @@ Status ViewCatalog::modifyView(OperationContext* opCtx, const NamespaceString& viewName, const NamespaceString& viewOn, const BSONArray& pipeline) { + invariant(opCtx->lockState()->isDbLockedForMode(viewName.db(), MODE_X)); + stdx::lock_guard<stdx::mutex> lk(_mutex); if (viewName.db() != viewOn.db()) @@ -388,6 +401,11 @@ Status ViewCatalog::modifyView(OperationContext* opCtx, } Status ViewCatalog::dropView(OperationContext* opCtx, const NamespaceString& viewName) { + invariant(opCtx->lockState()->isDbLockedForMode(viewName.db(), MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); + invariant(opCtx->lockState()->isCollectionLockedForMode( + NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); + stdx::lock_guard<stdx::mutex> lk(_mutex); _requireValidCatalog(lk, opCtx); |