diff --git a/api/api.cc b/api/api.cc index 33b8ade4d7..4dee8b8b60 100644 --- a/api/api.cc +++ b/api/api.cc @@ -11,6 +11,7 @@ #include #include #include "storage_service.hh" +#include "token_metadata.hh" #include "commitlog.hh" #include "gossiper.hh" #include "failure_detector.hh" @@ -155,6 +156,14 @@ future<> unset_server_snapshot(http_context& ctx) { return ctx.http_server.set_routes([&ctx] (routes& r) { unset_snapshot(ctx, r); }); } +future<> set_server_token_metadata(http_context& ctx, sharded& ss) { + return ctx.http_server.set_routes([&ctx, &ss] (routes& r) { set_token_metadata(ctx, r, ss); }); +} + +future<> unset_server_token_metadata(http_context& ctx) { + return ctx.http_server.set_routes([&ctx] (routes& r) { unset_token_metadata(ctx, r); }); +} + future<> set_server_snitch(http_context& ctx, sharded& snitch) { return register_api(ctx, "endpoint_snitch_info", "The endpoint snitch info API", [&snitch] (http_context& ctx, routes& r) { set_endpoint_snitch(ctx, r, snitch); diff --git a/api/api_init.hh b/api/api_init.hh index 1782091a22..5167341f11 100644 --- a/api/api_init.hh +++ b/api/api_init.hh @@ -103,6 +103,8 @@ future<> set_server_authorization_cache(http_context& ctx, sharded unset_server_authorization_cache(http_context& ctx); future<> set_server_snapshot(http_context& ctx, sharded& snap_ctl); future<> unset_server_snapshot(http_context& ctx); +future<> set_server_token_metadata(http_context& ctx, sharded& ss); +future<> unset_server_token_metadata(http_context& ctx); future<> set_server_gossip(http_context& ctx, sharded& g); future<> set_server_load_sstable(http_context& ctx, sharded& sys_ks); future<> unset_server_load_sstable(http_context& ctx); diff --git a/api/storage_service.cc b/api/storage_service.cc index ab7c61df3d..8dbdcee9cc 100644 --- a/api/storage_service.cc +++ b/api/storage_service.cc @@ -463,24 +463,6 @@ static future describe_ring_as_json(sharded& ss, service::raft_group0_client& group0_client) { - ss::local_hostid.set(r, [&ss](std::unique_ptr req) { - auto id = ss.local().get_token_metadata().get_my_id(); - return make_ready_future(id.to_sstring()); - }); - - ss::get_tokens.set(r, [&ss] (std::unique_ptr req) { - return make_ready_future(stream_range_as_array(ss.local().get_token_metadata().sorted_tokens(), [](const dht::token& i) { - return fmt::to_string(i); - })); - }); - - ss::get_node_tokens.set(r, [&ss] (std::unique_ptr req) { - gms::inet_address addr(req->param["endpoint"]); - return make_ready_future(stream_range_as_array(ss.local().get_token_metadata().get_tokens(addr), [](const dht::token& i) { - return fmt::to_string(i); - })); - }); - ss::get_commitlog.set(r, [&ctx](const_req req) { return ctx.db.local().commitlog()->active_config().commit_log_location; }); @@ -544,24 +526,6 @@ void set_storage_service(http_context& ctx, routes& r, sharded addr; - return container_to_vec(addr); - }); - - ss::get_joining_nodes.set(r, [&ss](const_req req) { - auto points = ss.local().get_token_metadata().get_bootstrap_tokens(); - std::unordered_set addr; - for (auto i: points) { - addr.insert(fmt::to_string(i.second)); - } - return container_to_vec(addr); - }); - ss::get_release_version.set(r, [&ss](const_req req) { return ss.local().get_release_version(); }); @@ -626,11 +590,6 @@ void set_storage_service(http_context& ctx, routes& r, shardedparam)); }); - ss::get_host_id_map.set(r, [&ss](const_req req) { - std::vector res; - return map_to_key_value(ss.local().get_token_metadata().get_endpoint_to_host_id_map_for_reading(), res); - }); - ss::get_load.set(r, [&ctx](std::unique_ptr req) { return get_cf_stats(ctx, &replica::column_family_stats::live_disk_space_used); }); @@ -1363,15 +1322,9 @@ void set_storage_service(http_context& ctx, routes& r, sharded& ss) { + ss::local_hostid.set(r, [&ss](std::unique_ptr req) { + auto id = ss.local().get_token_metadata().get_my_id(); + return make_ready_future(id.to_sstring()); + }); + + ss::get_tokens.set(r, [&ss] (std::unique_ptr req) { + return make_ready_future(stream_range_as_array(ss.local().get_token_metadata().sorted_tokens(), [](const dht::token& i) { + return fmt::to_string(i); + })); + }); + + ss::get_node_tokens.set(r, [&ss] (std::unique_ptr req) { + gms::inet_address addr(req->param["endpoint"]); + return make_ready_future(stream_range_as_array(ss.local().get_token_metadata().get_tokens(addr), [](const dht::token& i) { + return fmt::to_string(i); + })); + }); + + ss::get_leaving_nodes.set(r, [&ss](const_req req) { + return container_to_vec(ss.local().get_token_metadata().get_leaving_endpoints()); + }); + + ss::get_moving_nodes.set(r, [](const_req req) { + std::unordered_set addr; + return container_to_vec(addr); + }); + + ss::get_joining_nodes.set(r, [&ss](const_req req) { + auto points = ss.local().get_token_metadata().get_bootstrap_tokens(); + std::unordered_set addr; + for (auto i: points) { + addr.insert(fmt::to_string(i.second)); + } + return container_to_vec(addr); + }); + + ss::get_host_id_map.set(r, [&ss](const_req req) { + std::vector res; + return map_to_key_value(ss.local().get_token_metadata().get_endpoint_to_host_id_map_for_reading(), res); + }); +} + +void unset_token_metadata(http_context& ctx, routes& r) { + ss::local_hostid.unset(r); + ss::get_tokens.unset(r); + ss::get_node_tokens.unset(r); + ss::get_leaving_nodes.unset(r); + ss::get_moving_nodes.unset(r); + ss::get_joining_nodes.unset(r); + ss::get_host_id_map.unset(r); +} + +} diff --git a/api/token_metadata.hh b/api/token_metadata.hh new file mode 100644 index 0000000000..374ba594b0 --- /dev/null +++ b/api/token_metadata.hh @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023-present ScyllaDB + */ + +/* + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#pragma once + +#include +#include "api.hh" + +namespace service { class storage_service; } + +namespace api { + +void set_token_metadata(http_context& ctx, httpd::routes& r, sharded& ss); +void unset_token_metadata(http_context& ctx, httpd::routes& r); + +} diff --git a/configure.py b/configure.py index 4ddbb03cdc..268b3619ec 100755 --- a/configure.py +++ b/configure.py @@ -1191,6 +1191,7 @@ api = ['api/api.cc', Json2Code('api/api-doc/storage_service.json'), Json2Code('api/api-doc/lsa.json'), 'api/storage_service.cc', + 'api/token_metadata.cc', Json2Code('api/api-doc/commitlog.json'), 'api/commitlog.cc', Json2Code('api/api-doc/gossiper.json'), diff --git a/main.cc b/main.cc index 0105dadb4a..e5dc824c85 100644 --- a/main.cc +++ b/main.cc @@ -1360,6 +1360,13 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl api::unset_server_storage_service(ctx).get(); }); + // FIXME -- this can happen next to token_metadata start, but it needs "storage_service" + // API register, so it comes that late for now + api::set_server_token_metadata(ctx, ss).get(); + auto stop_tokens_api = defer_verbose_shutdown("token metadata API", [&ctx] { + api::unset_server_token_metadata(ctx).get(); + }); + supervisor::notify("initializing virtual tables"); smp::invoke_on_all([&] { return db::initialize_virtual_tables(db, ss, gossiper, raft_gr, sys_ks, *cfg);