From 33db0d4fea73cc9f70b1f473cdd2f2fbd6120fab Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 24 Jan 2025 19:50:01 +0100 Subject: [PATCH] tablets: Add formatter for resize_decision::way_type --- locator/tablets.cc | 19 ++++++++++++------- locator/tablets.hh | 7 +++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/locator/tablets.cc b/locator/tablets.cc index a18199307a..cecc458658 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -633,13 +633,7 @@ resize_decision::resize_decision(sstring decision, uint64_t seq_number) } sstring resize_decision::type_name() const { - static const std::array index_to_string = { - "none", - "split", - "merge", - }; - static_assert(std::variant_size_v == index_to_string.size()); - return index_to_string[way.index()]; + return fmt::format("{}", way); } resize_decision::seq_number_t resize_decision::next_sequence_number() const { @@ -1031,6 +1025,17 @@ void tablet_metadata_guard::subscribe() { } +auto fmt::formatter::format(const locator::resize_decision_way& way, fmt::format_context& ctx) const + -> decltype(ctx.out()) { + static const std::array index_to_string = { + "none", + "split", + "merge", + }; + static_assert(std::variant_size_v == index_to_string.size()); + return fmt::format_to(ctx.out(), "{}", index_to_string[way.index()]); +} + auto fmt::formatter::format(const locator::global_tablet_id& id, fmt::format_context& ctx) const -> decltype(ctx.out()) { return fmt::format_to(ctx.out(), "{}:{}", id.table, id.tablet); diff --git a/locator/tablets.hh b/locator/tablets.hh index a52f1de2af..3765970714 100644 --- a/locator/tablets.hh +++ b/locator/tablets.hh @@ -354,6 +354,8 @@ struct resize_decision { seq_number_t next_sequence_number() const; }; +using resize_decision_way = resize_decision::way_type; + struct table_load_stats { uint64_t size_in_bytes = 0; // Stores the minimum seq number among all replicas, as coordinator wants to know if @@ -668,6 +670,11 @@ struct tablet_metadata_change_hint { } +template <> +struct fmt::formatter : fmt::formatter { + auto format(const locator::resize_decision_way&, fmt::format_context& ctx) const -> decltype(ctx.out()); +}; + template <> struct fmt::formatter : fmt::formatter { auto format(const locator::tablet_transition_stage&, fmt::format_context& ctx) const -> decltype(ctx.out());