From 238f0ef4a44481787fa36db99c78936480202d6f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 26 Oct 2018 16:20:05 -0700 Subject: [PATCH] rgw: chained cache shouldn't access service after it was unchained This fixes a cleanup ordering issue. We can now have the chained cache removed before and after the service is destructed. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_cache.cc | 8 ++++++++ src/rgw/rgw_cache.h | 3 +++ src/rgw/services/svc_sys_obj_cache.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc index a53940b2626..fe8ab51f539 100644 --- a/src/rgw/rgw_cache.cc +++ b/src/rgw/rgw_cache.cc @@ -329,8 +329,16 @@ void ObjectCache::unchain_cache(RGWChainedCache *cache) { for (; iter != chained_cache.end(); ++iter) { if (cache == *iter) { chained_cache.erase(iter); + cache->unregistered(); return; } } } +ObjectCache::~ObjectCache() +{ + for (auto cache : chained_cache) { + cache->unregistered(); + } +} + diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 60087f92ea4..b0696237fe6 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -132,6 +132,7 @@ public: virtual void chain_cb(const string& key, void *data) = 0; virtual void invalidate(const string& key) = 0; virtual void invalidate_all() = 0; + virtual void unregistered() {} struct Entry { RGWChainedCache *cache; @@ -173,8 +174,10 @@ class ObjectCache { void invalidate_lru(ObjectCacheEntry& entry); void do_invalidate_all(); + public: ObjectCache() : lru_size(0), lru_counter(0), lru_window(0), lock("ObjectCache"), cct(NULL), enabled(false) { } + ~ObjectCache(); int get(const std::string& name, ObjectCacheInfo& bl, uint32_t mask, rgw_cache_entry_info *cache_info); std::optional get(const std::string& name) { std::optional info{std::in_place}; diff --git a/src/rgw/services/svc_sys_obj_cache.h b/src/rgw/services/svc_sys_obj_cache.h index 7b986fe5089..fefbc298cd8 100644 --- a/src/rgw/services/svc_sys_obj_cache.h +++ b/src/rgw/services/svc_sys_obj_cache.h @@ -112,6 +112,10 @@ public: svc->unregister_chained_cache(this); } + void unregistered() override { + svc = nullptr; + } + void init(RGWSI_SysObj_Cache *_svc) { if (!_svc) { return; -- 2.39.5