Skip to content

Commit

Permalink
c/p_balancer: fixed possible overflow of final used ration
Browse files Browse the repository at this point in the history
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 <michal@redpanda.com>
(cherry picked from commit ba31bfb)
  • Loading branch information
mmaslankaprv authored and vbotbuildovich committed Jun 12, 2024
1 parent b0ed98c commit 328954c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/v/cluster/partition_balancer_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 328954c

Please sign in to comment.