Files
scylladb/replica/schema_describe_helper.cc
Marcin Maliszkiewicz 19bc6ffcb0 replica: make truncate_table_on_all_shards get whole schema from table_shards
Before for views and indexes it was fetching base schema from db (and
couple other properties). This is a problem once we introduce atomic
tables and views deletion (in the following commit).
Because once we delete table it can no longer be fetched from db object,
and truncation is performed after atomically deleting all relevant
tables/views/indexes.

Now the whole relevant schema will be fetched via global_table_ptr
(table_shards) object.
2025-07-10 10:40:43 +02:00

57 lines
1.8 KiB
C++

/*
* Copyright (C) 2024-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#include "replica/schema_describe_helper.hh"
#include "data_dictionary/data_dictionary.hh"
#include "index/secondary_index_manager.hh"
#include "schema/schema.hh"
#include "view_info.hh"
#include "replica/database.hh"
namespace replica {
::schema_describe_helper make_schema_describe_helper(schema_ptr schema, const data_dictionary::database& db) {
::schema_describe_helper h{
.type = ::schema_describe_helper::type::table,
};
if (schema->is_view()) {
auto table = db.find_column_family(schema->view_info()->base_id());
h.base_schema = table.schema();
const auto& mgr = table.get_index_manager();
if (mgr.is_index(*schema)) {
h.type = ::schema_describe_helper::type::index;
h.is_global_index = mgr.is_global_index(*schema);
h.custom_index_class = mgr.custom_index_class(*schema);
} else {
h.type = ::schema_describe_helper::type::view;
}
}
return h;
}
::schema_describe_helper make_schema_describe_helper(const global_table_ptr& table_shards) {
::schema_describe_helper h{
.type = ::schema_describe_helper::type::table,
};
auto& schema = *table_shards->schema();
if (schema.is_view()) {
h.base_schema = table_shards.base().schema();
const auto& mgr = table_shards->get_index_manager();
if (mgr.is_index(schema)) {
h.type = ::schema_describe_helper::type::index;
h.is_global_index = mgr.is_global_index(schema);
h.custom_index_class = mgr.custom_index_class(schema);
} else {
h.type = ::schema_describe_helper::type::view;
}
}
return h;
}
} // namespace replica