From 1b2cd56bccfc2aecbec057e173895d02b5637ee5 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 17 Apr 2024 10:49:07 +0300 Subject: [PATCH] tablets: Generalize transition mutations preparation Tablet transition handlers prepare two mutations -- one for tablets table, that sets transition state, transition mode and few others; and another one for topology table that "activates" the tablet_migration state for topology coordinator. The latter is common to all three handlers. Signed-off-by: Pavel Emelyanov --- service/storage_service.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/service/storage_service.cc b/service/storage_service.cc index ae46627996..89b94bd8b8 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -5754,10 +5754,6 @@ future<> storage_service::move_tablet(table_id table, dht::token token, locator: .set_stage(last_token, locator::tablet_transition_stage::allow_write_both_read_old) .set_transition(last_token, locator::tablet_transition_kind::migration) .build()); - updates.emplace_back(topology_mutation_builder(write_timestamp) - .set_transition_state(topology::transition_state::tablet_migration) - .set_version(_topology_state_machine._topology.version + 1) - .build()); sstring reason = format("Moving tablet {} from {} to {}", gid, src, dst); @@ -5802,10 +5798,6 @@ future<> storage_service::add_tablet_replica(table_id table, dht::token token, l .set_stage(last_token, locator::tablet_transition_stage::allow_write_both_read_old) .set_transition(last_token, locator::tablet_transition_kind::rebuild) .build()); - updates.emplace_back(topology_mutation_builder(write_timestamp) - .set_transition_state(topology::transition_state::tablet_migration) - .set_version(_topology_state_machine._topology.version + 1) - .build()); sstring reason = format("Adding replica to tablet {}, node {}", gid, dst); @@ -5851,10 +5843,6 @@ future<> storage_service::del_tablet_replica(table_id table, dht::token token, l .set_stage(last_token, locator::tablet_transition_stage::allow_write_both_read_old) .set_transition(last_token, locator::tablet_transition_kind::rebuild) .build()); - updates.emplace_back(topology_mutation_builder(write_timestamp) - .set_transition_state(topology::transition_state::tablet_migration) - .set_version(_topology_state_machine._topology.version + 1) - .build()); sstring reason = format("Removing replica from tablet {}, node {}", gid, dst); @@ -5962,6 +5950,11 @@ future<> storage_service::transit_tablet(table_id table, dht::token token, nonco rtlogger.info("{}", reason); rtlogger.trace("do update {} reason {}", updates, reason); + updates.emplace_back(topology_mutation_builder(guard.write_timestamp()) + .set_transition_state(topology::transition_state::tablet_migration) + .set_version(_topology_state_machine._topology.version + 1) + .build()); + topology_change change{std::move(updates)}; group0_command g0_cmd = _group0->client().prepare_command(std::move(change), guard, reason); try {