replica: Fix undefined behavior in table::generate_and_propagate_view_updates()

Undefined behavior because the evaluation order is undefined.

With GCC, where evaluation is right-to-left, schema will be moved
once it's forwarded to make_flat_mutation_reader_from_mutations_v2().

The consequence is that memory tracking of mutation_fragment_v2
(for tracking only permit used by view update), which uses the schema,
can be incorrect. However, it's more likely that Scylla will crash
when estimating memory usage for row, which access schema column
information using schema::column_at(), which in turn asserts that
the requested column does really exist.

Fixes #13093.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>

Closes #13092

(cherry picked from commit 3fae46203d)
This commit is contained in:
Raphael S. Carvalho
2023-03-06 22:59:51 -03:00
committed by Avi Kivity
parent aeac63a3ee
commit cb78c3bf2c

View File

@@ -1776,10 +1776,11 @@ future<> table::generate_and_propagate_view_updates(const schema_ptr& base,
tracing::trace_state_ptr tr_state,
gc_clock::time_point now) const {
auto base_token = m.token();
auto m_schema = m.schema();
db::view::view_update_builder builder = co_await db::view::make_view_update_builder(
base,
std::move(views),
make_flat_mutation_reader_from_mutations(m.schema(), std::move(permit), {std::move(m)}),
make_flat_mutation_reader_from_mutations(std::move(m_schema), std::move(permit), {std::move(m)}),
std::move(existings),
now);