From ce249836e01aacd8024584be666455c299d38172 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Sat, 21 Nov 2020 23:06:38 -0500 Subject: [PATCH] rgw: Use LazyFIFO in data changes log That way we don't start sending ops to open a FIFO until we need it. Signed-off-by: Adam C. Emerson (cherry picked from commit 12939a258f8c627d1b7b23c0b9d7c22e98e69d89) Signed-off-by: Adam C. Emerson --- src/rgw/rgw_datalog.cc | 47 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/rgw/rgw_datalog.cc b/src/rgw/rgw_datalog.cc index 6182ae91909e4..3ecab432646c1 100644 --- a/src/rgw/rgw_datalog.cc +++ b/src/rgw/rgw_datalog.cc @@ -4,6 +4,7 @@ #include #include "common/debug.h" +#include "common/containers.h" #include "common/errno.h" #include "common/error_code.h" @@ -24,6 +25,8 @@ static constexpr auto dout_subsys = ceph_subsys_rgw; namespace bs = boost::system; namespace lr = librados; +using ceph::containers::tiny_vector; + void rgw_data_change::dump(ceph::Formatter *f) const { std::string type; @@ -229,27 +232,16 @@ public: class RGWDataChangesFIFO final : public RGWDataChangesBE { using centries = std::vector; - std::vector> fifos; + tiny_vector fifos; public: RGWDataChangesFIFO(lr::IoCtx& ioctx, RGWDataChangesLog& datalog, uint64_t gen_id, int shards) - : RGWDataChangesBE(ioctx, datalog, gen_id) { - fifos.resize(shards); - for (auto i = 0; i < shards; ++i) { - auto r = rgw::cls::fifo::FIFO::create(ioctx, get_oid(i), - &fifos[i], null_yield); - if (r < 0) { - throw bs::system_error(ceph::to_error_code(r)); - } - } - ceph_assert(fifos.size() == unsigned(shards)); - ceph_assert(std::none_of(fifos.cbegin(), fifos.cend(), - [](const auto& p) { - return p == nullptr; - })); - } + : RGWDataChangesBE(ioctx, datalog, gen_id), + fifos(shards, [&ioctx, this](std::size_t i, auto emplacer) { + emplacer.emplace(ioctx, get_oid(i)); + }) {} ~RGWDataChangesFIFO() override = default; void prepare(ceph::real_time, const std::string&, ceph::buffer::list&& entry, entries& out) override { @@ -260,7 +252,7 @@ public: std::get(out).push_back(std::move(entry)); } int push(int index, entries&& items) override { - auto r = fifos[index]->push(std::get(items), null_yield); + auto r = fifos[index].push(std::get(items), null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to push to FIFO: " << get_oid(index) @@ -271,7 +263,7 @@ public: int push(int index, ceph::real_time, const std::string&, ceph::buffer::list&& bl) override { - auto r = fifos[index]->push(std::move(bl), null_yield); + auto r = fifos[index].push(std::move(bl), null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to push to FIFO: " << get_oid(index) @@ -285,8 +277,8 @@ public: std::string* out_marker, bool* truncated) override { std::vector log_entries; bool more = false; - auto r = fifos[index]->list(max_entries, marker, &log_entries, &more, - null_yield); + auto r = fifos[index].list(max_entries, marker, &log_entries, &more, + null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to list FIFO: " << get_oid(index) @@ -317,14 +309,15 @@ public: } int get_info(int index, RGWDataChangesLogInfo *info) override { auto& fifo = fifos[index]; - auto r = fifo->read_meta(null_yield); + auto r = fifo.read_meta(null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to get FIFO metadata: " << get_oid(index) << ": " << cpp_strerror(-r) << dendl; return r; } - auto m = fifo->meta(); + rados::cls::fifo::info m; + fifo.meta(m, null_yield); auto p = m.head_part_num; if (p < 0) { info->marker = rgw::cls::fifo::marker{}.to_string(); @@ -332,7 +325,7 @@ public: return 0; } rgw::cls::fifo::part_info h; - r = fifo->get_part_info(p, &h, null_yield); + r = fifo.get_part_info(p, &h, null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to get part info: " << get_oid(index) << "/" << p @@ -344,7 +337,7 @@ public: return 0; } int trim(int index, std::string_view marker) override { - auto r = fifos[index]->trim(marker, false, null_yield); + auto r = fifos[index].trim(marker, false, null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to trim FIFO: " << get_oid(index) @@ -358,7 +351,7 @@ public: if (marker == rgw::cls::fifo::marker(0, 0).to_string()) { rgw_complete_aio_completion(c, -ENODATA); } else { - fifos[index]->trim(marker, false, c); + fifos[index].trim(marker, false, c, null_yield); } return r; } @@ -371,8 +364,8 @@ public: std::vector log_entries; bool more = false; for (auto shard = 0u; shard < fifos.size(); ++shard) { - auto r = fifos[shard]->list(1, {}, &log_entries, &more, - null_yield); + auto r = fifos[shard].list(1, {}, &log_entries, &more, + null_yield); if (r < 0) { lderr(cct) << __PRETTY_FUNCTION__ << ": unable to list FIFO: " << get_oid(shard) -- 2.39.5