From 9bd9b7659fdb7a1a01d5e1523f0d461dbf5eaafe Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Wed, 10 Feb 2021 17:09:02 -0500 Subject: [PATCH] rgw: Try to prune empties even if no empties found Since we won't actually delete empties until much later. Signed-off-by: Adam C. Emerson --- src/rgw/rgw_datalog.cc | 54 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/rgw/rgw_datalog.cc b/src/rgw/rgw_datalog.cc index 2716a9c2bee3a..0f2be19d06600 100644 --- a/src/rgw/rgw_datalog.cc +++ b/src/rgw/rgw_datalog.cc @@ -882,38 +882,36 @@ void DataLogBackends::trim_entries(int shard_id, std::string_view marker, } int DataLogBackends::trim_generations(std::optional& through) { - if (size() == 1) { - return 0; - } - - std::vector candidates; - { - std::scoped_lock l(m); - auto e = cend() - 1; - for (auto i = cbegin(); i < e; ++i) { - candidates.push_back(i->second); + if (size() != 1) { + std::vector candidates; + { + std::scoped_lock l(m); + auto e = cend() - 1; + for (auto i = cbegin(); i < e; ++i) { + candidates.push_back(i->second); + } } - } - std::optional highest; - for (auto& be : candidates) { - auto r = be->is_empty(); - if (r < 0) { - return r; - } else if (r == 1) { - highest = be->gen_id; - } else { - break; + std::optional highest; + for (auto& be : candidates) { + auto r = be->is_empty(); + if (r < 0) { + return r; + } else if (r == 1) { + highest = be->gen_id; + } else { + break; + } } - } - through = highest; - if (!highest) { - return 0; - } - auto ec = empty_to(*highest, null_yield); - if (ec) { - return ceph::from_error_code(ec); + through = highest; + if (!highest) { + return 0; + } + auto ec = empty_to(*highest, null_yield); + if (ec) { + return ceph::from_error_code(ec); + } } return ceph::from_error_code(remove_empty(null_yield)); -- 2.39.5