From 5ceb7cb998b505d2fe0cd98b534a918424e4d809 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 19 Dec 2017 16:47:09 -0500 Subject: [PATCH] rgw: Add expiration in the object cache We had it in the chained caches, but it doesn't do much good if they just fetch objects out of the object cache. Fixes: http://tracker.ceph.com/issues/22517 Signed-off-by: Adam C. Emerson (cherry picked from commit 82a7e6ca31b416a7f0e41b5fda4c403d1d6be947) --- src/rgw/rgw_cache.cc | 9 ++++++--- src/rgw/rgw_cache.h | 14 +++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc index 31aff871165..e9b12875be1 100644 --- a/src/rgw/rgw_cache.cc +++ b/src/rgw/rgw_cache.cc @@ -17,10 +17,13 @@ int ObjectCache::get(string& name, ObjectCacheInfo& info, uint32_t mask, rgw_cac return -ENOENT; } - map::iterator iter = cache_map.find(name); - if (iter == cache_map.end()) { + auto iter = cache_map.find(name); + if (iter == cache_map.end() || + (expiry.count() && + (ceph::coarse_mono_clock::now() - iter->second.info.time_added) > expiry)) { ldout(cct, 10) << "cache get: name=" << name << " : miss" << dendl; - if(perfcounter) perfcounter->inc(l_rgw_cache_miss); + if (perfcounter) + perfcounter->inc(l_rgw_cache_miss); return -ENOENT; } diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 6bc9ef14903..1c03c271060 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -49,16 +49,17 @@ struct ObjectMetaInfo { WRITE_CLASS_ENCODER(ObjectMetaInfo) struct ObjectCacheInfo { - int status; - uint32_t flags; - uint64_t epoch; + int status = 0; + uint32_t flags = 0; + uint64_t epoch = 0; bufferlist data; map xattrs; map rm_xattrs; ObjectMetaInfo meta; - obj_version version; + obj_version version = {}; + ceph::coarse_mono_time time_added = ceph::coarse_mono_clock::now(); - ObjectCacheInfo() : status(0), flags(0), epoch(0), version() {} + ObjectCacheInfo() = default; void encode(bufferlist& bl) const { ENCODE_START(5, 3, bl); @@ -146,6 +147,7 @@ class ObjectCache { list chained_cache; bool enabled; + ceph::timespan expiry; void touch_lru(string& name, ObjectCacheEntry& entry, std::list::iterator& lru_iter); void remove_lru(string& name, std::list::iterator& lru_iter); @@ -159,6 +161,8 @@ public: void set_ctx(CephContext *_cct) { cct = _cct; lru_window = cct->_conf->rgw_cache_lru_size / 2; + expiry = std::chrono::seconds(cct->_conf->get_val( + "rgw_cache_expiry_interval")); } bool chain_cache_entry(list& cache_info_entries, RGWChainedCache::Entry *chained_entry); -- 2.47.3