From 8f4291291b0dea4b4701894da0775149266a1373 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 26 Jan 2021 20:30:58 -0500 Subject: [PATCH] rgw: Prune datalog generations in the renew loop Every 150 times through, which is a bit less than an hour between runs by default. Signed-off-by: Adam C. Emerson --- src/rgw/rgw_datalog.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/rgw/rgw_datalog.cc b/src/rgw/rgw_datalog.cc index 9f919f4efe896..a8d1cd1684193 100644 --- a/src/rgw/rgw_datalog.cc +++ b/src/rgw/rgw_datalog.cc @@ -931,6 +931,8 @@ RGWDataChangesLog::~RGWDataChangesLog() { } void RGWDataChangesLog::renew_run() noexcept { + static constexpr auto runs_per_prune = 150; + auto run = 0; for (;;) { dout(2) << "RGWDataChangesLog::ChangesRenewThread: start" << dendl; int r = renew_entries(); @@ -941,6 +943,25 @@ void RGWDataChangesLog::renew_run() noexcept { if (going_down()) break; + if (run == runs_per_prune) { + std::optional through; + dout(2) << "RGWDataChangesLog::ChangesRenewThread: pruning old generations" << dendl; + trim_generations(through); + if (r < 0) { + derr << "RGWDataChangesLog::ChangesRenewThread: failed pruning r=" + << r << dendl; + } else if (through) { + dout(2) << "RGWDataChangesLog::ChangesRenewThread: pruned generations " + << "through " << *through << "." << dendl; + } else { + dout(2) << "RGWDataChangesLog::ChangesRenewThread: nothing to prune." + << dendl; + } + run = 0; + } else { + ++run; + } + int interval = cct->_conf->rgw_data_log_window * 3 / 4; std::unique_lock locker{renew_lock}; renew_cond.wait_for(locker, std::chrono::seconds(interval)); -- 2.39.5