From cfb2c2c758aa118f1f1275d09dabec7c847d12be Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 10 Feb 2024 10:34:17 +0800 Subject: [PATCH] db: add formatter for gc_clock::time_point before this change, we rely on the default-generated fmt::formatter created from operator<<, but fmt v10 dropped the default-generated formatter. in this change, we define formatters for `gc_clock::time_point`, and drop its operator<<. Refs #13245 Signed-off-by: Kefu Chai Closes scylladb/scylladb#17254 --- gc_clock.hh | 8 ++++++-- replica/database.cc | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gc_clock.hh b/gc_clock.hh index 1605c27e76..1d356d370e 100644 --- a/gc_clock.hh +++ b/gc_clock.hh @@ -58,8 +58,6 @@ using ttl_opt = std::optional; // 20 years in seconds static constexpr gc_clock::duration max_ttl = gc_clock::duration{20 * 365 * 24 * 60 * 60}; -std::ostream& operator<<(std::ostream& os, gc_clock::time_point tp); - template<> struct appending_hash { template @@ -107,3 +105,9 @@ struct serializer { }; } + +template<> +struct fmt::formatter { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + auto format(gc_clock::time_point, fmt::format_context& ctx) const -> decltype(ctx.out()); +}; diff --git a/replica/database.cc b/replica/database.cc index d8efb1114e..6753da91be 100644 --- a/replica/database.cc +++ b/replica/database.cc @@ -2980,11 +2980,10 @@ flat_mutation_reader_v2 make_multishard_streaming_reader(distributed::format(gc_clock::time_point tp, fmt::format_context& ctx) const + -> decltype(ctx.out()) { auto sec = std::chrono::duration_cast(tp.time_since_epoch()).count(); - std::ostream tmp(os.rdbuf()); - tmp << std::setw(12) << sec; - return os; + return fmt::format_to(ctx.out(), "{:>12}", sec); } const timeout_config infinite_timeout_config = {