From 1b4b5397061f8a6945d60a24229de2d399d11a42 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 26 Aug 2025 11:17:06 +0300 Subject: [PATCH 1/4] api: Coroutinize set_server_column_family() To facilitate next patching Signed-off-by: Pavel Emelyanov --- api/api.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/api.cc b/api/api.cc index 473c033be4..18b3ab60d8 100644 --- a/api/api.cc +++ b/api/api.cc @@ -225,7 +225,7 @@ future<> unset_server_gossip(http_context& ctx) { } future<> set_server_column_family(http_context& ctx, sharded& db, sharded& sys_ks) { - return register_api(ctx, "column_family", + co_await register_api(ctx, "column_family", "The column family API", [&db, &sys_ks] (http_context& ctx, routes& r) { set_column_family(ctx, r, db, sys_ks); }); From 4e556214babe7a0f0b0bb41b4d95705cdfbbd62c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 26 Aug 2025 11:18:35 +0300 Subject: [PATCH 2/4] api: Squash (un)set_cache_service into ..._column_family The set_server_column_family() registers API handlers that work with replica::database. The set_server_cache() does the very same thing, but registers handlers with some other prefix. Squash the latter into former, later "cache" handlers will also make use of the database reference argument that's already available in ..._column_family() setter. Signed-off-by: Pavel Emelyanov --- api/api.cc | 16 ++++++---------- api/api_init.hh | 2 -- main.cc | 5 ----- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/api/api.cc b/api/api.cc index 18b3ab60d8..cb6fe2f6b2 100644 --- a/api/api.cc +++ b/api/api.cc @@ -229,10 +229,15 @@ future<> set_server_column_family(http_context& ctx, sharded& "The column family API", [&db, &sys_ks] (http_context& ctx, routes& r) { set_column_family(ctx, r, db, sys_ks); }); + co_await register_api(ctx, "cache_service", + "The cache service API", set_cache_service); } future<> unset_server_column_family(http_context& ctx) { - return ctx.http_server.set_routes([&ctx] (routes& r) { unset_column_family(ctx, r); }); + return ctx.http_server.set_routes([&ctx] (routes& r) { + unset_column_family(ctx, r); + unset_cache_service(ctx, r); + }); } future<> set_server_messaging_service(http_context& ctx, sharded& ms) { @@ -264,15 +269,6 @@ future<> unset_server_stream_manager(http_context& ctx) { return ctx.http_server.set_routes([&ctx] (routes& r) { unset_stream_manager(ctx, r); }); } -future<> set_server_cache(http_context& ctx) { - return register_api(ctx, "cache_service", - "The cache service API", set_cache_service); -} - -future<> unset_server_cache(http_context& ctx) { - return ctx.http_server.set_routes([&ctx] (routes& r) { unset_cache_service(ctx, r); }); -} - future<> set_hinted_handoff(http_context& ctx, sharded& proxy, sharded& g) { return register_api(ctx, "hinted_handoff", "The hinted handoff API", [&proxy, &g] (http_context& ctx, routes& r) { diff --git a/api/api_init.hh b/api/api_init.hh index 1da8c4ce67..f0e496e384 100644 --- a/api/api_init.hh +++ b/api/api_init.hh @@ -126,8 +126,6 @@ future<> set_server_stream_manager(http_context& ctx, sharded unset_server_stream_manager(http_context& ctx); future<> set_hinted_handoff(http_context& ctx, sharded& p, sharded& g); future<> unset_hinted_handoff(http_context& ctx); -future<> set_server_cache(http_context& ctx); -future<> unset_server_cache(http_context& ctx); future<> set_server_compaction_manager(http_context& ctx, sharded& cm); future<> unset_server_compaction_manager(http_context& ctx); future<> set_server_done(http_context& ctx); diff --git a/main.cc b/main.cc index acff30b4c5..48dfd989f4 100644 --- a/main.cc +++ b/main.cc @@ -2080,11 +2080,6 @@ sharded token_metadata; api::unset_server_tasks_compaction_module(ctx).get(); }); - api::set_server_cache(ctx).get(); - auto stop_cache_api = defer_verbose_shutdown("cache API", [&ctx] { - api::unset_server_cache(ctx).get(); - }); - api::set_server_commitlog(ctx, db).get(); auto stop_commitlog_api = defer_verbose_shutdown("commitlog API", [&ctx] { api::unset_server_commitlog(ctx).get(); From 596d4640ffd39c8d2afa15c6c116efe058544973 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 26 Aug 2025 11:20:13 +0300 Subject: [PATCH 3/4] api: Add sharded& arg to set_cache_service() The reference is already available in set_server_column_family(), pass it further so that "cache" handlers are able to use it (next patch). Signed-off-by: Pavel Emelyanov --- api/api.cc | 4 +++- api/cache_service.cc | 2 +- api/cache_service.hh | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/api.cc b/api/api.cc index cb6fe2f6b2..ac3754595a 100644 --- a/api/api.cc +++ b/api/api.cc @@ -230,7 +230,9 @@ future<> set_server_column_family(http_context& ctx, sharded& set_column_family(ctx, r, db, sys_ks); }); co_await register_api(ctx, "cache_service", - "The cache service API", set_cache_service); + "The cache service API", [&db] (http_context& ctx, routes& r) { + set_cache_service(ctx, db, r); + }); } future<> unset_server_column_family(http_context& ctx) { diff --git a/api/cache_service.cc b/api/cache_service.cc index fe892c6fad..91ee72cf0f 100644 --- a/api/cache_service.cc +++ b/api/cache_service.cc @@ -16,7 +16,7 @@ using namespace json; using namespace seastar::httpd; namespace cs = httpd::cache_service_json; -void set_cache_service(http_context& ctx, routes& r) { +void set_cache_service(http_context& ctx, sharded& db, routes& r) { cs::get_row_cache_save_period_in_seconds.set(r, [](std::unique_ptr req) { // We never save the cache // Origin uses 0 for never diff --git a/api/cache_service.hh b/api/cache_service.hh index 602b06841d..ba9080ad51 100644 --- a/api/cache_service.hh +++ b/api/cache_service.hh @@ -7,15 +7,20 @@ */ #pragma once +#include namespace seastar::httpd { class routes; } +namespace replica { +class database; +} + namespace api { struct http_context; -void set_cache_service(http_context& ctx, seastar::httpd::routes& r); +void set_cache_service(http_context& ctx, seastar::sharded& db, seastar::httpd::routes& r); void unset_cache_service(http_context& ctx, seastar::httpd::routes& r); } From 67b63768e4934a1fcde415c4ba60d449aa2f74b4 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 26 Aug 2025 11:22:18 +0300 Subject: [PATCH 4/4] api: Capture and use db in cache_service handlers Now the sharded& argument is there, so it can replace ctx one on handlers lambdas. Signed-off-by: Pavel Emelyanov --- api/cache_service.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/api/cache_service.cc b/api/cache_service.cc index 91ee72cf0f..1def22f404 100644 --- a/api/cache_service.cc +++ b/api/cache_service.cc @@ -204,53 +204,53 @@ void set_cache_service(http_context& ctx, sharded& db, routes }); }); - cs::get_row_hits.set(r, [&ctx] (std::unique_ptr req) { - return map_reduce_cf(ctx.db, uint64_t(0), [](const replica::column_family& cf) { + cs::get_row_hits.set(r, [&db] (std::unique_ptr req) { + return map_reduce_cf(db, uint64_t(0), [](const replica::column_family& cf) { return cf.get_row_cache().stats().hits.count(); }, std::plus()); }); - cs::get_row_requests.set(r, [&ctx] (std::unique_ptr req) { - return map_reduce_cf(ctx.db, uint64_t(0), [](const replica::column_family& cf) { + cs::get_row_requests.set(r, [&db] (std::unique_ptr req) { + return map_reduce_cf(db, uint64_t(0), [](const replica::column_family& cf) { return cf.get_row_cache().stats().hits.count() + cf.get_row_cache().stats().misses.count(); }, std::plus()); }); - cs::get_row_hit_rate.set(r, [&ctx] (std::unique_ptr req) { - return map_reduce_cf(ctx.db, ratio_holder(), [](const replica::column_family& cf) { + cs::get_row_hit_rate.set(r, [&db] (std::unique_ptr req) { + return map_reduce_cf(db, ratio_holder(), [](const replica::column_family& cf) { return ratio_holder(cf.get_row_cache().stats().hits.count() + cf.get_row_cache().stats().misses.count(), cf.get_row_cache().stats().hits.count()); }, std::plus()); }); - cs::get_row_hits_moving_avrage.set(r, [&ctx] (std::unique_ptr req) { - return map_reduce_cf_raw(ctx.db, utils::rate_moving_average(), [](const replica::column_family& cf) { + cs::get_row_hits_moving_avrage.set(r, [&db] (std::unique_ptr req) { + return map_reduce_cf_raw(db, utils::rate_moving_average(), [](const replica::column_family& cf) { return cf.get_row_cache().stats().hits.rate(); }, std::plus()).then([](const utils::rate_moving_average& m) { return make_ready_future(meter_to_json(m)); }); }); - cs::get_row_requests_moving_avrage.set(r, [&ctx] (std::unique_ptr req) { - return map_reduce_cf_raw(ctx.db, utils::rate_moving_average(), [](const replica::column_family& cf) { + cs::get_row_requests_moving_avrage.set(r, [&db] (std::unique_ptr req) { + return map_reduce_cf_raw(db, utils::rate_moving_average(), [](const replica::column_family& cf) { return cf.get_row_cache().stats().hits.rate() + cf.get_row_cache().stats().misses.rate(); }, std::plus()).then([](const utils::rate_moving_average& m) { return make_ready_future(meter_to_json(m)); }); }); - cs::get_row_size.set(r, [&ctx] (std::unique_ptr req) { + cs::get_row_size.set(r, [&db] (std::unique_ptr req) { // In origin row size is the weighted size. // We currently do not support weights, so we use raw size in bytes instead - return ctx.db.map_reduce0([](replica::database& db) -> uint64_t { + return db.map_reduce0([](replica::database& db) -> uint64_t { return db.row_cache_tracker().region().occupancy().used_space(); }, uint64_t(0), std::plus()).then([](const int64_t& res) { return make_ready_future(res); }); }); - cs::get_row_entries.set(r, [&ctx] (std::unique_ptr req) { - return ctx.db.map_reduce0([](replica::database& db) -> uint64_t { + cs::get_row_entries.set(r, [&db] (std::unique_ptr req) { + return db.map_reduce0([](replica::database& db) -> uint64_t { return db.row_cache_tracker().partitions(); }, uint64_t(0), std::plus()).then([](const int64_t& res) { return make_ready_future(res);