Skip to content

Commit

Permalink
Merge 'Sanitize /system/highest_supported_sstable_version API endpoin…
Browse files Browse the repository at this point in the history
…t' from Pavel Emelyanov

Its handler dereferences long chain of objects to get to the value it needs. There's shorter way.
Also, the endpoint in question is not unregistered on stop.

Closes scylladb#21279

* github.com:scylladb/scylladb:
  api: Make get_highest_supported_sstable_version use proper service
  api: Move system::get_highest_supported_sstable_version set/unset
  api: Scaffold for sstables-format-selector
  • Loading branch information
avikivity committed Oct 28, 2024
2 parents b09bb6b + 420baf5 commit 49d3e28
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
8 changes: 8 additions & 0 deletions api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ future<> unset_load_meter(http_context& ctx) {
return ctx.http_server.set_routes([&ctx] (routes& r) { unset_load_meter(ctx, r); });
}

future<> set_format_selector(http_context& ctx, db::sstables_format_selector& sel) {
return ctx.http_server.set_routes([&ctx, &sel] (routes& r) { set_format_selector(ctx, r, sel); });
}

future<> unset_format_selector(http_context& ctx) {
return ctx.http_server.set_routes([&ctx] (routes& r) { unset_format_selector(ctx, r); });
}

future<> set_server_sstables_loader(http_context& ctx, sharded<sstables_loader>& sst_loader) {
return ctx.http_server.set_routes([&ctx, &sst_loader] (routes& r) { set_sstables_loader(ctx, r, sst_loader); });
}
Expand Down
3 changes: 3 additions & 0 deletions api/api_init.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace cql_transport { class controller; }
namespace db {
class snapshot_ctl;
class config;
class sstables_format_selector;
namespace view {
class view_builder;
}
Expand Down Expand Up @@ -135,6 +136,8 @@ future<> set_server_raft(http_context&, sharded<service::raft_group_registry>&);
future<> unset_server_raft(http_context&);
future<> set_load_meter(http_context& ctx, service::load_meter& lm);
future<> unset_load_meter(http_context& ctx);
future<> set_format_selector(http_context& ctx, db::sstables_format_selector& sel);
future<> unset_format_selector(http_context& ctx);
future<> set_server_cql_server_test(http_context& ctx, cql_transport::controller& ctl);
future<> unset_server_cql_server_test(http_context& ctx);
future<> set_server_commitlog(http_context& ctx, sharded<replica::database>&);
Expand Down
15 changes: 11 additions & 4 deletions api/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "api/api-doc/system.json.hh"
#include "api/api-doc/metrics.json.hh"
#include "replica/database.hh"
#include "sstables/sstables_manager.hh"
#include "db/sstables-format-selector.hh"

#include <rapidjson/document.h>
#include <seastar/core/reactor.hh>
Expand Down Expand Up @@ -183,11 +183,18 @@ void set_system(http_context& ctx, routes& r) {
apilog.info("Profile dumped to {}", profile_dest);
return make_ready_future<json::json_return_type>(json::json_return_type(json::json_void()));
}) ;
}

hs::get_highest_supported_sstable_version.set(r, [&ctx] (const_req req) {
auto& table = ctx.db.local().find_column_family("system", "local");
return seastar::to_sstring(table.get_sstables_manager().get_highest_supported_format());
void set_format_selector(http_context& ctx, routes& r, db::sstables_format_selector& sel) {
hs::get_highest_supported_sstable_version.set(r, [&sel] (std::unique_ptr<request> req) {
return smp::submit_to(0, [&sel] {
return make_ready_future<json::json_return_type>(seastar::to_sstring(sel.selected_format()));
});
});
}

void unset_format_selector(http_context& ctx, routes& r) {
hs::get_highest_supported_sstable_version.unset(r);
}

}
5 changes: 5 additions & 0 deletions api/system.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ namespace seastar::httpd {
class routes;
}

namespace db { class sstables_format_selector; }

namespace api {

struct http_context;
void set_system(http_context& ctx, seastar::httpd::routes& r);

void set_format_selector(http_context& ctx, seastar::httpd::routes& r, db::sstables_format_selector& sel);
void unset_format_selector(http_context& ctx, seastar::httpd::routes& r);

}
5 changes: 5 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,11 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl

db::sstables_format_selector sst_format_selector(db);

api::set_format_selector(ctx, sst_format_selector).get();
auto stop_format_seletor_api = defer_verbose_shutdown("sstables format selector API", [&ctx] {
api::unset_format_selector(ctx).get();
});

supervisor::notify("starting system keyspace");
sys_ks.start(std::ref(qp), std::ref(db)).get();
// TODO: stop()?
Expand Down

0 comments on commit 49d3e28

Please sign in to comment.