From 248709ea16b2d07f14a59d694f8463455260c4e1 Mon Sep 17 00:00:00 2001 From: Alexandre Snarskii Date: Sun, 7 Nov 2021 19:51:48 +0300 Subject: [PATCH 1/2] correct disk space calculations --- src/Disks/DiskLocal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Disks/DiskLocal.cpp b/src/Disks/DiskLocal.cpp index 2774bb1bfd2..a701a4e2cb1 100644 --- a/src/Disks/DiskLocal.cpp +++ b/src/Disks/DiskLocal.cpp @@ -172,7 +172,7 @@ UInt64 DiskLocal::getTotalSpace() const fs = getStatVFS((fs::path(disk_path) / "data/").string()); else fs = getStatVFS(disk_path); - UInt64 total_size = fs.f_blocks * fs.f_bsize; + UInt64 total_size = fs.f_blocks * fs.f_frsize; if (total_size < keep_free_space_bytes) return 0; return total_size - keep_free_space_bytes; @@ -187,7 +187,7 @@ UInt64 DiskLocal::getAvailableSpace() const fs = getStatVFS((fs::path(disk_path) / "data/").string()); else fs = getStatVFS(disk_path); - UInt64 total_size = fs.f_bavail * fs.f_bsize; + UInt64 total_size = fs.f_bavail * fs.f_frsize; if (total_size < keep_free_space_bytes) return 0; return total_size - keep_free_space_bytes; From c36c64a9a0672ae0f3451b21343aa1e9ab289315 Mon Sep 17 00:00:00 2001 From: Alexandre Snarskii Date: Tue, 9 Nov 2021 12:28:59 +0300 Subject: [PATCH 2/2] more corrections for disk size calculations --- src/Common/Exception.cpp | 4 ++-- src/Interpreters/AsynchronousMetrics.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp index fc6a18fd3b9..cdf5816237c 100644 --- a/src/Common/Exception.cpp +++ b/src/Common/Exception.cpp @@ -206,8 +206,8 @@ static void getNoSpaceLeftInfoMessage(std::filesystem::path path, String & msg) fmt::format_to(std::back_inserter(msg), "\nTotal space: {}\nAvailable space: {}\nTotal inodes: {}\nAvailable inodes: {}\nMount point: {}", - ReadableSize(fs.f_blocks * fs.f_bsize), - ReadableSize(fs.f_bavail * fs.f_bsize), + ReadableSize(fs.f_blocks * fs.f_frsize), + ReadableSize(fs.f_bavail * fs.f_frsize), formatReadableQuantity(fs.f_files), formatReadableQuantity(fs.f_favail), mount_point); diff --git a/src/Interpreters/AsynchronousMetrics.cpp b/src/Interpreters/AsynchronousMetrics.cpp index 66b105970af..121f7c4153f 100644 --- a/src/Interpreters/AsynchronousMetrics.cpp +++ b/src/Interpreters/AsynchronousMetrics.cpp @@ -1222,9 +1222,9 @@ void AsynchronousMetrics::update(std::chrono::system_clock::time_point update_ti { auto stat = getStatVFS(getContext()->getPath()); - new_values["FilesystemMainPathTotalBytes"] = stat.f_blocks * stat.f_bsize; - new_values["FilesystemMainPathAvailableBytes"] = stat.f_bavail * stat.f_bsize; - new_values["FilesystemMainPathUsedBytes"] = (stat.f_blocks - stat.f_bavail) * stat.f_bsize; + new_values["FilesystemMainPathTotalBytes"] = stat.f_blocks * stat.f_frsize; + new_values["FilesystemMainPathAvailableBytes"] = stat.f_bavail * stat.f_frsize; + new_values["FilesystemMainPathUsedBytes"] = (stat.f_blocks - stat.f_bavail) * stat.f_frsize; new_values["FilesystemMainPathTotalINodes"] = stat.f_files; new_values["FilesystemMainPathAvailableINodes"] = stat.f_favail; new_values["FilesystemMainPathUsedINodes"] = stat.f_files - stat.f_favail; @@ -1234,9 +1234,9 @@ void AsynchronousMetrics::update(std::chrono::system_clock::time_point update_ti /// Current working directory of the server is the directory with logs. auto stat = getStatVFS("."); - new_values["FilesystemLogsPathTotalBytes"] = stat.f_blocks * stat.f_bsize; - new_values["FilesystemLogsPathAvailableBytes"] = stat.f_bavail * stat.f_bsize; - new_values["FilesystemLogsPathUsedBytes"] = (stat.f_blocks - stat.f_bavail) * stat.f_bsize; + new_values["FilesystemLogsPathTotalBytes"] = stat.f_blocks * stat.f_frsize; + new_values["FilesystemLogsPathAvailableBytes"] = stat.f_bavail * stat.f_frsize; + new_values["FilesystemLogsPathUsedBytes"] = (stat.f_blocks - stat.f_bavail) * stat.f_frsize; new_values["FilesystemLogsPathTotalINodes"] = stat.f_files; new_values["FilesystemLogsPathAvailableINodes"] = stat.f_favail; new_values["FilesystemLogsPathUsedINodes"] = stat.f_files - stat.f_favail;