From 821c8b19a68757efc56604f5601b1ba71a3701e5 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 13 Apr 2023 12:52:47 +0300 Subject: [PATCH] view: Carry backing-secondary-index bit via view builder When view builder constructs it populates itself with view updates. Later the updates may instantiate the value_getter-s which, in turn, would need to check if the view is backing secondary index. Good news is that when view builder constructs it has all the information at hand needed to evaluate this "backing" bit. It's then propagated down to value_getter via corresponding view_updates. The getter's _view field becomes unused after this change and is (void)-ed to make this patch compile. Signed-off-by: Pavel Emelyanov --- db/view/view.cc | 13 ++++++++----- db/view/view.hh | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/db/view/view.cc b/db/view/view.cc index 545561c00d..e536665661 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -574,14 +574,16 @@ private: const bool _backing_secondary_index; public: - value_getter(const schema& base, const view_ptr& view, const partition_key& base_key, const clustering_or_static_row& update, const std::optional& existing) + value_getter(const schema& base, const view_ptr& view, const partition_key& base_key, const clustering_or_static_row& update, const std::optional& existing, bool backing_secondary_index) : _base(base) , _view(view) , _base_key(base_key) , _update(update) , _existing(existing) - , _backing_secondary_index(service::get_local_storage_proxy().local_db().find_column_family(_base.id()).get_index_manager().is_index(*_view)) - {} + , _backing_secondary_index(backing_secondary_index) + { + (void)_view; + } using vector_type = utils::small_vector; vector_type operator()(const column_definition& cdef) { @@ -649,7 +651,7 @@ private: std::vector view_updates::get_view_rows(const partition_key& base_key, const clustering_or_static_row& update, const std::optional& existing) { - value_getter getter(*_base, _view, base_key, update, existing); + value_getter getter(*_base, _view, base_key, update, existing, _backing_secondary_index); auto get_value = boost::adaptors::transformed(std::ref(getter)); @@ -1452,7 +1454,8 @@ 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())); } - return view_updates(std::move(v)); + bool is_index = base_table.get_index_manager().is_index(v.view); + return view_updates(std::move(v), is_index); })); return view_update_builder(base_table, base, std::move(vs), std::move(updates), std::move(existings), now); } diff --git a/db/view/view.hh b/db/view/view.hh index 70ccd28bf1..a80e117102 100644 --- a/db/view/view.hh +++ b/db/view/view.hh @@ -209,13 +209,16 @@ class view_updates final { base_info_ptr _base_info; std::unordered_map _updates; mutable size_t _op_count = 0; + const bool _backing_secondary_index; public: - explicit view_updates(view_and_base vab) + explicit view_updates(view_and_base vab, bool backing_secondary_index) : _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)) { + , _updates(8, partition_key::hashing(*_view), partition_key::equality(*_view)) + , _backing_secondary_index(backing_secondary_index) + { } future<> move_to(utils::chunked_vector& mutations);