summaryrefslogtreecommitdiff
path: root/src/mongo/db/ttl_collection_cache.cpp
diff options
context:
space:
mode:
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 27d1335510c..86fcc682068 100644
--- a/src/mongo/db/ttl_collection_cache.cpp
+++ b/src/mongo/db/ttl_collection_cache.cpp
@@ -63,13 +63,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()) {
@@ -77,6 +94,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;