From a3509912843852a2c3d7d5d0bc0e8a83c12ecea1 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 19 May 2022 13:35:05 +0300 Subject: [PATCH] Disks: More accurate free space calculation for least_used Signed-off-by: Azat Khuzhin --- src/Disks/VolumeJBOD.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Disks/VolumeJBOD.h b/src/Disks/VolumeJBOD.h index 0fb80422d55..21d61e6dd8d 100644 --- a/src/Disks/VolumeJBOD.h +++ b/src/Disks/VolumeJBOD.h @@ -82,8 +82,9 @@ private: ReservationPtr reserve(uint64_t bytes) { ReservationPtr reservation = disk->reserve(bytes); - if (reservation) - free_size -= bytes; + /// Not just subtract bytes, but update the value, + /// since some reservations may be done directly via IDisk, or not by ClickHouse. + free_size = reservation->getUnreservedSpace(); return reservation; } };