From e35762241ac42016a5ea42c2a72034169a2abfee Mon Sep 17 00:00:00 2001 From: Alejo Sanchez Date: Thu, 12 Jan 2023 13:35:44 +0100 Subject: [PATCH] api: gossiper: fix alive nodes Fix API call to wait for all shards to reach the current shard 0 gossiper version. Throws when timeout is reached. Signed-off-by: Alejo Sanchez --- api/gossiper.cc | 8 +++++--- gms/gossiper.cc | 6 ++++++ gms/gossiper.hh | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/api/gossiper.cc b/api/gossiper.cc index e3fdac542f..8bb475e8b8 100644 --- a/api/gossiper.cc +++ b/api/gossiper.cc @@ -19,9 +19,11 @@ void set_gossiper(http_context& ctx, routes& r, gms::gossiper& g) { return container_to_vec(res); }); - httpd::gossiper_json::get_live_endpoint.set(r, [&g] (const_req req) { - auto res = g.get_live_members(); - return container_to_vec(res); + + httpd::gossiper_json::get_live_endpoint.set(r, [&g] (std::unique_ptr req) { + return g.get_live_members_synchronized().then([] (auto res) { + return make_ready_future(container_to_vec(res)); + }); }); httpd::gossiper_json::get_endpoint_downtime.set(r, [&g] (const_req req) { diff --git a/gms/gossiper.cc b/gms/gossiper.cc index 1e0c5981d4..a597e1eaaf 100644 --- a/gms/gossiper.cc +++ b/gms/gossiper.cc @@ -757,6 +757,12 @@ future<> gossiper::update_live_endpoints_version() { }); } +future> gossiper::get_live_members_synchronized() { + auto live_members = gossiper::get_live_members(); + co_await replicate_live_endpoints_on_change(); + co_return live_members; +} + future<> gossiper::failure_detector_loop_for_node(gms::inet_address node, int64_t gossip_generation, uint64_t live_endpoints_version) { auto last = gossiper::clk::now(); auto diff = gossiper::clk::duration(0); diff --git a/gms/gossiper.hh b/gms/gossiper.hh index d2866eb805..fc4983cccc 100644 --- a/gms/gossiper.hh +++ b/gms/gossiper.hh @@ -440,6 +440,9 @@ public: // Wait for nodes to be alive on all shards future<> wait_alive(std::vector nodes, std::chrono::milliseconds timeout); + // Get live members synchronized to all shards + future> get_live_members_synchronized(); + future<> apply_state_locally(std::map map); private: