From 6f1773e428980331af2cc7a7634aa5486dc79d7e Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Thu, 11 Apr 2024 01:04:17 +0530 Subject: [PATCH] rgw/lc: cleanup duplicate code Cleaning up duplicate code around updating head Signed-off-by: Soumya Koduri (cherry picked from commit e2b3a3002f404c8e61fd792e773abde1ec60016e) --- src/rgw/rgw_lc.cc | 133 ++++++++++++++++++++++------------------------ src/rgw/rgw_lc.h | 7 +++ 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index 4b4b2874396f6..29ee37542a2c1 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -2203,6 +2203,55 @@ exit: return ret; } /* advance head */ +inline int RGWLC::check_if_shard_done(const std::string& lc_shard, + rgw::sal::Lifecycle::LCHead& head, int worker_ix) +{ + int ret{0}; + + if (head.get_marker().empty()) { + /* done with this shard */ + ldpp_dout(this, 5) << + "RGWLC::process() next_entry not found. cycle finished lc_shard=" + << lc_shard << " worker=" << worker_ix + << dendl; + head.set_shard_rollover_date(ceph_clock_now()); + ret = sal_lc->put_head(lc_shard, head); + if (ret < 0) { + ldpp_dout(this, 0) << "RGWLC::process() failed to put head " + << lc_shard + << dendl; + } + ret = 1; // to mark that shard is done + } + return ret; +} + +inline int RGWLC::update_head(const std::string& lc_shard, + rgw::sal::Lifecycle::LCHead& head, + rgw::sal::Lifecycle::LCEntry& entry, + time_t start_date, int worker_ix) +{ + int ret{0}; + + ret = advance_head(lc_shard, head, entry, start_date); + if (ret != 0) { + ldpp_dout(this, 0) << "RGWLC::update_head() failed to advance head " + << lc_shard + << dendl; + goto exit; + } + + ret = check_if_shard_done(lc_shard, head, worker_ix); + if (ret < 0) { + ldpp_dout(this, 0) << "RGWLC::update_head() failed to check if shard is done " + << lc_shard + << dendl; + } + +exit: + return ret; +} + int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, bool once = false) { @@ -2285,27 +2334,13 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, ret = sal_lc->get_entry(lc_shard, head->get_marker(), &entry); if (ret == -ENOENT) { /* skip to next entry */ - std::unique_ptr tmp_entry = sal_lc->get_entry(); - tmp_entry->set_bucket(head->get_marker()); - if (advance_head(lc_shard, *head.get(), *tmp_entry.get(), now) < 0) { - goto exit; - } - /* done with this shard */ - if (head->get_marker().empty()) { - ldpp_dout(this, 5) << - "RGWLC::process() next_entry not found. cycle finished lc_shard=" - << lc_shard << " worker=" << worker->ix - << dendl; - head->set_shard_rollover_date(ceph_clock_now()); - ret = sal_lc->put_head(lc_shard, *head.get()); - if (ret < 0) { - ldpp_dout(this, 0) << "RGWLC::process() failed to put head " - << lc_shard - << dendl; - } - goto exit; - } - continue; + std::unique_ptr tmp_entry = sal_lc->get_entry(); + tmp_entry->set_bucket(head->get_marker()); + + if (update_head(lc_shard, *head.get(), *tmp_entry.get(), now, worker->ix) != 0) { + goto exit; + } + continue; } if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() sal_lc->get_entry(lc_shard, head.marker, entry) " @@ -2326,51 +2361,21 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, << "RGWLC::process(): ACTIVE entry: " << entry << " index: " << index << " worker ix: " << worker->ix << dendl; /* skip to next entry */ - if (advance_head(lc_shard, *head.get(), *entry.get(), now) < 0) { - goto exit; - } - /* done with this shard */ - if (head->get_marker().empty()) { - ldpp_dout(this, 5) << - "RGWLC::process() cycle finished lc_shard=" - << lc_shard << " worker=" << worker->ix - << dendl; - head->set_shard_rollover_date(ceph_clock_now()); - ret = sal_lc->put_head(lc_shard, *head.get()); - if (ret < 0) { - ldpp_dout(this, 0) << "RGWLC::process() failed to put head " - << lc_shard - << dendl; - } - goto exit; + if (update_head(lc_shard, *head.get(), *entry.get(), now, worker->ix) != 0) { + goto exit; } continue; } } else { if ((entry->get_status() == lc_complete) && already_run_today(cct, entry->get_start_time())) { - /* skip to next entry */ - if (advance_head(lc_shard, *head.get(), *entry.get(), now) < 0) { - goto exit; - } ldpp_dout(this, 5) << "RGWLC::process() worker ix: " << worker->ix << " SKIP processing for already-processed bucket " << entry->get_bucket() << dendl; - /* done with this shard */ - if (head->get_marker().empty()) { - ldpp_dout(this, 5) << - "RGWLC::process() cycle finished lc_shard=" - << lc_shard << " worker=" << worker->ix - << dendl; - head->set_shard_rollover_date(ceph_clock_now()); - ret = sal_lc->put_head(lc_shard, *head.get()); - if (ret < 0) { - ldpp_dout(this, 0) << "RGWLC::process() failed to put head " - << lc_shard - << dendl; - } - goto exit; - } + /* skip to next entry */ + if (update_head(lc_shard, *head.get(), *entry.get(), now, worker->ix) != 0) { + goto exit; + } continue; } } @@ -2452,19 +2457,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, } } - /* done with this shard */ - if (head->get_marker().empty()) { - ldpp_dout(this, 5) << - "RGWLC::process() cycle finished lc_shard=" - << lc_shard << " worker=" << worker->ix - << dendl; - head->set_shard_rollover_date(ceph_clock_now()); - ret = sal_lc->put_head(lc_shard, *head.get()); - if (ret < 0) { - ldpp_dout(this, 0) << "RGWLC::process() failed to put head " - << lc_shard - << dendl; - } + if (check_if_shard_done(lc_shard, *head.get(), worker->ix) != 0 ) { goto exit; } } while(1 && !once && !going_down()); diff --git a/src/rgw/rgw_lc.h b/src/rgw/rgw_lc.h index 11a09c36be6bf..162b839efea72 100644 --- a/src/rgw/rgw_lc.h +++ b/src/rgw/rgw_lc.h @@ -631,6 +631,13 @@ public: rgw::sal::Lifecycle::LCHead& head, rgw::sal::Lifecycle::LCEntry& entry, time_t start_date); + int check_if_shard_done(const std::string& lc_shard, + rgw::sal::Lifecycle::LCHead& head, + int worker_ix); + int update_head(const std::string& lc_shard, + rgw::sal::Lifecycle::LCHead& head, + rgw::sal::Lifecycle::LCEntry& entry, + time_t start_date, int worker_ix); int process(int index, int max_lock_secs, LCWorker* worker, bool once); int process_bucket(int index, int max_lock_secs, LCWorker* worker, const std::string& bucket_entry_marker, bool once); -- 2.39.5