From 61532eb53b91abd9d48f068a1ccfae51e60b2796 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Sat, 1 Feb 2025 00:04:27 +0100 Subject: [PATCH] topology_state_machine: Introduce lock transition Will be used in load balancer tests to prevent concurrent topology operations, in particular background load balancing. load balancer will be invoked explicitly by the test. Disabling load balancer in topology is not a solution, because we want the explicit call to perform the load balancing. --- docs/dev/topology-over-raft.md | 3 +++ service/storage_service.cc | 2 ++ service/topology_coordinator.cc | 4 ++++ service/topology_state_machine.cc | 1 + service/topology_state_machine.hh | 1 + 5 files changed, 11 insertions(+) diff --git a/docs/dev/topology-over-raft.md b/docs/dev/topology-over-raft.md index 5195ed2754..e3e39d6ab9 100644 --- a/docs/dev/topology-over-raft.md +++ b/docs/dev/topology-over-raft.md @@ -124,6 +124,9 @@ Additionally to specific node states, there entire topology can also be in a tra it from group 0. We also use this state to rollback a failed bootstrap or decommission. - `rollback_to_normal` - the decommission or removenode operation failed. Rollback the operation by moving the node we tried to decommission/remove back to the normal state. +- `lock` - the topology stays in this state until externally changed (to null state), preventing topology + requests from starting. Intended to be used in tests which want to prevent internally-triggered topology + operations during the test. When a node bootstraps, we create new tokens for it and a new CDC generation and enter the `commit_cdc_generation` state. Once the generation is committed, diff --git a/service/storage_service.cc b/service/storage_service.cc index 7a367a13fc..bbd4af7091 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -744,6 +744,8 @@ future<> storage_service::topology_state_load(state_change_hint hint) { return read_new_t::no; } switch (*state) { + case topology::transition_state::lock: + [[fallthrough]]; case topology::transition_state::join_group0: [[fallthrough]]; case topology::transition_state::tablet_migration: diff --git a/service/topology_coordinator.cc b/service/topology_coordinator.cc index f886b5fbea..5b9f907577 100644 --- a/service/topology_coordinator.cc +++ b/service/topology_coordinator.cc @@ -2341,6 +2341,10 @@ class topology_coordinator : public endpoint_lifecycle_subscriber { case topology::transition_state::tablet_resize_finalization: co_await handle_tablet_resize_finalization(std::move(guard)); break; + case topology::transition_state::lock: + release_guard(std::move(guard)); + co_await await_event(); + break; case topology::transition_state::left_token_ring: { auto node = get_node_to_work_on(std::move(guard)); diff --git a/service/topology_state_machine.cc b/service/topology_state_machine.cc index 190ffaab66..57b99e807a 100644 --- a/service/topology_state_machine.cc +++ b/service/topology_state_machine.cc @@ -153,6 +153,7 @@ static std::unordered_map transition_state_ {topology::transition_state::left_token_ring, "left token ring"}, {topology::transition_state::rollback_to_normal, "rollback to normal"}, {topology::transition_state::truncate_table, "truncate table"}, + {topology::transition_state::lock, "lock"}, }; // Allows old deprecated names to be recognized and point to the correct transition. diff --git a/service/topology_state_machine.hh b/service/topology_state_machine.hh index 8e7014c8ff..5e03e3d1d9 100644 --- a/service/topology_state_machine.hh +++ b/service/topology_state_machine.hh @@ -120,6 +120,7 @@ struct topology { left_token_ring, rollback_to_normal, truncate_table, + lock, }; std::optional tstate;