summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorKevin Albertson <kevin.albertson@10gen.com>2016-07-05 11:15:18 -0400
committerKevin Albertson <kevin.albertson@10gen.com>2016-07-19 13:57:58 -0400
commitd059552b998bd9f3ff0275016dff2df89a137b02 (patch)
treece58b37687b6f99b6b66740dcedc3325997b9bae /src/mongo/db/catalog
parente9201e5c46124472b941a1932dc8827a36487e5e (diff)
downloadmongo-d059552b998bd9f3ff0275016dff2df89a137b02.tar.gz
SERVER-24631: Add TTL collection namespace cache
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/collection_info_cache.cpp25
-rw-r--r--src/mongo/db/catalog/collection_info_cache.h4
2 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/collection_info_cache.cpp b/src/mongo/db/catalog/collection_info_cache.cpp
index fe2a15499dc..d5431bdb0eb 100644
--- a/src/mongo/db/catalog/collection_info_cache.cpp
+++ b/src/mongo/db/catalog/collection_info_cache.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/planner_ixselect.h"
#include "mongo/db/service_context.h"
+#include "mongo/db/ttl_collection_cache.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
@@ -55,6 +56,13 @@ CollectionInfoCache::CollectionInfoCache(Collection* collection)
_querySettings(new QuerySettings()),
_indexUsageTracker(getGlobalServiceContext()->getPreciseClockSource()) {}
+CollectionInfoCache::~CollectionInfoCache() {
+ // Necessary because the collection cache will not explicitly get updated upon database drop.
+ if (_hasTTLIndex) {
+ TTLCollectionCache& ttlCollectionCache = TTLCollectionCache::get(getGlobalServiceContext());
+ ttlCollectionCache.unregisterCollection(_collection->ns());
+ }
+}
const UpdateIndexData& CollectionInfoCache::getIndexKeys(OperationContext* txn) const {
// This requires "some" lock, and MODE_IS is an expression for that, for now.
@@ -66,12 +74,19 @@ const UpdateIndexData& CollectionInfoCache::getIndexKeys(OperationContext* txn)
void CollectionInfoCache::computeIndexKeys(OperationContext* txn) {
_indexedPaths.clear();
+ bool hadTTLIndex = _hasTTLIndex;
+ _hasTTLIndex = false;
+
IndexCatalog::IndexIterator i = _collection->getIndexCatalog()->getIndexIterator(txn, true);
while (i.more()) {
IndexDescriptor* descriptor = i.next();
if (descriptor->getAccessMethodName() != IndexNames::TEXT) {
BSONObj key = descriptor->keyPattern();
+ const BSONObj& infoObj = descriptor->infoObj();
+ if (infoObj.hasField("expireAfterSeconds")) {
+ _hasTTLIndex = true;
+ }
BSONObjIterator j(key);
while (j.more()) {
BSONElement e = j.next();
@@ -112,6 +127,16 @@ void CollectionInfoCache::computeIndexKeys(OperationContext* txn) {
}
}
+ TTLCollectionCache& ttlCollectionCache = TTLCollectionCache::get(getGlobalServiceContext());
+
+ if (_hasTTLIndex != hadTTLIndex) {
+ if (_hasTTLIndex) {
+ ttlCollectionCache.registerCollection(_collection->ns());
+ } else {
+ ttlCollectionCache.unregisterCollection(_collection->ns());
+ }
+ }
+
_keysComputed = true;
}
diff --git a/src/mongo/db/catalog/collection_info_cache.h b/src/mongo/db/catalog/collection_info_cache.h
index 4c5b67ed880..ea832633cd3 100644
--- a/src/mongo/db/catalog/collection_info_cache.h
+++ b/src/mongo/db/catalog/collection_info_cache.h
@@ -49,6 +49,8 @@ class CollectionInfoCache {
public:
CollectionInfoCache(Collection* collection);
+ ~CollectionInfoCache();
+
/**
* Get the PlanCache for this collection.
*/
@@ -130,6 +132,8 @@ private:
* when index composition changes.
*/
void rebuildIndexData(OperationContext* txn);
+
+ bool _hasTTLIndex = false;
};
} // namespace mongo