gms: add formatter for gms::endpoint_state
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 a formatter for gms::endpoint_state, and change update the callers of `operator<<` to use `fmt::print()`. but we cannot drop `operator<<` yet, as we are still using the templated operator<< and templated fmt::formatter to print containers in scylla and in seastar -- they are still using `operator<<` under the hood. Refs #13245 Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> Closes scylladb/scylladb#16705
This commit is contained in:
@@ -35,12 +35,7 @@ const versioned_value* endpoint_state::get_application_state_ptr(application_sta
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const endpoint_state& x) {
|
||||
fmt::print(os, "HeartBeatState = {}, AppStateMap =", x._heart_beat_state);
|
||||
for (auto&entry : x._application_state) {
|
||||
const application_state& state = entry.first;
|
||||
const versioned_value& value = entry.second;
|
||||
os << " { " << state << " : " << value << " } ";
|
||||
}
|
||||
fmt::print(os, "{}", x);
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -67,3 +62,13 @@ future<> i_endpoint_state_change_subscriber::on_application_state_change(inet_ad
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto fmt::formatter<gms::endpoint_state>::format(const gms::endpoint_state& x,
|
||||
fmt::format_context& ctx) const -> decltype(ctx.out()) {
|
||||
auto out = ctx.out();
|
||||
out = fmt::format_to(out, "HeartBeatState = {}, AppStateMap =", x._heart_beat_state);
|
||||
for (auto& [state, value] : x._application_state) {
|
||||
out = fmt::format_to(out, " {{ {} : {} }} ", state, value);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -149,9 +149,11 @@ public:
|
||||
|
||||
bool is_cql_ready() const noexcept;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const endpoint_state& x);
|
||||
friend fmt::formatter<endpoint_state>;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const endpoint_state& x);
|
||||
|
||||
using endpoint_state_ptr = lw_shared_ptr<const endpoint_state>;
|
||||
|
||||
inline endpoint_state_ptr make_endpoint_state_ptr(const endpoint_state& eps) {
|
||||
@@ -174,3 +176,9 @@ using permit_id = utils::tagged_uuid<struct permit_id_tag>;
|
||||
constexpr permit_id null_permit_id = permit_id::create_null_id();
|
||||
|
||||
} // gms
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<gms::endpoint_state> {
|
||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||
auto format(const gms::endpoint_state&, fmt::format_context& ctx) const -> decltype(ctx.out());
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ std::ostream& operator<<(std::ostream& os, const gossip_digest_ack& ack) {
|
||||
os << "} ";
|
||||
os << "endpoint_state:{";
|
||||
for (auto& d : ack._map) {
|
||||
os << "[" << d.first << "->" << d.second << "]";
|
||||
fmt::print(os, "[{}->{}]", d.first, d.second);
|
||||
}
|
||||
return os << "}";
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace gms {
|
||||
std::ostream& operator<<(std::ostream& os, const gossip_digest_ack2& ack2) {
|
||||
os << "endpoint_state:{";
|
||||
for (auto& d : ack2._map) {
|
||||
os << "[" << d.first << "->" << d.second << "]";
|
||||
fmt::print(os, "[{}->{}]", d.first, d.second);
|
||||
}
|
||||
return os << "}";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user