dht: add formatter for paritition_range_view and i_partition

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
`partition_range_view` and `i_partition`, and drop their operator<<:s.

Refs #13245

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#17331
This commit is contained in:
Kefu Chai
2024-02-14 11:19:45 +08:00
committed by Botond Dénes
parent 3b7b315f6a
commit 8e8b73fa82
3 changed files with 22 additions and 29 deletions

View File

@@ -10,6 +10,7 @@
#include "sharder.hh"
#include <seastar/core/seastar.hh>
#include <seastar/coroutine/maybe_yield.hh>
#include "dht/ring_position.hh"
#include "dht/token-sharding.hh"
#include "utils/class_registrator.hh"
#include <boost/range/adaptor/map.hpp>
@@ -58,26 +59,6 @@ std::ostream& operator<<(std::ostream& out, const decorated_key& dk) {
return out;
}
std::ostream& operator<<(std::ostream& out, partition_ranges_view v) {
out << "{";
if (v.empty()) {
out << " }";
return out;
}
auto it = v.begin();
out << *it;
++it;
for (;it != v.end(); ++it) {
out << ", " << *it;
}
out << "}";
return out;
}
std::unique_ptr<dht::i_partitioner> make_partitioner(sstring partitioner_name) {
try {
return create_object<i_partitioner>(partitioner_name);
@@ -149,11 +130,6 @@ decorated_key::less_comparator::operator()(const decorated_key& lhs, const ring_
return lhs.tri_compare(*s, rhs) < 0;
}
std::ostream& operator<<(std::ostream& out, const i_partitioner& p) {
out << "{partitioner name = " << p.name();
return out << "}";
}
unsigned static_shard_of(const schema& s, const token& t) {
return s.get_sharder().shard_of(t);
}
@@ -518,3 +494,12 @@ auto fmt::formatter<dht::ring_position>::format(const dht::ring_position& pos, f
}
return fmt::format_to(out, "}}");
}
auto fmt::formatter<dht::partition_ranges_view>::format(const dht::partition_ranges_view& v, fmt::format_context& ctx) const
-> decltype(ctx.out()) {
auto out = fmt::format_to(ctx.out(), "{{");
for (auto& range : v) {
out = fmt::format_to(out, "{}", range);
}
return fmt::format_to(out, "}}");
}

View File

@@ -73,8 +73,6 @@ public:
}
};
std::ostream& operator<<(std::ostream& out, const i_partitioner& p);
// Returns the owning shard number for vnode-based replication strategies.
// Use table::shard_of() for the general case.
unsigned static_shard_of(const schema&, const token&);
@@ -120,3 +118,10 @@ dht::token first_token(const dht::partition_range&);
std::optional<shard_id> is_single_shard(const dht::sharder&, const schema&, const dht::partition_range&);
} // dht
template <> struct fmt::formatter<dht::i_partitioner> : fmt::formatter<std::string_view> {
template <typename FormatContext>
auto format(const dht::i_partitioner& p, FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "{{partitioner name = {}}}", p.name());
}
};

View File

@@ -486,8 +486,6 @@ public:
const dht::partition_range* end() const { return _data + _size; }
};
std::ostream& operator<<(std::ostream& out, partition_ranges_view v);
} // namespace dht
template<>
@@ -509,3 +507,8 @@ struct fmt::formatter<dht::ring_position> {
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
auto format(const dht::ring_position& pos, fmt::format_context& ctx) const -> decltype(ctx.out());
};
template <> struct fmt::formatter<dht::partition_ranges_view> : fmt::formatter<std::string_view> {
auto format(const dht::partition_ranges_view&, fmt::format_context& ctx) const
-> decltype(ctx.out());
};