diff --git a/src/v/cluster/partition_balancer_planner.cc b/src/v/cluster/partition_balancer_planner.cc index f3d9cd3509db8..5d27fa3a5c219 100644 --- a/src/v/cluster/partition_balancer_planner.cc +++ b/src/v/cluster/partition_balancer_planner.cc @@ -395,26 +395,49 @@ void partition_balancer_planner::get_full_node_reassignments( } } -std::vector -partition_balancer_planner::get_ntp_reassignments( +void partition_balancer_planner::get_unavailable_node_movement_cancelations( + std::vector& cancelations, + const reallocation_request_state& rrs) { + for (auto& update : _topic_table.in_progress_updates()) { + if ( + update.second.state + != topic_table::in_progress_state::update_requested) { + continue; + } + auto current_assignments = _topic_table.get_partition_assignment( + update.first); + if (!current_assignments.has_value()) { + continue; + } + for (auto& r : current_assignments->replicas) { + if (rrs.unavailable_nodes.contains(r.node_id)) { + cancelations.push_back(update.first); + continue; + } + } + } +} + +planner_result partition_balancer_planner::get_ntp_reassignments( const cluster_health_report& health_report, const std::vector& follower_metrics) { + reallocation_request_state rrs; + planner_result result; + + calculate_unavailable_nodes(follower_metrics, rrs); + if (_topic_table.has_updates_in_progress()) { - return {}; + get_unavailable_node_movement_cancelations(result.cancelations, rrs); + return result; } - reallocation_request_state rrs; - std::vector reassignments; - init_ntp_sizes_and_node_disk_reports_from_health_report(health_report, rrs); - - calculate_unavailable_nodes(follower_metrics, rrs); calculate_nodes_with_disk_constraints_violation(rrs); - get_unavailable_nodes_reassignments(reassignments, rrs); - get_full_node_reassignments(reassignments, rrs); + get_unavailable_nodes_reassignments(result.reassignments, rrs); + get_full_node_reassignments(result.reassignments, rrs); - return reassignments; + return result; } -} // namespace cluster \ No newline at end of file +} // namespace cluster diff --git a/src/v/cluster/partition_balancer_planner.h b/src/v/cluster/partition_balancer_planner.h index 3f5c7e5a0947c..8e0b83cbdfe3f 100644 --- a/src/v/cluster/partition_balancer_planner.h +++ b/src/v/cluster/partition_balancer_planner.h @@ -19,11 +19,6 @@ namespace cluster { -struct ntp_reassignments { - model::ntp ntp; - allocation_units allocation_units; -}; - struct planner_config { double max_disk_usage_ratio; // Size of partitions that can be planned to move in one request @@ -38,7 +33,7 @@ class partition_balancer_planner { topic_table& topic_table, partition_allocator& partition_allocator); - std::vector get_ntp_reassignments( + planner_result get_ntp_reassignments( const cluster_health_report&, const std::vector&); private: @@ -72,6 +67,9 @@ class partition_balancer_planner { void get_full_node_reassignments( std::vector&, reallocation_request_state&); + void get_unavailable_node_movement_cancelations( + std::vector& cancelations, const reallocation_request_state&); + void calculate_nodes_with_disk_constraints_violation( reallocation_request_state&); diff --git a/src/v/cluster/partition_balancer_types.h b/src/v/cluster/partition_balancer_types.h index af677c97575e3..3f5c0a0d450f0 100644 --- a/src/v/cluster/partition_balancer_types.h +++ b/src/v/cluster/partition_balancer_types.h @@ -10,6 +10,7 @@ #pragma once +#include "cluster/scheduling/types.h" #include "model/fundamental.h" #include "model/metadata.h" @@ -37,4 +38,14 @@ struct node_disk_space { } }; -} // namespace cluster \ No newline at end of file +struct ntp_reassignments { + model::ntp ntp; + allocation_units allocation_units; +}; + +struct planner_result { + std::vector reassignments; + std::vector cancelations; +}; + +} // namespace cluster