From: Casey Bodley Date: Fri, 1 Sep 2017 16:22:47 +0000 (-0400) Subject: rgw: add BucketTrimPollCR for interval and lease logic X-Git-Tag: v13.0.1~210^2~27 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=129fc99d5208279029ff1722d21f0ad24c37db62;p=ceph.git rgw: add BucketTrimPollCR for interval and lease logic Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_sync_log_trim.cc b/src/rgw/rgw_sync_log_trim.cc index 09017290dfd..05b6e247ed6 100644 --- a/src/rgw/rgw_sync_log_trim.cc +++ b/src/rgw/rgw_sync_log_trim.cc @@ -18,8 +18,11 @@ #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 #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 diff --git a/src/rgw/rgw_sync_log_trim.h b/src/rgw/rgw_sync_log_trim.h index 6110a7aa80e..fb69512e97b 100644 --- a/src/rgw/rgw_sync_log_trim.h +++ b/src/rgw/rgw_sync_log_trim.h @@ -20,6 +20,7 @@ #include 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