Merge 'schema_tables: turn view schema fixing code into a sanity check' from Kamil Braun
The purpose of `maybe_fix_legacy_secondary_index_mv_schema` was to deal with legacy materialized view schemas used for secondary indexes, schemas which were created before the notion of "computed columns" was introduced. Back then, secondary index schemas would use a regular "token" column. Later it became a computed column and old schemas would be migrated during rolling upgrade. The migration code was introduced in 2019 (db8d4a0cc6) and then fixed in 2020 (d473bc9b06). The fix was present in Enterprise 2022.1 and in OSS 4.5. So, assuming that users don't try crazy things like upgrading from 2021.X to 2023.X (which we do not support), all clusters will have already executed the migration code once they upgrade to 2023.X, meaning we can get rid of it. The main motivation of this PR is to get rid of the `db::schema_tables::merge_schema` call in `parse_schema_tables`. In Raft mode this was the only call to `merge_schema` outside "group 0 code" and in fact it is unsafe -- it uses locally generated mutations with locally generated timestamp (`api::new_timestamp()`), so if we actually did it, we would permanently diverge the group 0 state machine across nodes (the schema pulling code is disabled in Raft mode). Fortunately, this should be dead code by now, as explained in the previous paragraph. The migration code is now turned into a sanity check, if the users try something crazy, they will get an error instead of silent data corruption. Closes scylladb/scylladb#15695 * github.com:scylladb/scylladb: view: remove unused `_backing_secondary_index` schema_tables: turn view schema fixing code into a sanity check schema_tables: make comment more precise feature_service: make COMPUTED_COLUMNS feature unconditionally true
This commit is contained in:
@@ -575,15 +575,13 @@ private:
|
||||
const partition_key& _base_key;
|
||||
const clustering_or_static_row& _update;
|
||||
const std::optional<clustering_or_static_row>& _existing;
|
||||
const bool _backing_secondary_index;
|
||||
|
||||
public:
|
||||
value_getter(const schema& base, const partition_key& base_key, const clustering_or_static_row& update, const std::optional<clustering_or_static_row>& existing, bool backing_secondary_index)
|
||||
value_getter(const schema& base, const partition_key& base_key, const clustering_or_static_row& update, const std::optional<clustering_or_static_row>& existing)
|
||||
: _base(base)
|
||||
, _base_key(base_key)
|
||||
, _update(update)
|
||||
, _existing(existing)
|
||||
, _backing_secondary_index(backing_secondary_index)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -616,22 +614,18 @@ public:
|
||||
|
||||
private:
|
||||
vector_type handle_computed_column(const column_definition& cdef) {
|
||||
bytes computed_value;
|
||||
if (!cdef.is_computed()) {
|
||||
//FIXME(sarna): this legacy code is here for backward compatibility and should be removed
|
||||
// once "computed_columns feature" is supported by every node
|
||||
if (!_backing_secondary_index) {
|
||||
throw std::logic_error(format("Column {} doesn't exist in base and this view is not backing a secondary index", cdef.name_as_text()));
|
||||
}
|
||||
computed_value = legacy_token_column_computation().compute_value(_base, _base_key);
|
||||
} else {
|
||||
auto& computation = cdef.get_computation();
|
||||
if (auto* collection_computation = dynamic_cast<const collection_column_computation*>(&computation)) {
|
||||
return handle_collection_column_computation(collection_computation);
|
||||
}
|
||||
computed_value = computation.compute_value(_base, _base_key);
|
||||
throw std::logic_error{format(
|
||||
"Detected legacy non-computed token column {} in view for table {}.{}",
|
||||
cdef.name_as_text(), _base.ks_name(), _base.cf_name())};
|
||||
}
|
||||
|
||||
auto& computation = cdef.get_computation();
|
||||
if (auto* collection_computation = dynamic_cast<const collection_column_computation*>(&computation)) {
|
||||
return handle_collection_column_computation(collection_computation);
|
||||
}
|
||||
|
||||
auto computed_value = computation.compute_value(_base, _base_key);
|
||||
return {managed_bytes_view(linearized_values.emplace_back(std::move(computed_value)))};
|
||||
}
|
||||
|
||||
@@ -653,7 +647,7 @@ private:
|
||||
|
||||
std::vector<view_updates::view_row_entry>
|
||||
view_updates::get_view_rows(const partition_key& base_key, const clustering_or_static_row& update, const std::optional<clustering_or_static_row>& existing) {
|
||||
value_getter getter(*_base, base_key, update, existing, _backing_secondary_index);
|
||||
value_getter getter(*_base, base_key, update, existing);
|
||||
auto get_value = boost::adaptors::transformed(std::ref(getter));
|
||||
|
||||
|
||||
@@ -1458,8 +1452,7 @@ view_update_builder make_view_update_builder(
|
||||
" base schema version of the view ({}) for view {}.{} of {}.{}",
|
||||
base->version(), v.base->base_schema()->version(), v.view->ks_name(), v.view->cf_name(), base->ks_name(), base->cf_name()));
|
||||
}
|
||||
bool is_index = base_table.get_index_manager().is_index(v.view);
|
||||
return view_updates(std::move(v), is_index);
|
||||
return view_updates(std::move(v));
|
||||
}));
|
||||
return view_update_builder(std::move(db), base_table, base, std::move(vs), std::move(updates), std::move(existings), now);
|
||||
}
|
||||
|
||||
@@ -210,15 +210,13 @@ class view_updates final {
|
||||
base_info_ptr _base_info;
|
||||
std::unordered_map<partition_key, mutation_partition, partition_key::hashing, partition_key::equality> _updates;
|
||||
mutable size_t _op_count = 0;
|
||||
const bool _backing_secondary_index;
|
||||
public:
|
||||
explicit view_updates(view_and_base vab, bool backing_secondary_index)
|
||||
explicit view_updates(view_and_base vab)
|
||||
: _view(std::move(vab.view))
|
||||
, _view_info(*_view->view_info())
|
||||
, _base(vab.base->base_schema())
|
||||
, _base_info(vab.base)
|
||||
, _updates(8, partition_key::hashing(*_view), partition_key::equality(*_view))
|
||||
, _backing_secondary_index(backing_secondary_index)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user