From b4249cc432b5b74e5c8f545bdc7daddbc9e60d23 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 1 Sep 2017 10:57:41 -0400 Subject: [PATCH] rgw: BucketTrimManager implements BucketChangeObserver Signed-off-by: Casey Bodley --- src/rgw/rgw_sync_log_trim.cc | 19 ++++++++++++++++++- src/rgw/rgw_sync_log_trim.h | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_sync_log_trim.cc b/src/rgw/rgw_sync_log_trim.cc index 315288edce1..cd177dc5747 100644 --- a/src/rgw/rgw_sync_log_trim.cc +++ b/src/rgw/rgw_sync_log_trim.cc @@ -13,6 +13,9 @@ * Foundation. See file COPYING. */ +#include + +#include "common/bounded_key_counter.h" #include "rgw_sync_log_trim.h" #define dout_subsys ceph_subsys_rgw @@ -21,6 +24,7 @@ #define dout_prefix (*_dout << "trim: ") using rgw::BucketTrimConfig; +using BucketChangeCounter = BoundedKeyCounter; namespace rgw { @@ -29,8 +33,15 @@ class BucketTrimManager::Impl { RGWRados *const store; const BucketTrimConfig config; + /// count frequency of bucket instance entries in the data changes log + BucketChangeCounter counter; + + /// protect data shared between data sync and trim threads + std::mutex mutex; + Impl(RGWRados *store, const BucketTrimConfig& config) - : store(store), config(config) + : store(store), config(config), + counter(config.counter_size) {} }; @@ -41,4 +52,10 @@ BucketTrimManager::BucketTrimManager(RGWRados *store, } BucketTrimManager::~BucketTrimManager() = default; +void BucketTrimManager::on_bucket_changed(const boost::string_view& bucket) +{ + std::lock_guard lock(impl->mutex); + impl->counter.insert(bucket.to_string()); +} + } // namespace rgw diff --git a/src/rgw/rgw_sync_log_trim.h b/src/rgw/rgw_sync_log_trim.h index fb21ac7d9de..2819eeb0bc4 100644 --- a/src/rgw/rgw_sync_log_trim.h +++ b/src/rgw/rgw_sync_log_trim.h @@ -17,14 +17,24 @@ #define RGW_SYNC_LOG_TRIM_H #include +#include class CephContext; class RGWRados; namespace rgw { +/// Interface to inform the trim process about which buckets are most active +struct BucketChangeObserver { + virtual ~BucketChangeObserver() = default; + + virtual void on_bucket_changed(const boost::string_view& bucket_instance) = 0; +}; + /// Configuration for BucketTrimManager struct BucketTrimConfig { + /// maximum number of buckets to track with BucketChangeObserver + size_t counter_size{0}; }; /// fill out the BucketTrimConfig from the ceph context @@ -34,12 +44,15 @@ void configure_bucket_trim(CephContext *cct, BucketTrimConfig& config); /// input: the frequency of entries read from the data changes log, and a global /// listing of the bucket.instance metadata. This allows us to trim active /// buckets quickly, while also ensuring that all buckets will eventually trim -class BucketTrimManager { +class BucketTrimManager : public BucketChangeObserver { class Impl; std::unique_ptr impl; public: BucketTrimManager(RGWRados *store, const BucketTrimConfig& config); ~BucketTrimManager(); + + /// increment a counter for the given bucket instance + void on_bucket_changed(const boost::string_view& bucket_instance) override; }; } // namespace rgw -- 2.39.5