diff --git a/api/api.cc b/api/api.cc index 473c033be4..ac3754595a 100644 --- a/api/api.cc +++ b/api/api.cc @@ -225,14 +225,21 @@ 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); }); + co_await register_api(ctx, "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) { - 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 +271,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/api/cache_service.cc b/api/cache_service.cc index fe892c6fad..1def22f404 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 @@ -204,53 +204,53 @@ void set_cache_service(http_context& ctx, routes& r) { }); }); - 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); 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); } diff --git a/main.cc b/main.cc index 989741f682..3f47a6cee9 100644 --- a/main.cc +++ b/main.cc @@ -2106,11 +2106,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();