diff options
author | Will Buerger <will.buerger@mongodb.com> | 2022-11-07 19:31:13 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-07 20:30:45 +0000 |
commit | 6cdb5546daa6fd7cc93feac639f04925dcc7919b (patch) | |
tree | 6a41004d2db44a0b1c8c8bfd4737ff3d6d502576 /src/mongo/db/catalog/collection_catalog_test.cpp | |
parent | ac2d60233b700d69cc1ebe69a29a5ff54fe4fb25 (diff) | |
download | mongo-6cdb5546daa6fd7cc93feac639f04925dcc7919b.tar.gz |
SERVER-70424: Provide way to create collection instance from untimestamped storage snapshot
Diffstat (limited to 'src/mongo/db/catalog/collection_catalog_test.cpp')
-rw-r--r-- | src/mongo/db/catalog/collection_catalog_test.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp index 8710d807f73..7782e58e855 100644 --- a/src/mongo/db/catalog/collection_catalog_test.cpp +++ b/src/mongo/db/catalog/collection_catalog_test.cpp @@ -2388,5 +2388,49 @@ DEATH_TEST_F(CollectionCatalogTimestampTest, OpenCollectionInWriteUnitOfWork, "i CollectionCatalog::get(opCtx.get())->openCollection(opCtx.get(), nss, readTimestamp); } +TEST_F(CollectionCatalogTimestampTest, OpenCollectionNoTimestamp) { + RAIIServerParameterControllerForTest featureFlagController( + "featureFlagPointInTimeCatalogLookups", true); + + const NamespaceString nss("a.b"); + const Timestamp createCollectionTs = Timestamp(10, 10); + const Timestamp createIndexTs = Timestamp(20, 20); + const Timestamp readTimestamp = Timestamp(30, 30); + + createCollection(opCtx.get(), nss, createCollectionTs); + + // Fetch a collection instance after creation but before creating an index. Maintain a reference + // to the current catalog so the collection instance isn't invalidated when the snapshot is + // abandoned. + auto preIndexCatalog = CollectionCatalog::get(opCtx.get()); + auto preIndexColl = preIndexCatalog->lookupCollectionByNamespace(opCtx.get(), nss); + ASSERT(preIndexColl); + ASSERT_EQ(0, preIndexColl->getIndexCatalog()->numIndexesTotal()); + + createIndex(opCtx.get(), + nss, + BSON("v" << 2 << "name" + << "x_1" + << "key" << BSON("x" << 1)), + createIndexTs); + OneOffRead oor(opCtx.get(), readTimestamp); + Lock::GlobalLock globalLock(opCtx.get(), MODE_IS); + + // Open an instance of the latest collection by passing no timestamp. + auto coll = CollectionCatalog::get(opCtx.get())->openCollection(opCtx.get(), nss, boost::none); + ASSERT(coll); + ASSERT_EQ(1, coll->getIndexCatalog()->numIndexesTotal()); + + // Verify the CollectionCatalog returns the latest collection. + auto currentColl = + CollectionCatalog::get(opCtx.get())->lookupCollectionByNamespace(opCtx.get(), nss); + ASSERT(currentColl); + ASSERT_EQ(1, currentColl->getIndexCatalog()->numIndexesTotal()); + ASSERT_EQ(coll, currentColl); + ASSERT_NE(coll, preIndexColl); + + // Ensure the idents are shared between the up-to-date instances. + ASSERT_EQ(coll->getSharedIdent(), currentColl->getSharedIdent()); +} } // namespace } // namespace mongo |