From 1104411f83c7a8fbeeeaffe1caf070e1cf4204fd Mon Sep 17 00:00:00 2001 From: Michael Litvak Date: Tue, 14 Jan 2025 11:08:06 +0200 Subject: [PATCH] view_builder: pass view name by value to write_view_build_status The function write_view_build_status takes two lambda functions and chooses which of them to run depending on the upgrade state. It might run both of them. The parameters ks_name and view_name should be passed by value instead of by reference because they are moved inside each lambda function. Otherwise, if both lambdas are run, the second call operates on invalid values that were moved. --- db/view/view.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/view/view.cc b/db/view/view.cc index 5cec26ace0..4ccded2c62 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -2356,7 +2356,7 @@ static future<> announce_with_raft( future<> view_builder::mark_view_build_started(sstring ks_name, sstring view_name) { co_await write_view_build_status( - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { co_await utils::get_local_injector().inject("view_builder_pause_add_new_view", utils::wait_for_message(5min)); const sstring query_string = format("INSERT INTO {}.{} (keyspace_name, view_name, host_id, status) VALUES (?, ?, ?, ?)", db::system_keyspace::NAME, db::system_keyspace::VIEW_BUILD_STATUS_V2); @@ -2365,7 +2365,7 @@ future<> view_builder::mark_view_build_started(sstring ks_name, sstring view_nam {std::move(ks_name), std::move(view_name), host_id.uuid(), "STARTED"}, "view builder: mark view build STARTED"); }, - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { co_await utils::get_local_injector().inject("view_builder_pause_add_new_view", utils::wait_for_message(5min)); co_await _sys_dist_ks.start_view_build(std::move(ks_name), std::move(view_name)); } @@ -2374,7 +2374,7 @@ future<> view_builder::mark_view_build_started(sstring ks_name, sstring view_nam future<> view_builder::mark_view_build_success(sstring ks_name, sstring view_name) { co_await write_view_build_status( - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { co_await utils::get_local_injector().inject("view_builder_pause_mark_success", utils::wait_for_message(5min)); const sstring query_string = format("UPDATE {}.{} SET status = ? WHERE keyspace_name = ? AND view_name = ? AND host_id = ?", db::system_keyspace::NAME, db::system_keyspace::VIEW_BUILD_STATUS_V2); @@ -2383,7 +2383,7 @@ future<> view_builder::mark_view_build_success(sstring ks_name, sstring view_nam {"SUCCESS", std::move(ks_name), std::move(view_name), host_id.uuid()}, "view builder: mark view build SUCCESS"); }, - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { co_await utils::get_local_injector().inject("view_builder_pause_mark_success", utils::wait_for_message(5min)); co_await _sys_dist_ks.finish_view_build(std::move(ks_name), std::move(view_name)); } @@ -2392,14 +2392,14 @@ future<> view_builder::mark_view_build_success(sstring ks_name, sstring view_nam future<> view_builder::remove_view_build_status(sstring ks_name, sstring view_name) { co_await write_view_build_status( - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { const sstring query_string = format("DELETE FROM {}.{} WHERE keyspace_name = ? AND view_name = ?", db::system_keyspace::NAME, db::system_keyspace::VIEW_BUILD_STATUS_V2); co_await announce_with_raft(_qp, _group0_client, _as, std::move(query_string), {std::move(ks_name), std::move(view_name)}, "view builder: delete view build status"); }, - [&] () -> future<> { + [this, ks_name, view_name] () -> future<> { co_await _sys_dist_ks.remove_view(std::move(ks_name), std::move(view_name)); } );