From 29d2928f93e20bd1bd611801171f59f25386941d Mon Sep 17 00:00:00 2001 From: Maxim Akhmedov Date: Thu, 25 Jun 2020 00:27:53 +0300 Subject: [PATCH] Consider allocatedBytes() instead of bytes() in Storage{Buffer,Memory}. --- src/Storages/IStorage.h | 6 +++++- src/Storages/StorageBuffer.cpp | 2 +- src/Storages/StorageMemory.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 3cf26d218cd..5b49e1cfd4c 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -449,7 +449,7 @@ public: } /// If it is possible to quickly determine exact number of bytes for the table on storage: - /// - memory (approximated) + /// - memory (approximated, resident) /// - disk (compressed) /// /// Used for: @@ -457,6 +457,10 @@ public: // /// Does not takes underlying Storage (if any) into account /// (since for Buffer we still need to know how much bytes it uses). + /// + /// Memory part should be estimated as a resident memory size. + /// In particular, alloctedBytes() is preferable over bytes() + /// when considering in-memory blocks. virtual std::optional totalBytes() const { return {}; diff --git a/src/Storages/StorageBuffer.cpp b/src/Storages/StorageBuffer.cpp index e0bd19feba9..85b61dd34f9 100644 --- a/src/Storages/StorageBuffer.cpp +++ b/src/Storages/StorageBuffer.cpp @@ -797,7 +797,7 @@ std::optional StorageBuffer::totalBytes() const for (const auto & buffer : buffers) { std::lock_guard lock(buffer.mutex); - bytes += buffer.data.bytes(); + bytes += buffer.data.allocatedBytes(); } return bytes; } diff --git a/src/Storages/StorageMemory.cpp b/src/Storages/StorageMemory.cpp index 44413caaa57..3a10b2c7e7d 100644 --- a/src/Storages/StorageMemory.cpp +++ b/src/Storages/StorageMemory.cpp @@ -169,7 +169,7 @@ std::optional StorageMemory::totalBytes() const UInt64 bytes = 0; std::lock_guard lock(mutex); for (const auto & buffer : data) - bytes += buffer.bytes(); + bytes += buffer.allocatedBytes(); return bytes; }