mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 11:36:54 +00:00
index: fix local vector index locality detection after schema reload
When index metadata was deserialized from system tables during schema
reload, target_parser::is_local() failed to recognize local vector
indexes. It only handled the non-vector JSON format {"pk": [...],
"ck": [...]}, but vector indexes serialize their targets as
{"pk": [...], "tc": "..."}. As a result, every local vector index was
incorrectly marked as global after a schema reload.
Fix this by introducing vector_index::is_local() that recognizes the
vector-specific target format, and dispatching to it from the schema
deserialization code based on the index class name. This keeps
target_parser as secondary-index-specific and follows the same dispatch
pattern already used for target serialization.
Also remove the now-unused has_vector_index_on_column() helper (its
callers were removed by #29407).
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
#include "data_dictionary/user_types_metadata.hh"
|
||||
|
||||
#include "index/target_parser.hh"
|
||||
#include "index/vector_index.hh"
|
||||
#include "lang/lua.hh"
|
||||
#include "lang/manager.hh"
|
||||
|
||||
@@ -2473,7 +2474,11 @@ static index_metadata create_index_from_index_row(const query::result_set_row& r
|
||||
}
|
||||
index_metadata_kind kind = deserialize_index_kind(row.get_nonnull<sstring>("kind"));
|
||||
sstring target_string = options.at(cql3::statements::index_target::target_option_name);
|
||||
const index_metadata::is_local_index is_local(secondary_index::target_parser::is_local(target_string));
|
||||
auto class_it = options.find("class_name");
|
||||
bool is_vector = class_it != options.end() && class_it->second == "vector_index";
|
||||
const index_metadata::is_local_index is_local(
|
||||
is_vector ? secondary_index::vector_index::is_local(target_string)
|
||||
: secondary_index::target_parser::is_local(target_string));
|
||||
return index_metadata{index_name, options, kind, is_local};
|
||||
}
|
||||
|
||||
|
||||
@@ -327,13 +327,17 @@ void vector_index::validate(const schema &schema, const cql3::statements::index_
|
||||
check_index_options(properties);
|
||||
}
|
||||
|
||||
bool vector_index::has_vector_index_on_column(const schema& s, const sstring& target_name) {
|
||||
for (const auto& index : s.indices()) {
|
||||
if (is_vector_index_on_column(index, target_name)) {
|
||||
return true;
|
||||
}
|
||||
bool vector_index::is_local(const sstring& target_string) {
|
||||
std::optional<rjson::value> json_value = rjson::try_parse(target_string);
|
||||
if (!json_value || !json_value->IsObject()) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
rjson::value* pk = rjson::find(*json_value, PK_TARGET_KEY);
|
||||
if (!pk || !pk->IsArray() || pk->Empty()) {
|
||||
return false;
|
||||
}
|
||||
rjson::value* tc = rjson::find(*json_value, TC_TARGET_KEY);
|
||||
return tc && tc->IsString();
|
||||
}
|
||||
|
||||
bool vector_index::is_vector_index_on_column(const index_metadata& im, const sstring& target_name) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
const std::vector<::shared_ptr<cql3::statements::index_target>> &targets, const gms::feature_service& fs,
|
||||
const data_dictionary::database& db) const override;
|
||||
static bool has_index(const schema& s) { return has_index_impl<vector_index>(s); }
|
||||
static bool has_vector_index_on_column(const schema& s, const sstring& target_name);
|
||||
static bool is_local(const sstring& target_string);
|
||||
static bool is_vector_index_on_column(const index_metadata& im, const sstring& target_name);
|
||||
static void check_cdc_options(const schema& s) {
|
||||
check_cdc_options_impl<vector_index>(s);
|
||||
|
||||
Reference in New Issue
Block a user