From 328954c2142ef614f0e67f4f0d9a33b07c52400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ma=C5=9Blanka?= Date: Wed, 12 Jun 2024 07:23:46 +0000 Subject: [PATCH] c/p_balancer: fixed possible overflow of final used ration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replicas eviction policy is asynchronously applied to each partition it may happen that the size of individual partitions is not exactly equal to the total usage size reported. In this case the individual partition sizes that are moved out of the node may sum up to a value larger than the total used bytes. Added a code preventing overflowing the final ratio in this case Signed-off-by: Michał Maślanka (cherry picked from commit ba31bfba7d1456b579799b05ab9913f124ff204a) --- src/v/cluster/partition_balancer_types.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/v/cluster/partition_balancer_types.h b/src/v/cluster/partition_balancer_types.h index b2ccbc09ba081..27bfc2a5e1a06 100644 --- a/src/v/cluster/partition_balancer_types.h +++ b/src/v/cluster/partition_balancer_types.h @@ -41,6 +41,13 @@ struct node_disk_space { double peak_used_ratio() const { return double(used + assigned) / total; } double final_used_ratio() const { + // it sometimes may happen that the partition replica size on one node + // is out of date with the total used size reported by a node space + // manager. This may lead to an overflow of final used ratio. + if (released >= used + assigned) { + return 0.0; + } + return double(used + assigned - released) / total; }