2022-06-21 13:42:36 +00:00
|
|
|
#include <Interpreters/InterpreterDescribeCacheQuery.h>
|
2022-06-23 15:46:27 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2022-06-21 13:42:36 +00:00
|
|
|
#include <Processors/Sources/SourceFromSingleChunk.h>
|
|
|
|
#include <Parsers/ASTDescribeCacheQuery.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <Storages/ColumnsDescription.h>
|
2022-08-26 17:23:46 +00:00
|
|
|
#include <Interpreters/Cache/FileCacheFactory.h>
|
|
|
|
#include <Interpreters/Cache/FileCache.h>
|
2022-06-23 15:46:27 +00:00
|
|
|
#include <Access/Common/AccessFlags.h>
|
2022-06-21 13:42:36 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
static Block getSampleBlock()
|
|
|
|
{
|
|
|
|
ColumnsWithTypeAndName columns{
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeUInt64>(), "max_size"},
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeUInt64>(), "max_elements"},
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeUInt64>(), "max_file_segment_size"},
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeNumber<UInt8>>(), "cache_on_write_operations"},
|
2023-01-18 19:52:16 +00:00
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeNumber<UInt8>>(), "cache_hits_threshold"},
|
2022-06-21 13:42:36 +00:00
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeUInt64>(), "current_size"},
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeUInt64>(), "current_elements"},
|
2022-08-10 13:55:09 +00:00
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "path"},
|
|
|
|
ColumnWithTypeAndName{std::make_shared<DataTypeNumber<UInt8>>(), "do_not_evict_index_and_mark_files"},
|
2022-06-21 13:42:36 +00:00
|
|
|
};
|
|
|
|
return Block(columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockIO InterpreterDescribeCacheQuery::execute()
|
|
|
|
{
|
2022-09-19 12:02:51 +00:00
|
|
|
getContext()->checkAccess(AccessType::SHOW_FILESYSTEM_CACHES);
|
2022-06-21 13:42:36 +00:00
|
|
|
|
|
|
|
const auto & ast = query_ptr->as<ASTDescribeCacheQuery &>();
|
|
|
|
Block sample_block = getSampleBlock();
|
|
|
|
MutableColumns res_columns = sample_block.cloneEmptyColumns();
|
|
|
|
|
|
|
|
auto cache_data = FileCacheFactory::instance().getByName(ast.cache_name);
|
|
|
|
const auto & settings = cache_data.settings;
|
|
|
|
const auto & cache = cache_data.cache;
|
|
|
|
|
|
|
|
res_columns[0]->insert(settings.max_size);
|
|
|
|
res_columns[1]->insert(settings.max_elements);
|
|
|
|
res_columns[2]->insert(settings.max_file_segment_size);
|
|
|
|
res_columns[3]->insert(settings.cache_on_write_operations);
|
2023-01-18 19:52:16 +00:00
|
|
|
res_columns[4]->insert(settings.cache_hits_threshold);
|
2022-06-21 13:42:36 +00:00
|
|
|
res_columns[5]->insert(cache->getUsedCacheSize());
|
|
|
|
res_columns[6]->insert(cache->getFileSegmentsNum());
|
|
|
|
res_columns[7]->insert(cache->getBasePath());
|
2022-08-10 13:55:09 +00:00
|
|
|
res_columns[8]->insert(settings.do_not_evict_index_and_mark_files);
|
2022-06-21 13:42:36 +00:00
|
|
|
|
|
|
|
BlockIO res;
|
|
|
|
size_t num_rows = res_columns[0]->size();
|
|
|
|
auto source = std::make_shared<SourceFromSingleChunk>(sample_block, Chunk(std::move(res_columns), num_rows));
|
|
|
|
res.pipeline = QueryPipeline(std::move(source));
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|