From 8dbaef676dae689572b327a2f65781b0aa889e66 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 22 Mar 2023 16:43:19 +0800 Subject: [PATCH] treewide: use fmtlib to format gms::inet_address the goal of this change is to reduce the dependency on `operator<<(ostream&, const gms::inet_address&)`. this is not an exhaustive search-and-replace change, as in some caller sites we have other dependencies to yet-converted ostream printer, we cannot fix them all, this change only updates some caller of `operator<<(ostream&, const gms::inet_address&)`. Refs #13245 Signed-off-by: Kefu Chai --- api/api.hh | 2 +- api/failure_detector.cc | 2 +- api/messaging_service.cc | 2 +- api/storage_service.cc | 8 ++++---- api/stream_manager.cc | 4 ++-- gms/gossip_digest.hh | 3 ++- init.cc | 4 ++-- message/messaging_service.cc | 3 ++- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/api.hh b/api/api.hh index a8fde2e395..530dc09583 100644 --- a/api/api.hh +++ b/api/api.hh @@ -27,7 +27,7 @@ template std::vector container_to_vec(const T& container) { std::vector res; for (auto i : container) { - res.push_back(boost::lexical_cast(i)); + res.push_back(fmt::to_string(i)); } return res; } diff --git a/api/failure_detector.cc b/api/failure_detector.cc index c3da443a21..3f11ee91e8 100644 --- a/api/failure_detector.cc +++ b/api/failure_detector.cc @@ -22,7 +22,7 @@ void set_failure_detector(http_context& ctx, routes& r, gms::gossiper& g) { std::vector res; for (auto i : g.get_endpoint_states()) { fd::endpoint_state val; - val.addrs = boost::lexical_cast(i.first); + val.addrs = fmt::to_string(i.first); val.is_alive = i.second.is_alive(); val.generation = i.second.get_heart_beat_state().get_generation(); val.version = i.second.get_heart_beat_state().get_heart_beat_version(); diff --git a/api/messaging_service.cc b/api/messaging_service.cc index c26c403227..9d23107122 100644 --- a/api/messaging_service.cc +++ b/api/messaging_service.cc @@ -29,7 +29,7 @@ std::vector map_to_message_counters( std::vector res; for (auto i : map) { res.push_back(message_counter()); - res.back().key = boost::lexical_cast(i.first); + res.back().key = fmt::to_string(i.first); res.back().value = i.second; } return res; diff --git a/api/storage_service.cc b/api/storage_service.cc index 4343e5fb6a..c6d70fb6cd 100644 --- a/api/storage_service.cc +++ b/api/storage_service.cc @@ -169,7 +169,7 @@ static ss::token_range token_range_endpoints_to_json(const dht::token_range_endp r.rpc_endpoints = d._rpc_endpoints; for (auto det : d._endpoint_details) { ss::endpoint_detail ed; - ed.host = boost::lexical_cast(det._host); + ed.host = fmt::to_string(det._host); ed.datacenter = det._datacenter; if (det._rack != "") { ed.rack = det._rack; @@ -485,8 +485,8 @@ void set_storage_service(http_context& ctx, routes& r, sharded req) { return make_ready_future(stream_range_as_array(ss.local().get_token_to_endpoint_map(), [](const auto& i) { storage_service_json::mapper val; - val.key = boost::lexical_cast(i.first); - val.value = boost::lexical_cast(i.second); + val.key = fmt::to_string(i.first); + val.value = fmt::to_string(i.second); return val; })); }); @@ -554,7 +554,7 @@ void set_storage_service(http_context& ctx, routes& r, sharded addr; for (auto i: points) { - addr.insert(boost::lexical_cast(i.second)); + addr.insert(fmt::to_string(i.second)); } return container_to_vec(addr); }); diff --git a/api/stream_manager.cc b/api/stream_manager.cc index 3ec02599bd..e780a2862c 100644 --- a/api/stream_manager.cc +++ b/api/stream_manager.cc @@ -39,7 +39,7 @@ static hs::progress_info get_progress_info(const streaming::progress_info& info) res.current_bytes = info.current_bytes; res.direction = info.dir; res.file_name = info.file_name; - res.peer = boost::lexical_cast(info.peer); + res.peer = fmt::to_string(info.peer); res.session_index = 0; res.total_bytes = info.total_bytes; return res; @@ -62,7 +62,7 @@ static hs::stream_state get_state( state.plan_id = result_future.plan_id.to_sstring(); for (auto info : result_future.get_coordinator().get()->get_all_session_info()) { hs::stream_info si; - si.peer = boost::lexical_cast(info.peer); + si.peer = fmt::to_string(info.peer); si.session_index = 0; si.state = info.state; si.connecting = si.peer; diff --git a/gms/gossip_digest.hh b/gms/gossip_digest.hh index a2e7c312cc..7300ea5ed2 100644 --- a/gms/gossip_digest.hh +++ b/gms/gossip_digest.hh @@ -66,7 +66,8 @@ public: } friend inline std::ostream& operator<<(std::ostream& os, const gossip_digest& d) { - return os << d._endpoint << ":" << d._generation << ":" << d._max_version; + fmt::print(os, "{}:{}:{}", d._endpoint, d._generation, d._max_version); + return os; } }; // class gossip_digest diff --git a/init.cc b/init.cc index 983cbb4cff..eaa1e14a63 100644 --- a/init.cc +++ b/init.cc @@ -45,8 +45,8 @@ std::set get_seeds_from_db_config(const db::config& cfg) { seeds.emplace(gms::inet_address("127.0.0.1")); } auto broadcast_address = utils::fb_utilities::get_broadcast_address(); - startlog.info("seeds={}, listen_address={}, broadcast_address={}", - to_string(seeds), listen, broadcast_address); + startlog.info("seeds={{{}}}, listen_address={}, broadcast_address={}", + fmt::join(seeds, ", "), listen, broadcast_address); if (broadcast_address != listen && seeds.contains(listen)) { startlog.error("Use broadcast_address instead of listen_address for seeds list"); throw std::runtime_error("Use broadcast_address for seeds list"); diff --git a/message/messaging_service.cc b/message/messaging_service.cc index 6f2701f088..00fde555a0 100644 --- a/message/messaging_service.cc +++ b/message/messaging_service.cc @@ -163,7 +163,8 @@ bool operator<(const msg_addr& x, const msg_addr& y) noexcept { } std::ostream& operator<<(std::ostream& os, const msg_addr& x) { - return os << x.addr << ":" << x.cpu_id; + fmt::print(os, "{}:{}", x.addr, x.cpu_id); + return os; } size_t msg_addr::hash::operator()(const msg_addr& id) const noexcept {