#include "StorageSystemFilesystemCache.h" #include #include #include #include #include #include #include #include namespace DB { NamesAndTypesList StorageSystemFilesystemCache::getNamesAndTypes() { return { {"cache_base_path", std::make_shared()}, {"cache_path", std::make_shared()}, {"file_segment_range_begin", std::make_shared()}, {"file_segment_range_end", std::make_shared()}, {"size", std::make_shared()}, {"state", std::make_shared()}, {"cache_hits", std::make_shared()}, {"references", std::make_shared()}, {"downloaded_size", std::make_shared()}, {"persistent", std::make_shared>()}, {"kind", std::make_shared()}, }; } StorageSystemFilesystemCache::StorageSystemFilesystemCache(const StorageID & table_id_) : IStorageSystemOneBlock(table_id_) { } void StorageSystemFilesystemCache::fillData(MutableColumns & res_columns, ContextPtr, const SelectQueryInfo &) const { auto caches = FileCacheFactory::instance().getAll(); for (const auto & [cache_base_path, cache_data] : caches) { const auto & cache = cache_data->cache; auto file_segments = cache->getSnapshot(); for (const auto & file_segment : *file_segments) { res_columns[0]->insert(cache_base_path); /// Do not use `file_segment->getPathInLocalCache` here because it will lead to nullptr dereference /// (because file_segments in getSnapshot doesn't have `cache` field set) res_columns[1]->insert( cache->getPathInLocalCache(file_segment->key(), file_segment->offset(), file_segment->getKind())); const auto & range = file_segment->range(); res_columns[2]->insert(range.left); res_columns[3]->insert(range.right); res_columns[4]->insert(range.size()); res_columns[5]->insert(FileSegment::stateToString(file_segment->state())); res_columns[6]->insert(file_segment->getHitsCount()); res_columns[7]->insert(file_segment->getRefCount()); res_columns[8]->insert(file_segment->getDownloadedSize()); res_columns[9]->insert(file_segment->isPersistent()); res_columns[10]->insert(toString(file_segment->getKind())); } } } }