]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: add BucketTrimPollCR for interval and lease logic
authorCasey Bodley <cbodley@redhat.com>
Fri, 1 Sep 2017 16:22:47 +0000 (12:22 -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 09017290dfd4ade3746acae7f7c488f03ce434e0..05b6e247ed6b4f0e4c80801ee7249e2a3abfdc39 100644 (file)
 
 #include "common/bounded_key_counter.h"
 #include "common/errno.h"
+#include "rgw_cr_rados.h"
 #include "rgw_rados.h"
 #include "rgw_sync_log_trim.h"
+
+#include <boost/asio/yield.hpp>
 #include "include/assert.h"
 
 #define dout_subsys ceph_subsys_rgw
@@ -263,6 +266,53 @@ class BucketTrimWatcher : public librados::WatchCtx2 {
 };
 
 
+class BucketTrimPollCR : public RGWCoroutine {
+  RGWRados *const store;
+  const BucketTrimConfig& config;
+  const rgw_raw_obj& obj;
+  const std::string name{"trim"}; //< lock name
+  const std::string cookie;
+
+ public:
+  BucketTrimPollCR(RGWRados *store, const BucketTrimConfig& config,
+                   const rgw_raw_obj& obj)
+    : RGWCoroutine(store->ctx()), store(store), config(config), obj(obj),
+      cookie(RGWSimpleRadosLockCR::gen_random_cookie(cct))
+  {}
+
+  int operate();
+};
+
+int BucketTrimPollCR::operate()
+{
+  reenter(this) {
+    for (;;) {
+      set_status("sleeping");
+      wait(utime_t{config.trim_interval_sec, 0});
+
+      // prevent others from trimming for our entire wait interval
+      set_status("acquiring trim lock");
+      yield call(new RGWSimpleRadosLockCR(store->get_async_rados(), store,
+                                          obj, name, cookie,
+                                          config.trim_interval_sec));
+      if (retcode < 0) {
+        ldout(cct, 4) << "failed to lock: " << cpp_strerror(retcode) << dendl;
+        continue;
+      }
+
+      set_status("trimming");
+      // TODO: spawn trim logic
+      if (retcode < 0) {
+        // on errors, unlock so other gateways can try
+        set_status("unlocking");
+        yield call(new RGWSimpleRadosUnlockCR(store->get_async_rados(), store,
+                                              obj, name, cookie));
+      }
+    }
+  }
+  return 0;
+}
+
 namespace rgw {
 
 class BucketTrimManager::Impl : public TrimCounters::Server {
@@ -318,4 +368,9 @@ void BucketTrimManager::on_bucket_changed(const boost::string_view& bucket)
   impl->counter.insert(bucket.to_string());
 }
 
+RGWCoroutine* BucketTrimManager::create_bucket_trim_cr()
+{
+  return new BucketTrimPollCR(impl->store, impl->config, impl->status_obj);
+}
+
 } // namespace rgw
index 6110a7aa80e31eb94a475112703f0121f6d89e44..fb69512e97b302eb2103d384b6a0b1d3c340d958 100644 (file)
@@ -20,6 +20,7 @@
 #include <boost/utility/string_view.hpp>
 
 class CephContext;
+class RGWCoroutine;
 class RGWRados;
 
 namespace rgw {
@@ -33,6 +34,8 @@ struct BucketChangeObserver {
 
 /// Configuration for BucketTrimManager
 struct BucketTrimConfig {
+  /// time interval in seconds between bucket trim attempts
+  uint32_t trim_interval_sec{0};
   /// maximum number of buckets to track with BucketChangeObserver
   size_t counter_size{0};
 };
@@ -55,6 +58,9 @@ class BucketTrimManager : public BucketChangeObserver {
 
   /// increment a counter for the given bucket instance
   void on_bucket_changed(const boost::string_view& bucket_instance) override;
+
+  /// create a coroutine to run the bucket trim process every trim interval
+  RGWCoroutine* create_bucket_trim_cr();
 };
 
 } // namespace rgw