2022-03-30 09:54:42 +00:00
|
|
|
#include "StorageSystemFilesystemCache.h"
|
2022-03-21 11:30:25 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeTuple.h>
|
2022-08-26 17:23:46 +00:00
|
|
|
#include <Interpreters/Cache/FileCache.h>
|
|
|
|
#include <Interpreters/Cache/FileSegment.h>
|
|
|
|
#include <Interpreters/Cache/FileCacheFactory.h>
|
2022-03-21 11:30:25 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Disks/IDisk.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-03-30 09:54:42 +00:00
|
|
|
NamesAndTypesList StorageSystemFilesystemCache::getNamesAndTypes()
|
2022-03-21 11:30:25 +00:00
|
|
|
{
|
|
|
|
return {
|
|
|
|
{"cache_base_path", std::make_shared<DataTypeString>()},
|
|
|
|
{"cache_path", std::make_shared<DataTypeString>()},
|
2022-03-24 14:32:08 +00:00
|
|
|
{"file_segment_range_begin", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"file_segment_range_end", std::make_shared<DataTypeUInt64>()},
|
2022-03-21 11:30:25 +00:00
|
|
|
{"size", std::make_shared<DataTypeUInt64>()},
|
2022-03-23 14:35:15 +00:00
|
|
|
{"state", std::make_shared<DataTypeString>()},
|
|
|
|
{"cache_hits", std::make_shared<DataTypeUInt64>()},
|
2022-03-24 14:32:08 +00:00
|
|
|
{"references", std::make_shared<DataTypeUInt64>()},
|
2022-04-07 16:46:46 +00:00
|
|
|
{"downloaded_size", std::make_shared<DataTypeUInt64>()},
|
2022-12-06 10:04:15 +00:00
|
|
|
{"persistent", std::make_shared<DataTypeNumber<UInt8>>()},
|
|
|
|
{"kind", std::make_shared<DataTypeString>()},
|
2022-03-21 11:30:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-30 09:54:42 +00:00
|
|
|
StorageSystemFilesystemCache::StorageSystemFilesystemCache(const StorageID & table_id_)
|
2022-03-21 11:30:25 +00:00
|
|
|
: IStorageSystemOneBlock(table_id_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-30 09:54:42 +00:00
|
|
|
void StorageSystemFilesystemCache::fillData(MutableColumns & res_columns, ContextPtr, const SelectQueryInfo &) const
|
2022-03-21 11:30:25 +00:00
|
|
|
{
|
|
|
|
auto caches = FileCacheFactory::instance().getAll();
|
|
|
|
|
2022-03-21 13:56:38 +00:00
|
|
|
for (const auto & [cache_base_path, cache_data] : caches)
|
2022-03-21 11:30:25 +00:00
|
|
|
{
|
2022-06-23 15:46:27 +00:00
|
|
|
const auto & cache = cache_data->cache;
|
2022-04-07 16:46:46 +00:00
|
|
|
auto file_segments = cache->getSnapshot();
|
2022-03-21 13:56:38 +00:00
|
|
|
|
2022-04-07 16:46:46 +00:00
|
|
|
for (const auto & file_segment : file_segments)
|
2022-03-21 11:30:25 +00:00
|
|
|
{
|
|
|
|
res_columns[0]->insert(cache_base_path);
|
2022-12-06 10:04:15 +00:00
|
|
|
|
|
|
|
/// 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)
|
2022-11-30 12:58:52 +00:00
|
|
|
res_columns[1]->insert(
|
2022-12-06 10:04:15 +00:00
|
|
|
cache->getPathInLocalCache(file_segment->key(), file_segment->offset(), file_segment->getKind()));
|
2022-03-21 11:30:25 +00:00
|
|
|
|
|
|
|
const auto & range = file_segment->range();
|
2022-03-24 14:32:08 +00:00
|
|
|
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()));
|
2022-04-07 16:46:46 +00:00
|
|
|
res_columns[6]->insert(file_segment->getHitsCount());
|
|
|
|
res_columns[7]->insert(file_segment->getRefCount());
|
|
|
|
res_columns[8]->insert(file_segment->getDownloadedSize());
|
2022-04-12 13:43:57 +00:00
|
|
|
res_columns[9]->insert(file_segment->isPersistent());
|
2022-12-06 10:04:15 +00:00
|
|
|
res_columns[10]->insert(toString(file_segment->getKind()));
|
2022-03-21 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|