From f70374f71fe4e715f6221d34aee268ed601b17b8 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Sat, 21 Nov 2020 19:34:07 -0500 Subject: [PATCH] rgw: Add LazyFIFO to keep from blasting an op-per-shard on startup LazyFIFO opens the FIFO on first access. Signed-off-by: Adam C. Emerson (cherry picked from commit 1cc4a0a4e274700b4ae044db125a8cb3a64253a2) Signed-off-by: Adam C. Emerson --- src/rgw/rgw_log_backing.h | 135 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/src/rgw/rgw_log_backing.h b/src/rgw/rgw_log_backing.h index ef2583c35b204..cd677764c5795 100644 --- a/src/rgw/rgw_log_backing.h +++ b/src/rgw/rgw_log_backing.h @@ -32,6 +32,8 @@ namespace bc = boost::container; namespace bs = boost::system; +#include "cls_fifo_legacy.h" + /// Type of log backing, stored in the mark used in the quick check, /// and passed to checking functions. enum class log_type { @@ -255,4 +257,137 @@ cursorgeno(std::optional cursor) { } } +class LazyFIFO { + librados::IoCtx& ioctx; + std::string oid; + std::mutex m; + std::unique_ptr fifo; + + int lazy_init(optional_yield y) { + std::unique_lock l(m); + if (fifo) return 0; + auto r = rgw::cls::fifo::FIFO::create(ioctx, oid, &fifo, y); + if (r) { + fifo.reset(); + } + return r; + } + +public: + + LazyFIFO(librados::IoCtx& ioctx, std::string oid) + : ioctx(ioctx), oid(std::move(oid)) {} + + int read_meta(optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->read_meta(y); + } + + int meta(rados::cls::fifo::info& info, optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + info = fifo->meta(); + return 0; + } + + int get_part_layout_info(std::uint32_t& part_header_size, + std::uint32_t& part_entry_overhead, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + std::tie(part_header_size, part_entry_overhead) + = fifo->get_part_layout_info(); + return 0; + } + + int push(const ceph::buffer::list& bl, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->push(bl, y); + } + + int push(ceph::buffer::list& bl, + librados::AioCompletion* c, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->push(bl, c); + return 0; + } + + int push(const std::vector& data_bufs, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->push(data_bufs, y); + } + + int push(const std::vector& data_bufs, + librados::AioCompletion* c, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->push(data_bufs, c); + return 0; + } + + int list(int max_entries, std::optional markstr, + std::vector* out, + bool* more, optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->list(max_entries, markstr, out, more, y); + } + + int list(int max_entries, std::optional markstr, + std::vector* out, bool* more, + librados::AioCompletion* c, optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->list(max_entries, markstr, out, more, c); + return 0; + } + + int trim(std::string_view markstr, bool exclusive, optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->trim(markstr, exclusive, y); + } + + int trim(std::string_view markstr, bool exclusive, librados::AioCompletion* c, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->trim(markstr, exclusive, c); + return 0; + } + + int get_part_info(int64_t part_num, rados::cls::fifo::part_header* header, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + return fifo->get_part_info(part_num, header, y); + } + + int get_part_info(int64_t part_num, rados::cls::fifo::part_header* header, + librados::AioCompletion* c, optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->get_part_info(part_num, header, c); + return 0; + } + + int get_head_info(fu2::unique_function< + void(int r, rados::cls::fifo::part_header&&)>&& f, + librados::AioCompletion* c, + optional_yield y) { + auto r = lazy_init(y); + if (r < 0) return r; + fifo->get_head_info(std::move(f), c); + return 0; + } +}; + #endif -- 2.39.5