diff options
author | Benety Goh <benety@mongodb.com> | 2022-08-26 08:08:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-26 13:06:53 +0000 |
commit | cc3ae631bce7943fbda5182ff3b9d93d1125be40 (patch) | |
tree | ff8dd8dc8b6f0926d54c2b551c9d3fa99c27198f /src/mongo/db/ttl_collection_cache_test.cpp | |
parent | acf81f84dabf486f74a84b99f04cd17efa35424f (diff) | |
download | mongo-cc3ae631bce7943fbda5182ff3b9d93d1125be40.tar.gz |
SERVER-68477 include 'expireAfterSeconds' type information when registering TTL indexes with the TTLCollectionCache
Diffstat (limited to 'src/mongo/db/ttl_collection_cache_test.cpp')
-rw-r--r-- | src/mongo/db/ttl_collection_cache_test.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/mongo/db/ttl_collection_cache_test.cpp b/src/mongo/db/ttl_collection_cache_test.cpp index 4f598b3736c..747d1371887 100644 --- a/src/mongo/db/ttl_collection_cache_test.cpp +++ b/src/mongo/db/ttl_collection_cache_test.cpp @@ -39,9 +39,9 @@ TEST(TTLCollectionCacheTest, Basic) { auto uuidCollA = UUID::gen(); auto uuidCollB = UUID::gen(); - auto infoIndexA1 = TTLCollectionCache::Info{"collA_ttl_1"}; + auto infoIndexA1 = TTLCollectionCache::Info{"collA_ttl_1", /*isExpireAfterSecondsNaN=*/false}; auto infoClusteredA = TTLCollectionCache::Info{TTLCollectionCache::ClusteredId{}}; - auto infoIndexB1 = TTLCollectionCache::Info("collB_ttl_1"); + auto infoIndexB1 = TTLCollectionCache::Info("collB_ttl_1", /*isExpireAfterSecondsNaN=*/true); // Confirm registerTTLInfo() behavior using getTTLInfo(). cache.registerTTLInfo(uuidCollA, infoIndexA1); @@ -52,36 +52,45 @@ TEST(TTLCollectionCacheTest, Basic) { ASSERT_EQ(infos.size(), 2U); ASSERT_EQ(infos.count(uuidCollA), 1U); ASSERT_EQ(infos[uuidCollA].size(), 2U); - auto indexNameA = stdx::get_if<TTLCollectionCache::IndexName>(&infos[uuidCollA][0]); - ASSERT(indexNameA); - ASSERT_EQ(*indexNameA, "collA_ttl_1"); - ASSERT(stdx::get_if<TTLCollectionCache::ClusteredId>(&infos[uuidCollA][1])); + ASSERT_FALSE(infos[uuidCollA][0].isClustered()); + ASSERT_EQ(infos[uuidCollA][0].getIndexName(), "collA_ttl_1"); + ASSERT_FALSE(infos[uuidCollA][0].isExpireAfterSecondsNaN()); + ASSERT(infos[uuidCollA][1].isClustered()); ASSERT_EQ(infos.count(uuidCollB), 1U); ASSERT_EQ(infos[uuidCollB].size(), 1U); - auto indexNameB = stdx::get_if<TTLCollectionCache::IndexName>(&infos[uuidCollB][0]); - ASSERT(indexNameB); - ASSERT_EQ(*indexNameB, "collB_ttl_1"); + ASSERT_FALSE(infos[uuidCollB][0].isClustered()); + ASSERT_EQ(infos[uuidCollB][0].getIndexName(), "collB_ttl_1"); + ASSERT(infos[uuidCollB][0].isExpireAfterSecondsNaN()); + + // Check that we can reset '_isExpireAfterSecondsNaN()' on the TTL index. + cache.unsetTTLIndexExpireAfterSecondsNaN(uuidCollB, infoIndexB1.getIndexName()); + infos = cache.getTTLInfos(); + ASSERT_EQ(infos.size(), 2U); + ASSERT_EQ(infos.count(uuidCollB), 1U); + ASSERT_EQ(infos[uuidCollB].size(), 1U); + ASSERT_EQ(infos[uuidCollB][0].getIndexName(), "collB_ttl_1"); + ASSERT_FALSE(infos[uuidCollB][0].isExpireAfterSecondsNaN()); // Check deregisterTTLInfo(). TTLCollectionCache should clean up // UUIDs that no longer have any TTL infos registered. - cache.deregisterTTLInfo(uuidCollB, infoIndexB1); + cache.deregisterTTLIndexByName(uuidCollB, infoIndexB1.getIndexName()); infos = cache.getTTLInfos(); ASSERT_EQ(infos.size(), 1U); ASSERT_EQ(infos.count(uuidCollA), 1U); ASSERT_EQ(infos[uuidCollA].size(), 2U); // Remove info for TTL index on collection A. - cache.deregisterTTLInfo(uuidCollA, infoIndexA1); + cache.deregisterTTLIndexByName(uuidCollA, infoIndexA1.getIndexName()); infos = cache.getTTLInfos(); ASSERT_EQ(infos.size(), 1U); ASSERT_EQ(infos.count(uuidCollA), 1U); ASSERT_EQ(infos[uuidCollA].size(), 1U); - ASSERT(stdx::get_if<TTLCollectionCache::ClusteredId>(&infos[uuidCollA][0])); + ASSERT(infos[uuidCollA][0].isClustered()); // Remove clustered info for collection A. - cache.deregisterTTLInfo(uuidCollA, infoClusteredA); + cache.deregisterTTLClusteredIndex(uuidCollA); infos = cache.getTTLInfos(); ASSERT_EQ(infos.size(), 0U); } |