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/repl/idempotency_test_fixture.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/mongo/db/repl/idempotency_test_fixture.cpp') diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index ca996de2692..571b5abedfe 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -324,7 +324,7 @@ OplogEntry IdempotencyTest::partialTxn(LogicalSessionId lsid, prevOpTime); } -std::string IdempotencyTest::computeDataHash(const Collection* collection) { +std::string IdempotencyTest::computeDataHash(const CollectionPtr& collection) { auto desc = collection->getIndexCatalog()->findIdIndex(_opCtx.get()); ASSERT_TRUE(desc); auto exec = InternalPlanner::indexScan(_opCtx.get(), @@ -375,7 +375,7 @@ std::vector IdempotencyTest::validateAllCollections() { CollectionState IdempotencyTest::validate(const NamespaceString& nss) { auto collUUID = [&]() -> OptionalCollectionUUID { AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss); - if (auto collection = autoColl.getCollection()) { + if (const auto& collection = autoColl.getCollection()) { return collection->uuid(); } return boost::none; @@ -388,8 +388,7 @@ CollectionState IdempotencyTest::validate(const NamespaceString& nss) { } { - AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss); - auto collection = autoColl.getCollection(); + AutoGetCollectionForReadCommand collection(_opCtx.get(), nss); if (!collection) { // Return a mostly default initialized CollectionState struct with exists set to false @@ -412,10 +411,9 @@ CollectionState IdempotencyTest::validate(const NamespaceString& nss) { ASSERT_TRUE(validateResults.valid); } - AutoGetCollectionForReadCommand autoColl(_opCtx.get(), nss); - auto collection = autoColl.getCollection(); + AutoGetCollectionForReadCommand collection(_opCtx.get(), nss); - std::string dataHash = computeDataHash(collection); + std::string dataHash = computeDataHash(collection.getCollection()); auto durableCatalog = DurableCatalog::get(_opCtx.get()); auto collectionOptions = -- cgit v1.2.1