From 21dee3d8ef7da525390b786e552678224186c1f9 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 22 Aug 2019 11:04:30 +0300 Subject: [PATCH 1/2] API:column_family.cc Add get_build_index implmentation This Patch adds an implementation of the get build index API and remove a FIXME. The API returns the list of the built secondary indexes belongs to a column family. Example: CREATE KEYSPACE scylla_demo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}; CREATE TABLE scylla_demo.mytableID ( uid uuid, text text, time timeuuid, PRIMARY KEY (uid, time) ); CREATE index on scylla_demo.mytableID (time); $ curl -X GET 'http://localhost:10000/column_family/built_indexes/scylla_demo%3Amytableid' ["mytableid_time_idx"] Signed-off-by: Amnon Heiman --- api/column_family.cc | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/api/column_family.cc b/api/column_family.cc index 5632dac345..0d3f60680f 100644 --- a/api/column_family.cc +++ b/api/column_family.cc @@ -27,6 +27,7 @@ #include "utils/estimated_histogram.hh" #include +#include "db/system_keyspace_view_types.hh" #include "db/data_listeners.hh" extern logging::logger apilog; @@ -53,8 +54,7 @@ std::tuple parse_fully_qualified_cf_name(sstring name) { return std::make_tuple(name.substr(0, pos), name.substr(end)); } -const utils::UUID& get_uuid(const sstring& name, const database& db) { - auto [ks, cf] = parse_fully_qualified_cf_name(name); +const utils::UUID& get_uuid(const sstring& ks, const sstring& cf, const database& db) { try { return db.find_uuid(ks, cf); } catch (std::out_of_range& e) { @@ -62,6 +62,11 @@ const utils::UUID& get_uuid(const sstring& name, const database& db) { } } +const utils::UUID& get_uuid(const sstring& name, const database& db) { + auto [ks, cf] = parse_fully_qualified_cf_name(name); + return get_uuid(ks, cf, db); +} + future<> foreach_column_family(http_context& ctx, const sstring& name, function f) { auto uuid = get_uuid(name, ctx.db.local()); @@ -843,13 +848,28 @@ void set_column_family(http_context& ctx, routes& r) { return true; }); - cf::get_built_indexes.set(r, [](const_req) { - // FIXME - // Currently there are no index support - return std::vector(); + cf::get_built_indexes.set(r, [&ctx](std::unique_ptr req) { + auto [ks, cf_name] = parse_fully_qualified_cf_name(req->param["name"]); + return db::system_keyspace::load_view_build_progress().then([ks, cf_name, &ctx](const std::vector& vb) mutable { + std::set vp; + for (auto b : vb) { + if (b.view.first == ks) { + vp.insert(b.view.second); + } + } + std::vector res; + auto uuid = get_uuid(ks, cf_name, ctx.db.local()); + column_family& cf = ctx.db.local().find_column_family(uuid); + res.reserve(cf.get_index_manager().list_indexes().size()); + for (auto&& i : cf.get_index_manager().list_indexes()) { + if (vp.find(secondary_index::index_table_name(i.metadata().name())) == vp.end()) { + res.emplace_back(i.metadata().name()); + } + } + return make_ready_future(res); + }); }); - cf::get_compression_metadata_off_heap_memory_used.set(r, [](const_req) { // FIXME // Currently there are no information on the compression From 2d3185fa7d9d5793b1945f2e53856b7796ce6e39 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Sun, 25 Aug 2019 16:51:14 +0300 Subject: [PATCH 2/2] column_family.cc: remove unhandle future The sum_ratio struct is a helper struct that is used when calculating ratio over multiple shards. Originally it was created thinking that it may need to use future, in practice it was never used and the future was ignore. This patch remove the future from the implementation and reduce an unhandle future warning from the compilation. Signed-off-by: Amnon Heiman --- api/column_family.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/column_family.cc b/api/column_family.cc index 0d3f60680f..4c9e72e7ca 100644 --- a/api/column_family.cc +++ b/api/column_family.cc @@ -26,7 +26,6 @@ #include "sstables/sstables.hh" #include "utils/estimated_histogram.hh" #include - #include "db/system_keyspace_view_types.hh" #include "db/data_listeners.hh" @@ -255,12 +254,11 @@ class sum_ratio { uint64_t _n = 0; T _total = 0; public: - future<> operator()(T value) { + void operator()(T value) { if (value > 0) { _total += value; _n++; } - return make_ready_future<>(); } // Returns average value of all registered ratios. T get() && {