Skip to content

Commit 9d5c05f

Browse files
Merge pull request ClickHouse#79348 from ClickHouse/filesystem-cache-capacity
Add async metric about filesystem cache capacity
2 parents 70fa556 + 24b25bb commit 9d5c05f

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/Interpreters/Cache/FileCache.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,11 @@ size_t FileCache::getUsedCacheSize() const
16131613
return main_priority->getSizeApprox();
16141614
}
16151615

1616+
size_t FileCache::getMaxCacheSize() const
1617+
{
1618+
return main_priority->getSizeLimitApprox();
1619+
}
1620+
16161621
size_t FileCache::getFileSegmentsNum() const
16171622
{
16181623
/// We use this method for metrics, so it is ok to get approximate result.

src/Interpreters/Cache/FileCache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class FileCache : private boost::noncopyable
157157
std::vector<String> tryGetCachePaths(const Key & key);
158158

159159
size_t getUsedCacheSize() const;
160+
size_t getMaxCacheSize() const;
160161

161162
size_t getFileSegmentsNum() const;
162163

src/Interpreters/Cache/IFileCachePriority.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class IFileCachePriority : private boost::noncopyable
9797
size_t getElementsLimit(const CachePriorityGuard::Lock &) const { return max_elements; }
9898

9999
size_t getSizeLimit(const CachePriorityGuard::Lock &) const { return max_size; }
100+
size_t getSizeLimitApprox() const { return max_size.load(std::memory_order_relaxed); }
100101

101102
virtual size_t getSize(const CachePriorityGuard::Lock &) const = 0;
102103

src/Interpreters/ServerAsynchronousMetrics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,20 @@ void ServerAsynchronousMetrics::updateImpl(TimePoint update_time, TimePoint curr
144144
{
145145
auto caches = FileCacheFactory::instance().getAll();
146146
size_t total_bytes = 0;
147+
size_t max_bytes = 0;
147148
size_t total_files = 0;
148149

149150
for (const auto & [_, cache_data] : caches)
150151
{
151152
total_bytes += cache_data->cache->getUsedCacheSize();
153+
max_bytes += cache_data->cache->getMaxCacheSize();
152154
total_files += cache_data->cache->getFileSegmentsNum();
153155
}
154156

155157
new_values["FilesystemCacheBytes"] = { total_bytes,
156158
"Total bytes in the `cache` virtual filesystem. This cache is hold on disk." };
159+
new_values["FilesystemCacheCapacity"] = { max_bytes,
160+
"Total capacity in the `cache` virtual filesystem. This cache is hold on disk." };
157161
new_values["FilesystemCacheFiles"] = { total_files,
158162
"Total number of cached file segments in the `cache` virtual filesystem. This cache is hold on disk." };
159163
}

0 commit comments

Comments
 (0)