diff --git a/api/api.cc b/api/api.cc index 4f4d5c9f20..c04fb9080f 100644 --- a/api/api.cc +++ b/api/api.cc @@ -194,6 +194,10 @@ future<> set_server_storage_proxy(http_context& ctx, sharded unset_server_storage_proxy(http_context& ctx) { + return ctx.http_server.set_routes([&ctx] (routes& r) { unset_storage_proxy(ctx, r); }); +} + future<> set_server_stream_manager(http_context& ctx, sharded& sm) { return register_api(ctx, "stream_manager", "The stream manager API", [&sm] (http_context& ctx, routes& r) { diff --git a/api/api_init.hh b/api/api_init.hh index 8318307ae0..c3951ef483 100644 --- a/api/api_init.hh +++ b/api/api_init.hh @@ -107,6 +107,7 @@ future<> unset_server_load_sstable(http_context& ctx); future<> set_server_messaging_service(http_context& ctx, sharded& ms); future<> unset_server_messaging_service(http_context& ctx); future<> set_server_storage_proxy(http_context& ctx, sharded& ss); +future<> unset_server_storage_proxy(http_context& ctx); future<> set_server_stream_manager(http_context& ctx, sharded& sm); future<> unset_server_stream_manager(http_context& ctx); future<> set_hinted_handoff(http_context& ctx, sharded& g); diff --git a/api/storage_proxy.cc b/api/storage_proxy.cc index 4eb0c67d9e..7a22a52978 100644 --- a/api/storage_proxy.cc +++ b/api/storage_proxy.cc @@ -191,36 +191,36 @@ void set_storage_proxy(http_context& ctx, routes& r, sharded(0); }); - sp::get_hinted_handoff_enabled.set(r, [](std::unique_ptr req) { - const auto& filter = service::get_storage_proxy().local().get_hints_host_filter(); + sp::get_hinted_handoff_enabled.set(r, [&ctx](std::unique_ptr req) { + const auto& filter = ctx.sp.local().get_hints_host_filter(); return make_ready_future(!filter.is_disabled_for_all()); }); - sp::set_hinted_handoff_enabled.set(r, [](std::unique_ptr req) { + sp::set_hinted_handoff_enabled.set(r, [&ctx](std::unique_ptr req) { auto enable = req->get_query_param("enable"); auto filter = (enable == "true" || enable == "1") ? db::hints::host_filter(db::hints::host_filter::enabled_for_all_tag {}) : db::hints::host_filter(db::hints::host_filter::disabled_for_all_tag {}); - return service::get_storage_proxy().invoke_on_all([filter = std::move(filter)] (service::storage_proxy& sp) { + return ctx.sp.invoke_on_all([filter = std::move(filter)] (service::storage_proxy& sp) { return sp.change_hints_host_filter(filter); }).then([] { return make_ready_future(json_void()); }); }); - sp::get_hinted_handoff_enabled_by_dc.set(r, [](std::unique_ptr req) { + sp::get_hinted_handoff_enabled_by_dc.set(r, [&ctx](std::unique_ptr req) { std::vector res; - const auto& filter = service::get_storage_proxy().local().get_hints_host_filter(); + const auto& filter = ctx.sp.local().get_hints_host_filter(); const auto& dcs = filter.get_dcs(); res.reserve(res.size()); std::copy(dcs.begin(), dcs.end(), std::back_inserter(res)); return make_ready_future(res); }); - sp::set_hinted_handoff_enabled_by_dc_list.set(r, [](std::unique_ptr req) { + sp::set_hinted_handoff_enabled_by_dc_list.set(r, [&ctx](std::unique_ptr req) { auto dcs = req->get_query_param("dcs"); auto filter = db::hints::host_filter::parse_from_dc_list(std::move(dcs)); - return service::get_storage_proxy().invoke_on_all([filter = std::move(filter)] (service::storage_proxy& sp) { + return ctx.sp.invoke_on_all([filter = std::move(filter)] (service::storage_proxy& sp) { return sp.change_hints_host_filter(filter); }).then([] { return make_ready_future(json_void()); @@ -518,4 +518,73 @@ void set_storage_proxy(http_context& ctx, routes& r, sharded& ss); +void unset_storage_proxy(http_context& ctx, httpd::routes& r); } diff --git a/api/storage_service.cc b/api/storage_service.cc index 6d721798b0..0a01e404db 100644 --- a/api/storage_service.cc +++ b/api/storage_service.cc @@ -1023,12 +1023,11 @@ void set_storage_service(http_context& ctx, routes& r, sharded(res); }); - ss::reset_local_schema.set(r, [&sys_ks](std::unique_ptr req) { + ss::reset_local_schema.set(r, [&ctx, &sys_ks](std::unique_ptr req) { // FIXME: We should truncate schema tables if more than one node in the cluster. - auto& sp = service::get_storage_proxy(); - auto& fs = sp.local().features(); + auto& fs = ctx.sp.local().features(); apilog.info("reset_local_schema"); - return db::schema_tables::recalculate_schema_version(sys_ks, sp, fs).then([] { + return db::schema_tables::recalculate_schema_version(sys_ks, ctx.sp, fs).then([] { return make_ready_future(json_void()); }); }); diff --git a/db/view/view.cc b/db/view/view.cc index b9525c70fd..f7586fcf5c 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -2094,16 +2094,15 @@ future<> view_builder::calculate_shard_build_step(view_builder_init_state& vbi) future> view_builder::view_build_statuses(sstring keyspace, sstring view_name) const { - return _sys_dist_ks.view_status(std::move(keyspace), std::move(view_name)).then([] (std::unordered_map status) { - std::unordered_map status_map; - const auto& topo = service::get_local_storage_proxy().get_token_metadata_ptr()->get_topology(); - topo.for_each_node([&] (const locator::node *node) { - auto it = status.find(node->host_id()); - auto s = it != status.end() ? std::move(it->second) : "UNKNOWN"; - status_map.emplace(node->endpoint().to_sstring(), std::move(s)); - }); - return status_map; + std::unordered_map status = co_await _sys_dist_ks.view_status(std::move(keyspace), std::move(view_name)); + std::unordered_map status_map; + const auto& topo = _db.get_token_metadata().get_topology(); + topo.for_each_node([&] (const locator::node *node) { + auto it = status.find(node->host_id()); + auto s = it != status.end() ? std::move(it->second) : "UNKNOWN"; + status_map.emplace(node->endpoint().to_sstring(), std::move(s)); }); + co_return status_map; } future<> view_builder::add_new_view(view_ptr view, build_step& step) { diff --git a/main.cc b/main.cc index e74445f444..0935a5e5a7 100644 --- a/main.cc +++ b/main.cc @@ -1318,6 +1318,9 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl api::unset_server_snitch(ctx).get(); }); api::set_server_storage_proxy(ctx, ss).get(); + auto stop_sp_api = defer_verbose_shutdown("storage proxy API", [&ctx] { + api::unset_server_storage_proxy(ctx).get(); + }); api::set_server_load_sstable(ctx, sys_ks).get(); auto stop_cf_api = defer_verbose_shutdown("column family API", [&ctx] { api::unset_server_load_sstable(ctx).get();