summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog_raii.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-07-31 15:26:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-07 13:32:12 +0000
commit9de175fb3776415e7237e6c0af4b76f518adc451 (patch)
tree56a22e0f57be9937d53deed8f76fdbc2502639c3 /src/mongo/db/catalog_raii.cpp
parent21d5a8e5bd822e71e5fb8feb2f9e71a7e8cf25f9 (diff)
downloadmongo-9de175fb3776415e7237e6c0af4b76f518adc451.tar.gz
SERVER-47885 Added lookupCollectionByXXXForRead interface to the Collection catalog that returns collection as shared_ptr<const Collection>
AutoGetCollectionForRead and AutoGetCollectionForReadCommand now uses this and holds the shared_ptr. They return the collection as const. Const correct various places to make this possible. Moved some logic from Collection destructors to deregister from the catalog as they may now be destroyed at a later point.
Diffstat (limited to 'src/mongo/db/catalog_raii.cpp')
-rw-r--r--src/mongo/db/catalog_raii.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index dd8591814ff..867296068e0 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -69,11 +69,13 @@ Database* AutoGetDb::ensureDbExists() {
return _db;
}
-AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
- const NamespaceStringOrUUID& nsOrUUID,
- LockMode modeColl,
- ViewMode viewMode,
- Date_t deadline)
+template <typename CatalogCollectionLookupT>
+AutoGetCollectionBase<CatalogCollectionLookupT>::AutoGetCollectionBase(
+ OperationContext* opCtx,
+ const NamespaceStringOrUUID& nsOrUUID,
+ LockMode modeColl,
+ AutoGetCollectionViewMode viewMode,
+ Date_t deadline)
: _autoDb(opCtx,
!nsOrUUID.dbname().empty() ? nsOrUUID.dbname() : nsOrUUID.nss()->db(),
isSharedLockMode(modeColl) ? MODE_IS : MODE_IX,
@@ -110,7 +112,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
if (!db)
return;
- _coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, _resolvedNss);
+ _coll = CatalogCollectionLookupT::lookupCollection(opCtx, _resolvedNss);
invariant(!nsOrUUID.uuid() || _coll,
str::stream() << "Collection for " << _resolvedNss.ns()
<< " disappeared after successufully resolving "
@@ -144,7 +146,17 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
_view = ViewCatalog::get(db)->lookup(opCtx, _resolvedNss.ns());
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "Namespace " << _resolvedNss.ns() << " is a view, not a collection",
- !_view || viewMode == kViewsPermitted);
+ !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted);
+}
+
+CatalogCollectionLookup::CollectionStorage CatalogCollectionLookup::lookupCollection(
+ OperationContext* opCtx, const NamespaceString& nss) {
+ return CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss);
+}
+
+CatalogCollectionLookupForRead::CollectionStorage CatalogCollectionLookupForRead::lookupCollection(
+ OperationContext* opCtx, const NamespaceString& nss) {
+ return CollectionCatalog::get(opCtx).lookupCollectionByNamespaceForRead(opCtx, nss);
}
LockMode fixLockModeForSystemDotViewsChanges(const NamespaceString& nss, LockMode mode) {
@@ -205,4 +217,7 @@ AutoGetOplog::AutoGetOplog(OperationContext* opCtx, OplogAccessMode mode, Date_t
_oplog = _oplogInfo->getCollection();
}
+template class AutoGetCollectionBase<CatalogCollectionLookup>;
+template class AutoGetCollectionBase<CatalogCollectionLookupForRead>;
+
} // namespace mongo