api: Move storage_service endpoints that use token metadata only
There are few of them that don't need the storage service for anything but get token metadata from. Move them to own .cc/.hh units. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <seastar/http/transformers.hh>
|
||||
#include <seastar/http/api_docs.hh>
|
||||
#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<service::storage_service>& 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<locator::snitch_ptr>& 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);
|
||||
|
||||
@@ -103,6 +103,8 @@ future<> set_server_authorization_cache(http_context& ctx, sharded<auth::service
|
||||
future<> unset_server_authorization_cache(http_context& ctx);
|
||||
future<> set_server_snapshot(http_context& ctx, sharded<db::snapshot_ctl>& snap_ctl);
|
||||
future<> unset_server_snapshot(http_context& ctx);
|
||||
future<> set_server_token_metadata(http_context& ctx, sharded<service::storage_service>& ss);
|
||||
future<> unset_server_token_metadata(http_context& ctx);
|
||||
future<> set_server_gossip(http_context& ctx, sharded<gms::gossiper>& g);
|
||||
future<> set_server_load_sstable(http_context& ctx, sharded<db::system_keyspace>& sys_ks);
|
||||
future<> unset_server_load_sstable(http_context& ctx);
|
||||
|
||||
@@ -463,24 +463,6 @@ static future<json::json_return_type> describe_ring_as_json(sharded<service::sto
|
||||
}
|
||||
|
||||
void set_storage_service(http_context& ctx, routes& r, sharded<service::storage_service>& ss, service::raft_group0_client& group0_client) {
|
||||
ss::local_hostid.set(r, [&ss](std::unique_ptr<http::request> req) {
|
||||
auto id = ss.local().get_token_metadata().get_my_id();
|
||||
return make_ready_future<json::json_return_type>(id.to_sstring());
|
||||
});
|
||||
|
||||
ss::get_tokens.set(r, [&ss] (std::unique_ptr<http::request> req) {
|
||||
return make_ready_future<json::json_return_type>(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<http::request> req) {
|
||||
gms::inet_address addr(req->param["endpoint"]);
|
||||
return make_ready_future<json::json_return_type>(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<service::storage_
|
||||
});
|
||||
});
|
||||
|
||||
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<sstring> 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<sstring> 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, sharded<service::storage_
|
||||
return describe_ring_as_json(ss, validate_keyspace(ctx, req->param));
|
||||
});
|
||||
|
||||
ss::get_host_id_map.set(r, [&ss](const_req req) {
|
||||
std::vector<ss::mapper> 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<http::request> 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<service::storage_
|
||||
}
|
||||
|
||||
void unset_storage_service(http_context& ctx, routes& r) {
|
||||
ss::local_hostid.unset(r);
|
||||
ss::get_tokens.unset(r);
|
||||
ss::get_node_tokens.unset(r);
|
||||
ss::get_commitlog.unset(r);
|
||||
ss::get_token_endpoint.unset(r);
|
||||
ss::toppartitions_generic.unset(r);
|
||||
ss::get_leaving_nodes.unset(r);
|
||||
ss::get_moving_nodes.unset(r);
|
||||
ss::get_joining_nodes.unset(r);
|
||||
ss::get_release_version.unset(r);
|
||||
ss::get_scylla_release_version.unset(r);
|
||||
ss::get_schema_version.unset(r);
|
||||
@@ -1381,7 +1334,6 @@ void unset_storage_service(http_context& ctx, routes& r) {
|
||||
ss::get_pending_range_to_endpoint_map.unset(r);
|
||||
ss::describe_any_ring.unset(r);
|
||||
ss::describe_ring.unset(r);
|
||||
ss::get_host_id_map.unset(r);
|
||||
ss::get_load.unset(r);
|
||||
ss::get_load_map.unset(r);
|
||||
ss::get_current_generation_number.unset(r);
|
||||
|
||||
73
api/token_metadata.cc
Normal file
73
api/token_metadata.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2023-present ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "storage_service.hh"
|
||||
#include "api/api-doc/storage_service.json.hh"
|
||||
#include "service/storage_service.hh"
|
||||
|
||||
using namespace seastar::httpd;
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace ss = httpd::storage_service_json;
|
||||
using namespace json;
|
||||
|
||||
void set_token_metadata(http_context& ctx, routes& r, sharded<service::storage_service>& ss) {
|
||||
ss::local_hostid.set(r, [&ss](std::unique_ptr<http::request> req) {
|
||||
auto id = ss.local().get_token_metadata().get_my_id();
|
||||
return make_ready_future<json::json_return_type>(id.to_sstring());
|
||||
});
|
||||
|
||||
ss::get_tokens.set(r, [&ss] (std::unique_ptr<http::request> req) {
|
||||
return make_ready_future<json::json_return_type>(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<http::request> req) {
|
||||
gms::inet_address addr(req->param["endpoint"]);
|
||||
return make_ready_future<json::json_return_type>(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<sstring> 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<sstring> 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<ss::mapper> 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);
|
||||
}
|
||||
|
||||
}
|
||||
21
api/token_metadata.hh
Normal file
21
api/token_metadata.hh
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2023-present ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <seastar/core/sharded.hh>
|
||||
#include "api.hh"
|
||||
|
||||
namespace service { class storage_service; }
|
||||
|
||||
namespace api {
|
||||
|
||||
void set_token_metadata(http_context& ctx, httpd::routes& r, sharded<service::storage_service>& ss);
|
||||
void unset_token_metadata(http_context& ctx, httpd::routes& r);
|
||||
|
||||
}
|
||||
@@ -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'),
|
||||
|
||||
7
main.cc
7
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);
|
||||
|
||||
Reference in New Issue
Block a user