summaryrefslogtreecommitdiff
path: root/src/mongo/db/ttl_collection_cache.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-26 08:08:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-26 13:06:53 +0000
commitcc3ae631bce7943fbda5182ff3b9d93d1125be40 (patch)
treeff8dd8dc8b6f0926d54c2b551c9d3fa99c27198f /src/mongo/db/ttl_collection_cache.cpp
parentacf81f84dabf486f74a84b99f04cd17efa35424f (diff)
downloadmongo-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.cpp')
-rw-r--r--src/mongo/db/ttl_collection_cache.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/mongo/db/ttl_collection_cache.cpp b/src/mongo/db/ttl_collection_cache.cpp
index 7343afddfea..43d55a46301 100644
--- a/src/mongo/db/ttl_collection_cache.cpp
+++ b/src/mongo/db/ttl_collection_cache.cpp
@@ -65,13 +65,30 @@ void TTLCollectionCache::registerTTLInfo(UUID uuid, const Info& info) {
}
}
-void TTLCollectionCache::deregisterTTLInfo(UUID uuid, const Info& info) {
+void TTLCollectionCache::_deregisterTTLInfo(UUID uuid, const Info& info) {
stdx::lock_guard<Latch> lock(_ttlInfosLock);
auto infoIt = _ttlInfos.find(uuid);
fassert(5400705, infoIt != _ttlInfos.end());
auto& [_, infoVec] = *infoIt;
- auto iter = std::find(infoVec.begin(), infoVec.end(), info);
+ auto iter = infoVec.begin();
+ if (info.isClustered()) {
+ // For clustered collections, we cannot have more than one clustered info per UUID.
+ // All we have to do here is ensure that the 'info' to search for is also 'clustered'.
+ iter = std::find_if(infoVec.begin(), infoVec.end(), [](const auto& infoVecItem) {
+ return infoVecItem.isClustered();
+ });
+ } else {
+ // For TTL indexes, we search non-clustered TTL info items on the index name only.
+ auto indexName = info.getIndexName();
+ iter = std::find_if(infoVec.begin(), infoVec.end(), [&indexName](const auto& infoVecItem) {
+ if (infoVecItem.isClustered()) {
+ return false;
+ }
+ return indexName == infoVecItem.getIndexName();
+ });
+ }
+
fassert(40220, iter != infoVec.end());
infoVec.erase(iter);
if (infoVec.empty()) {
@@ -79,6 +96,31 @@ void TTLCollectionCache::deregisterTTLInfo(UUID uuid, const Info& info) {
}
}
+void TTLCollectionCache::deregisterTTLIndexByName(UUID uuid, const IndexName& indexName) {
+ _deregisterTTLInfo(std::move(uuid), TTLCollectionCache::Info{indexName, /*unusedSpec=*/{}});
+}
+
+void TTLCollectionCache::deregisterTTLClusteredIndex(UUID uuid) {
+ _deregisterTTLInfo(std::move(uuid),
+ TTLCollectionCache::Info{TTLCollectionCache::ClusteredId{}});
+}
+
+void TTLCollectionCache::unsetTTLIndexExpireAfterSecondsNaN(UUID uuid, const IndexName& indexName) {
+ stdx::lock_guard<Latch> lock(_ttlInfosLock);
+ auto infoIt = _ttlInfos.find(uuid);
+ if (infoIt == _ttlInfos.end()) {
+ return;
+ }
+
+ auto&& infoVec = infoIt->second;
+ for (auto&& info : infoVec) {
+ if (!info.isClustered() && info.getIndexName() == indexName) {
+ info.unsetExpireAfterSecondsNaN();
+ break;
+ }
+ }
+}
+
TTLCollectionCache::InfoMap TTLCollectionCache::getTTLInfos() {
stdx::lock_guard<Latch> lock(_ttlInfosLock);
return _ttlInfos;