schema, everywhere: define and use table_id as a strong type
Define table_id as a distinct utils::tagged_uuid modeled after raft tagged_id, so it can be differentiated from other uuid-class types, in particular from table_schema_version. Fixes #11207 Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
@@ -1486,7 +1486,7 @@ future<> view_builder::drain() {
|
||||
}).handle_exception_type([] (const semaphore_timed_out&) {
|
||||
// ignored
|
||||
}).finally([this] {
|
||||
return parallel_for_each(_base_to_build_step, [] (std::pair<const utils::UUID, build_step>& p) {
|
||||
return parallel_for_each(_base_to_build_step, [] (std::pair<const table_id, build_step>& p) {
|
||||
return p.second.reader.close();
|
||||
});
|
||||
});
|
||||
@@ -1498,7 +1498,7 @@ future<> view_builder::stop() {
|
||||
return drain();
|
||||
}
|
||||
|
||||
view_builder::build_step& view_builder::get_or_create_build_step(utils::UUID base_id) {
|
||||
view_builder::build_step& view_builder::get_or_create_build_step(table_id base_id) {
|
||||
auto it = _base_to_build_step.find(base_id);
|
||||
if (it == _base_to_build_step.end()) {
|
||||
auto base = _db.find_column_family(base_id).shared_from_this();
|
||||
@@ -1526,7 +1526,7 @@ future<> view_builder::initialize_reader_at_current_token(build_step& step) {
|
||||
});
|
||||
}
|
||||
|
||||
void view_builder::load_view_status(view_builder::view_build_status status, std::unordered_set<utils::UUID>& loaded_views) {
|
||||
void view_builder::load_view_status(view_builder::view_build_status status, std::unordered_set<table_id>& loaded_views) {
|
||||
if (!status.next_token) {
|
||||
// No progress was made on this view, so we'll treat it as new.
|
||||
return;
|
||||
@@ -1544,14 +1544,14 @@ void view_builder::load_view_status(view_builder::view_build_status status, std:
|
||||
|
||||
void view_builder::reshard(
|
||||
std::vector<std::vector<view_builder::view_build_status>> view_build_status_per_shard,
|
||||
std::unordered_set<utils::UUID>& loaded_views) {
|
||||
std::unordered_set<table_id>& loaded_views) {
|
||||
// We must reshard. We aim for a simple algorithm, a step above not starting from scratch.
|
||||
// Shards build entries at different paces, so both first and last tokens will differ. We
|
||||
// want to be conservative when selecting the range that has been built. To do that, we
|
||||
// select the intersection of all the previous shard's ranges for each view.
|
||||
struct view_ptr_hash {
|
||||
std::size_t operator()(const view_ptr& v) const noexcept {
|
||||
return std::hash<utils::UUID>()(v->id());
|
||||
return std::hash<table_id>()(v->id());
|
||||
}
|
||||
};
|
||||
struct view_ptr_equals {
|
||||
@@ -1646,7 +1646,7 @@ void view_builder::setup_shard_build_step(
|
||||
return view_ptr(nullptr);
|
||||
};
|
||||
|
||||
vbi.built_views = boost::copy_range<std::unordered_set<utils::UUID>>(built
|
||||
vbi.built_views = boost::copy_range<std::unordered_set<table_id>>(built
|
||||
| boost::adaptors::transformed(maybe_fetch_view)
|
||||
| boost::adaptors::filtered([] (const view_ptr& v) { return bool(v); })
|
||||
| boost::adaptors::transformed([] (const view_ptr& v) { return v->id(); }));
|
||||
@@ -1683,7 +1683,7 @@ future<> view_builder::calculate_shard_build_step(view_builder_init_state& vbi)
|
||||
return false;
|
||||
}
|
||||
};
|
||||
std::unordered_set<utils::UUID> loaded_views;
|
||||
std::unordered_set<table_id> loaded_views;
|
||||
if (vbi.status_per_shard.size() != smp::count) {
|
||||
reshard(std::move(vbi.status_per_shard), loaded_views);
|
||||
} else if (!vbi.status_per_shard.empty()) {
|
||||
|
||||
@@ -144,7 +144,7 @@ class view_builder final : public service::migration_listener::only_view_notific
|
||||
}
|
||||
};
|
||||
|
||||
using base_to_build_step_type = std::unordered_map<utils::UUID, build_step>;
|
||||
using base_to_build_step_type = std::unordered_map<table_id, build_step>;
|
||||
|
||||
replica::database& _db;
|
||||
db::system_distributed_keyspace& _sys_dist_ks;
|
||||
@@ -160,7 +160,7 @@ class view_builder final : public service::migration_listener::only_view_notific
|
||||
seastar::abort_source _as;
|
||||
future<> _started = make_ready_future<>();
|
||||
// Used to coordinate between shards the conclusion of the build process for a particular view.
|
||||
std::unordered_set<utils::UUID> _built_views;
|
||||
std::unordered_set<table_id> _built_views;
|
||||
// Counter and promise (both on shard 0 only!) allowing to wait for all
|
||||
// shards to have read the view build statuses
|
||||
unsigned _shards_finished_read = 0;
|
||||
@@ -173,7 +173,7 @@ class view_builder final : public service::migration_listener::only_view_notific
|
||||
struct view_builder_init_state {
|
||||
std::vector<future<>> bookkeeping_ops;
|
||||
std::vector<std::vector<view_build_status>> status_per_shard;
|
||||
std::unordered_set<utils::UUID> built_views;
|
||||
std::unordered_set<table_id> built_views;
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -215,10 +215,10 @@ public:
|
||||
future<std::unordered_map<sstring, sstring>> view_build_statuses(sstring keyspace, sstring view_name) const;
|
||||
|
||||
private:
|
||||
build_step& get_or_create_build_step(utils::UUID);
|
||||
build_step& get_or_create_build_step(table_id);
|
||||
future<> initialize_reader_at_current_token(build_step&);
|
||||
void load_view_status(view_build_status, std::unordered_set<utils::UUID>&);
|
||||
void reshard(std::vector<std::vector<view_build_status>>, std::unordered_set<utils::UUID>&);
|
||||
void load_view_status(view_build_status, std::unordered_set<table_id>&);
|
||||
void reshard(std::vector<std::vector<view_build_status>>, std::unordered_set<table_id>&);
|
||||
void setup_shard_build_step(view_builder_init_state& vbi, std::vector<system_keyspace_view_name>, std::vector<system_keyspace_view_build_progress>);
|
||||
future<> calculate_shard_build_step(view_builder_init_state& vbi);
|
||||
future<> add_new_view(view_ptr, build_step&);
|
||||
|
||||
Reference in New Issue
Block a user