db/view/view_builder: Allow synchronizing with the end of a build
Intended for use by unit tests, this patch allows synchronizing with the end of a build for a particular view. Signed-off-by: Duarte Nunes <duarte@scylladb.com>
This commit is contained in:
@@ -1478,6 +1478,11 @@ future<> view_builder::maybe_mark_view_as_built(view_ptr view, dht::token next_t
|
||||
system_keyspace::mark_view_as_built(view->ks_name(), view->cf_name()),
|
||||
builder._sys_dist_ks.finish_view_build(view->ks_name(), view->cf_name())).then([view] {
|
||||
return system_keyspace::remove_view_build_progress_across_all_shards(view->ks_name(), view->cf_name());
|
||||
}).then([&builder, view] {
|
||||
auto it = builder._build_notifiers.find(std::pair(view->ks_name(), view->cf_name()));
|
||||
if (it != builder._build_notifiers.end()) {
|
||||
it->second.set_value();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1485,5 +1490,12 @@ future<> view_builder::maybe_mark_view_as_built(view_ptr view, dht::token next_t
|
||||
});
|
||||
}
|
||||
|
||||
future<> view_builder::wait_until_built(const sstring& ks_name, const sstring& view_name, lowres_clock::time_point timeout) {
|
||||
return container().invoke_on(0, [ks_name, view_name, timeout] (view_builder& builder) {
|
||||
auto v = std::pair(std::move(ks_name), std::move(view_name));
|
||||
return builder._build_notifiers[std::move(v)].get_shared_future(timeout);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace view
|
||||
} // namespace db
|
||||
|
||||
@@ -36,8 +36,10 @@
|
||||
|
||||
#include <seastar/core/abort_source.hh>
|
||||
#include <seastar/core/future.hh>
|
||||
#include <seastar/core/lowres_clock.hh>
|
||||
#include <seastar/core/semaphore.hh>
|
||||
#include <seastar/core/sharded.hh>
|
||||
#include <seastar/core/shared_future.hh>
|
||||
#include <seastar/core/shared_ptr.hh>
|
||||
|
||||
#include <optional>
|
||||
@@ -148,6 +150,8 @@ class view_builder final : public service::migration_listener::only_view_notific
|
||||
seastar::abort_source _as;
|
||||
// Used to coordinate between shards the conclusion of the build process for a particular view.
|
||||
std::unordered_set<utils::UUID> _built_views;
|
||||
// Used for testing.
|
||||
std::unordered_map<std::pair<sstring, sstring>, seastar::shared_promise<>, utils::tuple_hash> _build_notifiers;
|
||||
|
||||
public:
|
||||
static constexpr size_t batch_size = 128;
|
||||
@@ -172,6 +176,9 @@ public:
|
||||
virtual void on_update_view(const sstring& ks_name, const sstring& view_name, bool columns_changed) override;
|
||||
virtual void on_drop_view(const sstring& ks_name, const sstring& view_name) override;
|
||||
|
||||
// For tests
|
||||
future<> wait_until_built(const sstring& ks_name, const sstring& view_name, lowres_clock::time_point timeout);
|
||||
|
||||
private:
|
||||
build_step& get_or_create_build_step(utils::UUID);
|
||||
void initialize_reader_at_current_token(build_step&);
|
||||
|
||||
Reference in New Issue
Block a user