]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: BucketTrimManager implements BucketChangeObserver
authorCasey Bodley <cbodley@redhat.com>
Fri, 1 Sep 2017 14:57:41 +0000 (10:57 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 10 Nov 2017 18:23:00 +0000 (13:23 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_sync_log_trim.cc
src/rgw/rgw_sync_log_trim.h

index 315288edce1b5f3ccde060438b457c37216a0bb5..cd177dc5747459ea00e302cb10ad8c8119c7ea44 100644 (file)
@@ -13,6 +13,9 @@
  * Foundation.  See file COPYING.
  */
 
+#include <mutex>
+
+#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<std::string, int>;
 
 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<std::mutex> lock(impl->mutex);
+  impl->counter.insert(bucket.to_string());
+}
+
 } // namespace rgw
index fb21ac7d9decf263d31318d44240f87038e599e2..2819eeb0bc4f667de32bc39ad66099c3a63a62c0 100644 (file)
 #define RGW_SYNC_LOG_TRIM_H
 
 #include <memory>
+#include <boost/utility/string_view.hpp>
 
 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> 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