diff --git a/api/api.cc b/api/api.cc index 3e05f78798..32e6e9663a 100644 --- a/api/api.cc +++ b/api/api.cc @@ -102,12 +102,16 @@ future<> unset_rpc_controller(http_context& ctx) { return ctx.http_server.set_routes([&ctx] (routes& r) { unset_rpc_controller(ctx, r); }); } -future<> set_server_storage_service(http_context& ctx, sharded& ss, sharded& g, sharded& sys_ks) { - return register_api(ctx, "storage_service", "The storage service API", [&ss, &g, &sys_ks] (http_context& ctx, routes& r) { - set_storage_service(ctx, r, ss, g.local(), sys_ks); +future<> set_server_storage_service(http_context& ctx, sharded& ss) { + return register_api(ctx, "storage_service", "The storage service API", [&ss] (http_context& ctx, routes& r) { + set_storage_service(ctx, r, ss); }); } +future<> unset_server_storage_service(http_context& ctx) { + return ctx.http_server.set_routes([&ctx] (routes& r) { unset_storage_service(ctx, r); }); +} + future<> set_server_sstables_loader(http_context& ctx, sharded& sst_loader) { return ctx.http_server.set_routes([&ctx, &sst_loader] (routes& r) { set_sstables_loader(ctx, r, sst_loader); }); } diff --git a/api/api_init.hh b/api/api_init.hh index d3be39e425..8a38989e51 100644 --- a/api/api_init.hh +++ b/api/api_init.hh @@ -85,7 +85,8 @@ future<> set_server_init(http_context& ctx); future<> set_server_config(http_context& ctx, const db::config& cfg); future<> set_server_snitch(http_context& ctx, sharded& snitch); future<> unset_server_snitch(http_context& ctx); -future<> set_server_storage_service(http_context& ctx, sharded& ss, sharded& g, sharded& sys_ks); +future<> set_server_storage_service(http_context& ctx, sharded& ss); +future<> unset_server_storage_service(http_context& ctx); future<> set_server_sstables_loader(http_context& ctx, sharded& sst_loader); future<> unset_server_sstables_loader(http_context& ctx); future<> set_server_view_builder(http_context& ctx, sharded& vb); diff --git a/api/storage_service.cc b/api/storage_service.cc index 3bfe210404..731b80747e 100644 --- a/api/storage_service.cc +++ b/api/storage_service.cc @@ -54,10 +54,6 @@ extern logging::logger apilog; namespace api { -const locator::token_metadata& http_context::get_token_metadata() { - return *shared_token_metadata.local().get(); -} - namespace ss = httpd::storage_service_json; using namespace json; @@ -465,21 +461,21 @@ static future describe_ring_as_json(sharded& ss, gms::gossiper& g, sharded& sys_ks) { - ss::local_hostid.set(r, [&ctx](std::unique_ptr req) { - auto id = ctx.db.local().get_token_metadata().get_my_id(); +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, [&ctx] (std::unique_ptr req) { - return make_ready_future(stream_range_as_array(ctx.get_token_metadata().sorted_tokens(), [](const dht::token& i) { + 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, [&ctx] (std::unique_ptr req) { + 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(ctx.get_token_metadata().get_tokens(addr), [](const dht::token& i) { + 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); })); }); @@ -547,8 +543,8 @@ void set_storage_service(http_context& ctx, routes& r, sharded addr; for (auto i: points) { addr.insert(fmt::to_string(i.second)); @@ -629,9 +625,9 @@ void set_storage_service(http_context& ctx, routes& r, shardedparam)); }); - ss::get_host_id_map.set(r, [&ctx](const_req req) { + ss::get_host_id_map.set(r, [&ss](const_req req) { std::vector res; - return map_to_key_value(ctx.get_token_metadata().get_endpoint_to_host_id_map_for_reading(), 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) { @@ -651,9 +647,9 @@ void set_storage_service(http_context& ctx, routes& r, sharded req) { + ss::get_current_generation_number.set(r, [&ss](std::unique_ptr req) { gms::inet_address ep(utils::fb_utilities::get_broadcast_address()); - return g.get_current_generation_number(ep).then([](gms::generation_type res) { + return ss.local().gossiper().get_current_generation_number(ep).then([](gms::generation_type res) { return make_ready_future(res.value()); }); }); @@ -898,11 +894,11 @@ void set_storage_service(http_context& ctx, routes& r, sharded(json_void()); }); - ss::is_initialized.set(r, [&ss, &g](std::unique_ptr req) { - return ss.local().get_operation_mode().then([&g] (auto mode) { + ss::is_initialized.set(r, [&ss](std::unique_ptr req) { + return ss.local().get_operation_mode().then([&ss] (auto mode) { bool is_initialized = mode >= service::storage_service::mode::STARTING; if (mode == service::storage_service::mode::NORMAL) { - is_initialized = g.is_enabled(); + is_initialized = ss.local().gossiper().is_enabled(); } return make_ready_future(is_initialized); }); @@ -1123,12 +1119,12 @@ void set_storage_service(http_context& ctx, routes& r, sharded(json_void()); }); - ss::get_cluster_name.set(r, [&g](const_req req) { - return g.get_cluster_name(); + ss::get_cluster_name.set(r, [&ss](const_req req) { + return ss.local().gossiper().get_cluster_name(); }); - ss::get_partitioner_name.set(r, [&g](const_req req) { - return g.get_partitioner_name(); + ss::get_partitioner_name.set(r, [&ss](const_req req) { + return ss.local().gossiper().get_partitioner_name(); }); ss::get_tombstone_warn_threshold.set(r, [](std::unique_ptr req) { @@ -1339,6 +1335,95 @@ void set_storage_service(http_context& ctx, routes& r, sharded parse_tables(const sstring& ks_name, http_context& ctx, con // if the parameter is not found or is empty, returns a list of all table infos in the keyspace. std::vector parse_table_infos(const sstring& ks_name, http_context& ctx, const std::unordered_map& query_params, sstring param_name); -void set_storage_service(http_context& ctx, httpd::routes& r, sharded& ss, gms::gossiper& g, sharded& sys_ls); +void set_storage_service(http_context& ctx, httpd::routes& r, sharded& ss); +void unset_storage_service(http_context& ctx, httpd::routes& r); void set_sstables_loader(http_context& ctx, httpd::routes& r, sharded& sst_loader); void unset_sstables_loader(http_context& ctx, httpd::routes& r); void set_view_builder(http_context& ctx, httpd::routes& r, sharded& vb); diff --git a/main.cc b/main.cc index 5d29e71e62..9b1b5e7d63 100644 --- a/main.cc +++ b/main.cc @@ -1357,6 +1357,12 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl auto stop_storage_service = defer_verbose_shutdown("storage_service", [&] { ss.stop().get(); }); + + api::set_server_storage_service(ctx, ss).get(); + auto stop_ss_api = defer_verbose_shutdown("storage service API", [&ctx] { + api::unset_server_storage_service(ctx).get(); + }); + supervisor::notify("initializing virtual tables"); smp::invoke_on_all([&] { return db::initialize_virtual_tables(db, ss, gossiper, raft_gr, sys_ks, *cfg); @@ -1590,7 +1596,6 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl auto stop_messaging_api = defer_verbose_shutdown("messaging service API", [&ctx] { api::unset_server_messaging_service(ctx).get(); }); - api::set_server_storage_service(ctx, ss, gossiper, sys_ks).get(); api::set_server_repair(ctx, repair).get(); auto stop_repair_api = defer_verbose_shutdown("repair API", [&ctx] { api::unset_server_repair(ctx).get(); diff --git a/service/storage_service.hh b/service/storage_service.hh index ec17b41b6c..b6bedd7051 100644 --- a/service/storage_service.hh +++ b/service/storage_service.hh @@ -228,6 +228,9 @@ private: return _batchlog_manager; } + friend struct ::node_ops_ctl; +public: + const gms::gossiper& gossiper() const noexcept { return _gossiper; }; @@ -236,9 +239,6 @@ private: return _gossiper; }; - friend struct ::node_ops_ctl; -public: - locator::effective_replication_map_factory& get_erm_factory() noexcept { return _erm_factory; }