From 2b82ab88982566114d1bb7667477b71c883b0799 Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Thu, 17 Sep 2020 17:09:19 -0400 Subject: SERVER-50984 Add CollectionPtr to replace usage of const Collection* It implements a yieldable interface that is used to re-load the Collection pointer from the catalog after a yield that released locks. With lock-free reads and copy-on-write on Collection instances releasing locks without notifying an AutoGetCollection at a higher level may cause its pointers to dangle if a MODE_X writer installs a new Collection instance in the catalog. CollectionPtr should be passed by const reference so a yield can notify all the way up. --- src/mongo/db/cloner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mongo/db/cloner.cpp') diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index b0f8954adc6..47e1e5601ad 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -156,7 +156,7 @@ struct Cloner::Fun { collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss); uassert(28594, str::stream() << "Collection " << nss << " dropped while cloning", - collection != nullptr); + collection); } BSONObj tmp = i.nextSafe(); @@ -367,7 +367,7 @@ Status Cloner::_createCollectionsForDb( opCtx->checkForInterrupt(); WriteUnitOfWork wunit(opCtx); - const Collection* collection = + CollectionPtr collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss); if (collection) { if (!params.shardedColl) { -- cgit v1.2.1