summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/collection_catalog_test.cpp
diff options
context:
space:
mode:
authorWill Buerger <will.buerger@mongodb.com>2022-11-02 20:53:54 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-02 21:41:40 +0000
commita29be1cf33df71c62ebbcc55ec1c1d870c46e297 (patch)
tree9a86950050faca6ac45dde17f5cf73c447d19a54 /src/mongo/db/catalog/collection_catalog_test.cpp
parentfc1e90f1089002b92f9f03969efde84fc111492f (diff)
downloadmongo-a29be1cf33df71c62ebbcc55ec1c1d870c46e297.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.cpp42
1 files changed, 42 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..70b96c652fe 100644
--- a/src/mongo/db/catalog/collection_catalog_test.cpp
+++ b/src/mongo/db/catalog/collection_catalog_test.cpp
@@ -2388,5 +2388,47 @@ 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.
+ auto preIndexColl =
+ CollectionCatalog::get(opCtx.get())->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