From 50d6114c5884f52742e343dec2bdde82bca22c87 Mon Sep 17 00:00:00 2001 From: Adam Emerson Date: Tue, 19 Nov 2024 20:11:26 -0500 Subject: [PATCH] gcc11: Temporary change to neorados CLS log Signed-off-by: Adam Emerson --- src/neorados/cls/log.h | 134 +++++++++++++++++++++++++++- src/test/cls_log/test_neocls_log.cc | 32 +++++++ 2 files changed, 165 insertions(+), 1 deletion(-) diff --git a/src/neorados/cls/log.h b/src/neorados/cls/log.h index 41a38e134c0..c974aab1484 100644 --- a/src/neorados/cls/log.h +++ b/src/neorados/cls/log.h @@ -159,6 +159,7 @@ static constexpr auto max_list_entries = 1000u; }}; } +#if 0 // Until we are at last free of GCC11 /// \brief List log entries /// /// Execute an asynchronous operation that lists log entries @@ -199,6 +200,7 @@ auto list(RADOS& r, Object o, IOContext ioc, ceph::real_time from, return std::make_tuple(res, std::move(marker)); }, std::forward(token)); } +#endif /// \brief Get log header /// @@ -230,6 +232,7 @@ auto list(RADOS& r, Object o, IOContext ioc, ceph::real_time from, }}; } +#if 0 /// \brief Get log header /// /// Execute an asynchronous operation that returns the log header @@ -251,6 +254,7 @@ auto info(RADOS& r, Object o, IOContext ioc, CompletionToken&& token) return ret.header; }, std::forward(token)); } +#endif // Since trim uses the string markers and ignores the time if the // string markers are present, there's no benefit to having a function @@ -325,6 +329,7 @@ inline constexpr std::string_view end_marker{"9"}; } +#if 0 // Until we're freed from GCC11 // Asio's co_compse generates spurious warnings when compiled with // -O0. the 'mismatched' `operator new` calls directly into the // matching `operator new`, returning its result. @@ -407,7 +412,6 @@ auto trim(RADOS& r, Object oid, IOContext ioc, ceph::real_time from_time, real_time from_time, real_time to_time) -> void { try { for (;;) { - co_await r.execute(oid, ioc, WriteOp{}.exec(trim(from_time, to_time)), asio::deferred); } @@ -421,4 +425,132 @@ auto trim(RADOS& r, Object oid, IOContext ioc, ceph::real_time from_time, token, std::ref(r), std::move(oid), std::move(ioc), from_time, to_time); } #pragma GCC diagnostic pop +#endif + + +/// \brief Trim entries from the log +/// +/// Execute an asynchronous operation that trims a range of entries +/// from the log. +/// +/// \param op Write operation to modify +/// \param from_marker Start of range, based on markers from list +/// \param to_marker End of range, based on markers from list +/// +/// \note Use \ref begin_marker to trim everything up to a given point. +/// Use \ref end_marker to trim everything after a given point. Use them +/// both together to trim all entries. +/// +/// \return As appropriate to the completion token. See Boost.Asio +/// documentation. +template +boost::asio::awaitable +trim(RADOS& r, Object oid, IOContext ioc, + std::string_view from_marker, std::string_view to_marker, + boost::asio::use_awaitable_t ua = boost::asio::use_awaitable) +{ + using boost::system::error_code; + using boost::system::system_error; + using ceph::real_time; + using boost::system::errc::no_message_available; + + for (;;) try { + co_await r.execute(oid, ioc, + WriteOp{}.exec(trim(from_marker, to_marker)), + ua); + } catch (const system_error& e) { + if (e.code() != no_message_available) { + throw; + } + } + co_return; +} + +/// \brief Trim entries from the log +/// +/// Execute an asynchronous operation that trims a range of entries +/// from the log. +/// +/// \param op Write operation to modify +/// \param from_time Start of range, based on the timestamp supplied to add +/// \param to_time End of range, based on the timestamp supplied to add +/// +/// \return As appropriate to the completion token. See Boost.Asio +/// documentation. +template +boost::asio::awaitable +trim(RADOS& r, Object oid, IOContext ioc, + ceph::real_time from_time, ceph::real_time to_time, + boost::asio::use_awaitable_t ua = boost::asio::use_awaitable) +{ + using boost::system::error_code; + using boost::system::system_error; + using ceph::real_time; + using boost::system::errc::no_message_available; + + for (;;) try { + co_await r.execute(oid, ioc, WriteOp{}.exec(trim(from_time, to_time)), + ua); + } catch (const system_error& e) { + if (e.code() != no_message_available) { + co_return e.code(); + } + } + co_return error_code{}; +} + +/// \brief List log entries +/// +/// Execute an asynchronous operation that lists log entries +/// +/// \param r RADOS handle +/// \param o Object associated with log +/// \param ioc Object locator context +/// \param from Start of range +/// \param to End of range +/// \param in_marker Point to resume truncated listing +/// +/// \return (entries, marker) in a way appropriate to the +/// completion token. See Boost.Asio documentation. +template +boost::asio::awaitable, + std::string>, + E> +list(RADOS& r, Object o, IOContext ioc, ceph::real_time from, + ceph::real_time to, std::string in_marker, + std::span entries, + boost::asio::use_awaitable_t ua = boost::asio::use_awaitable) +{ + using namespace std::literals; + ReadOp op; + std::span out; + std::string out_marker; + op.exec(list(from, to, in_marker, entries, &out, &out_marker)); + co_await r.execute(std::move(o), std::move(ioc), std::move(op), nullptr, ua); + co_return std::make_tuple(out, std::move(out_marker)); +} + +/// \brief Get log header +/// +/// Execute an asynchronous operation that returns the log header +/// +/// \param r RADOS handle +/// \param o Object associated with log +/// \param ioc Object locator context +/// +/// \return The log header in a way appropriate to the completion +/// token. See Boost.Asio documentation. +template +boost::asio::awaitable +info(RADOS& r, Object o, IOContext ioc, + boost::asio::use_awaitable_t ua = boost::asio::use_awaitable) +{ + using namespace std::literals; + ReadOp op; + header h; + op.exec(info(&h)); + co_await r.execute(std::move(o), std::move(ioc), std::move(op), nullptr, ua); + co_return h; +} + } // namespace neorados::cls::log diff --git a/src/test/cls_log/test_neocls_log.cc b/src/test/cls_log/test_neocls_log.cc index d6b5ba176ec..b99edba844c 100644 --- a/src/test/cls_log/test_neocls_log.cc +++ b/src/test/cls_log/test_neocls_log.cc @@ -134,6 +134,7 @@ void check_entry(const l::entry& entry, real_time start_time, ASSERT_EQ(ts, entry.timestamp); } +#if 0 template CompletionToken> auto check_log(RADOS& r, Object oid, IOContext ioc, real_time start_time, int max, CompletionToken&& token) @@ -174,6 +175,35 @@ auto check_log(RADOS& r, Object oid, IOContext ioc, real_time start_time, std::move(ioc), start_time, max); #pragma GCC diagnostic pop } +#endif + +template +asio::awaitable +check_log(RADOS& r, Object oid, IOContext ioc, real_time start_time, + int max, asio::use_awaitable_t ua = asio::use_awaitable) +{ + try { + std::vector entries{neorados::cls::log::max_list_entries}; + std::string marker; + int i = 0; + do { + std::span result; + std::tie(result, marker) = + co_await neorados::cls::log::list(r, oid, ioc, {}, {}, + marker, entries, ua); + for (const auto& entry : result) { + auto num = decode(entry.data); + EXPECT_EQ(i, num); + check_entry(entry, start_time, i, true); + ++i; + } + } while (!marker.empty()); + EXPECT_EQ(i, max); + } catch (const system_error& e) { + co_return {e.code()}; + } + co_return {error_code{}}; +} template auto trim(RADOS& rados, Object oid, const IOContext ioc, @@ -442,6 +472,7 @@ CORO_TEST_F(neocls_log, trim_by_marker, NeoRadosTest) } } +#if 0 // Disable until we get rid of GCC11 TEST(neocls_log_bare, lambdata) { asio::io_context c; @@ -495,3 +526,4 @@ TEST(neocls_log_bare, lambdata) c.run(); ASSERT_TRUE(completed); } +#endif -- 2.39.5