From: liuhong Date: Fri, 20 Jan 2023 13:02:24 +0000 (+0800) Subject: rgw: add bucket notification cache X-Git-Tag: v19.0.0~1582^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6de6fd851aefd4118504170b9df214534d772c1e;p=ceph.git rgw: add bucket notification cache Bucket notification supports reading the rule configuration from the cache first, rather than directly from the bottom layer Signed-off-by: liuhong --- diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 3f2332db482ef..db546a3ca68f9 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -1051,6 +1051,7 @@ void RGWRados::finalize() delete binfo_cache; delete obj_tombstone_cache; + delete topic_cache; if (d3n_data_cache) delete d3n_data_cache; @@ -1281,6 +1282,9 @@ int RGWRados::init_complete(const DoutPrefixProvider *dpp) binfo_cache = new RGWChainedCacheImpl; binfo_cache->init(svc.cache); + topic_cache = new RGWChainedCacheImpl; + topic_cache->init(svc.cache); + lc = new RGWLC(); lc->initialize(cct, this->driver); diff --git a/src/rgw/driver/rados/rgw_rados.h b/src/rgw/driver/rados/rgw_rados.h index cc118f37dc724..043e9569e8163 100644 --- a/src/rgw/driver/rados/rgw_rados.h +++ b/src/rgw/driver/rados/rgw_rados.h @@ -39,6 +39,7 @@ #include "common/ceph_mutex.h" #include "rgw_cache.h" #include "rgw_sal_fwd.h" +#include "rgw_pubsub.h" struct D3nDataCache; @@ -319,6 +320,12 @@ struct bucket_info_entry { std::map attrs; }; +struct pubsub_bucket_topics_entry { + rgw_pubsub_bucket_topics info; + RGWObjVersionTracker objv_tracker; + real_time mtime; +}; + struct tombstone_entry; template @@ -426,6 +433,9 @@ protected: tombstone_cache_t* obj_tombstone_cache{nullptr}; + using RGWChainedCacheImpl_bucket_topics_entry = RGWChainedCacheImpl; + RGWChainedCacheImpl_bucket_topics_entry* topic_cache{nullptr}; + librados::IoCtx gc_pool_ctx; // .rgw.gc librados::IoCtx lc_pool_ctx; // .rgw.lc librados::IoCtx objexp_pool_ctx; @@ -1365,6 +1375,8 @@ public: ceph::real_time *pmtime, optional_yield y, const DoutPrefixProvider *dpp, std::map *pattrs = NULL); + RGWChainedCacheImpl_bucket_topics_entry *get_topic_cache() { return topic_cache; } + // Returns 0 on successful refresh. Returns error code if there was // an error or the version stored on the OSD is the same as that // presented in the BucketInfo structure. diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index fb34ae25aa8ff..bed3fbfae01da 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -59,6 +59,7 @@ #include "services/svc_zone_utils.h" #include "services/svc_role_rados.h" #include "services/svc_user.h" +#include "services/svc_sys_obj_cache.h" #include "cls/rgw/cls_rgw_client.h" #include "rgw_pubsub.h" @@ -1033,13 +1034,22 @@ std::string RadosBucket::topics_oid() const { int RadosBucket::read_topics(rgw_pubsub_bucket_topics& notifications, RGWObjVersionTracker* objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) { + // read from cache + auto cache = store->getRados()->get_topic_cache(); + const std::string key = store->svc()->zone->get_zone_params().log_pool.to_str() + topics_oid(); + if (auto e = cache->find(key)) { + notifications = e->info; + return 0; + } + bufferlist bl; + rgw_cache_entry_info cache_info; const int ret = rgw_get_system_obj(store->svc()->sysobj, store->svc()->zone->get_zone_params().log_pool, topics_oid(), bl, - objv_tracker, - nullptr, y, dpp, nullptr); + objv_tracker, nullptr, + y, dpp, nullptr, &cache_info); if (ret < 0) { return ret; } @@ -1053,6 +1063,11 @@ int RadosBucket::read_topics(rgw_pubsub_bucket_topics& notifications, return -EIO; } + pubsub_bucket_topics_entry e; + e.info = notifications; + if (!cache->put(dpp, store->getRados()->svc.cache, key, &e, { &cache_info })) { + ldpp_dout(dpp, 10) << "couldn't put bucket topics cache entry" << dendl; + } return 0; }