Skip to content

Commit

Permalink
Implement proposed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Balwancia committed Nov 21, 2024
1 parent b6248b5 commit 997e78b
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cql3/statements/create_index_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ create_index_statement::validate(query_processor& qp, const service::client_stat
throw exceptions::invalid_request_exception("Only CUSTOM indexes can be created without specifying a target column");
}

_properties->validate();
gms::feature_service fs = gms::feature_service(gms::feature_config_from_db_config(qp.db().get_config()));
_properties->validate(fs);
}

std::vector<::shared_ptr<index_target>> create_index_statement::validate_while_executing(data_dictionary::database db) const {
Expand Down
8 changes: 4 additions & 4 deletions cql3/statements/index_prop_defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
#include <set>
#include <seastar/core/print.hh>
#include "index_prop_defs.hh"
#include "gms/feature_service.hh"
#include "index/secondary_index.hh"
#include "exceptions/exceptions.hh"

void cql3::statements::index_prop_defs::validate() {
void cql3::statements::index_prop_defs::validate(gms::feature_service &fs) {
static std::set<sstring> keywords({ sstring(KW_OPTIONS) });

property_definitions::validate(keywords);

if (is_custom && !custom_class) {
throw exceptions::invalid_request_exception("CUSTOM index requires specifying the index class");
}

if (!is_custom && custom_class && *custom_class != "dummy-vector-backend") {
throw exceptions::invalid_request_exception("Cannot specify non-vector index class for a non-CUSTOM index");
if (custom_class && !(fs.supported_custom_classes().contains(*custom_class))) {
throw exceptions::invalid_request_exception("Unsupported custom index class " + *custom_class);
}
if (!is_custom && !_properties.empty()) {
throw exceptions::invalid_request_exception("Cannot specify options for a non-CUSTOM index");
Expand Down
3 changes: 2 additions & 1 deletion cql3/statements/index_prop_defs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include "gms/feature_service.hh"
#include "property_definitions.hh"
#include <seastar/core/sstring.hh>

Expand All @@ -29,7 +30,7 @@ public:
bool is_custom = false;
std::optional<sstring> custom_class;

void validate();
void validate(gms::feature_service &fs);
index_options_map get_raw_options();
index_options_map get_options();
};
Expand Down
8 changes: 8 additions & 0 deletions gms/feature_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,12 @@ future<> feature_service::enable(std::set<std::string_view> list) {
});
}

std::set<std::string_view> feature_service::supported_custom_classes() const {
std::set<std::string_view> classes = {
"dummy-vector-backend"sv,
};

return classes;
}

} // namespace gms
1 change: 1 addition & 0 deletions gms/feature_service.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public:
future<> enable(std::set<std::string_view> list);
db::schema_features cluster_schema_features() const;
std::set<std::string_view> supported_feature_set() const;
std::set<std::string_view> supported_custom_classes() const;

// Key in the 'system.scylla_local' table, that is used to
// persist enabled features
Expand Down
2 changes: 1 addition & 1 deletion index/secondary_index_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool secondary_index_manager::is_global_index(const schema& s) const {
});
}

std::optional<sstring> secondary_index_manager::vector_index_class(const schema& s) const {
std::optional<sstring> secondary_index_manager::custom_index_class(const schema& s) const {
auto range = _indices | std::views::values;
auto idx = std::ranges::find_if(range, [&s] (const index& i) {
return i.metadata().kind() != index_metadata_kind::custom && i.metadata().options().contains(cql3::statements::index_target::custom_index_option_name) && s.cf_name() == index_table_name(i.metadata().name());
Expand Down
2 changes: 1 addition & 1 deletion index/secondary_index_manager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public:
bool is_index(view_ptr) const;
bool is_index(const schema& s) const;
bool is_global_index(const schema& s) const;
std::optional<sstring> vector_index_class(const schema& s) const;
std::optional<sstring> custom_index_class(const schema& s) const;
private:
void add_index(const index_metadata& im);
};
Expand Down
4 changes: 2 additions & 2 deletions replica/schema_describe_helper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public:
return _db.find_column_family(base_id).get_index_manager().is_index(view_s);
}

virtual std::optional<sstring> vector_index_class(const table_id& base_id, const schema& view_s) const override {
return _db.find_column_family(base_id).get_index_manager().vector_index_class(view_s);
virtual std::optional<sstring> custom_index_class(const table_id& base_id, const schema& view_s) const override {
return _db.find_column_family(base_id).get_index_manager().custom_index_class(view_s);
}


Expand Down
6 changes: 3 additions & 3 deletions schema/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,9 @@ sstring schema::get_create_statement(const schema_describe_helper& helper, bool
<< cql3::util::maybe_quote(ks_name()) << "." << cql3::util::maybe_quote(view_info()->base_name());

describe_index_columns(os, is_local, *this, helper.find_schema(view_info()->base_id()));
auto vector_index_class = helper.vector_index_class(view_info()->base_id(), *this);
if (vector_index_class) {
os << " USING \'" << *vector_index_class <<"\'";
auto custom_index_class = helper.custom_index_class(view_info()->base_id(), *this);
if (custom_index_class) {
os << " USING \'" << *custom_index_class <<"\'";
}

os << ";\n";
Expand Down
2 changes: 1 addition & 1 deletion schema/schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class schema_describe_helper {
public:
virtual bool is_global_index(const table_id& base_id, const schema& view_s) const = 0;
virtual bool is_index(const table_id& base_id, const schema& view_s) const = 0;
virtual std::optional<sstring> vector_index_class(const table_id& base_id, const schema& view_s) const = 0;
virtual std::optional<sstring> custom_index_class(const table_id& base_id, const schema& view_s) const = 0;
virtual schema_ptr find_schema(const table_id& id) const = 0;
virtual ~schema_describe_helper() = default;
};
Expand Down
2 changes: 1 addition & 1 deletion seastar

0 comments on commit 997e78b

Please sign in to comment.