2019-06-19 10:07:56 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndexGranularityInfo.h>
|
2019-06-19 14:46:06 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2019-06-19 10:07:56 +00:00
|
|
|
#include <Poco/Path.h>
|
|
|
|
#include <Poco/File.h>
|
|
|
|
#include <Poco/DirectoryIterator.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-10-11 15:37:16 +00:00
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 10:07:56 +00:00
|
|
|
std::optional<std::string> MergeTreeIndexGranularityInfo::getMrkExtensionFromFS(const std::string & path_to_part) const
|
|
|
|
{
|
|
|
|
if (Poco::File(path_to_part).exists())
|
|
|
|
{
|
|
|
|
Poco::DirectoryIterator end;
|
|
|
|
for (Poco::DirectoryIterator part_it(path_to_part); part_it != end; ++part_it)
|
|
|
|
{
|
|
|
|
const auto & ext = "." + part_it.path().getExtension();
|
|
|
|
if (ext == getNonAdaptiveMrkExtension() || ext == getAdaptiveMrkExtension())
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:27:53 +00:00
|
|
|
MergeTreeIndexGranularityInfo::MergeTreeIndexGranularityInfo(const MergeTreeData & storage,
|
|
|
|
const String & marks_file_extension_, UInt8 mark_size_in_bytes_)
|
|
|
|
: marks_file_extension(marks_file_extension_), mark_size_in_bytes(mark_size_in_bytes_)
|
2019-06-19 10:07:56 +00:00
|
|
|
{
|
2019-10-16 18:27:53 +00:00
|
|
|
const auto storage_settings = storage.getSettings();
|
2019-08-13 10:29:31 +00:00
|
|
|
fixed_index_granularity = storage_settings->index_granularity;
|
2019-06-19 10:07:56 +00:00
|
|
|
/// Granularity is fixed
|
2019-10-16 18:27:53 +00:00
|
|
|
if (!storage.canUseAdaptiveGranularity())
|
2019-06-19 10:07:56 +00:00
|
|
|
setNonAdaptive();
|
|
|
|
else
|
2019-08-13 10:29:31 +00:00
|
|
|
setAdaptive(storage_settings->index_granularity_bytes);
|
2019-06-19 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-16 18:27:53 +00:00
|
|
|
void MergeTreeIndexGranularityInfo::changeGranularityIfRequired(const String & path)
|
2019-06-19 10:07:56 +00:00
|
|
|
{
|
2019-10-16 18:27:53 +00:00
|
|
|
auto mrk_ext = getMrkExtensionFromFS(path);
|
2019-10-11 15:37:16 +00:00
|
|
|
if (mrk_ext && *mrk_ext == ".mrk") /// TODO
|
2019-06-19 10:07:56 +00:00
|
|
|
setNonAdaptive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeIndexGranularityInfo::setAdaptive(size_t index_granularity_bytes_)
|
|
|
|
{
|
2019-06-19 11:59:08 +00:00
|
|
|
is_adaptive = true;
|
2019-06-19 10:07:56 +00:00
|
|
|
index_granularity_bytes = index_granularity_bytes_;
|
2019-10-11 15:37:16 +00:00
|
|
|
|
2019-06-19 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeIndexGranularityInfo::setNonAdaptive()
|
|
|
|
{
|
2019-06-19 11:59:08 +00:00
|
|
|
is_adaptive = false;
|
2019-06-19 10:07:56 +00:00
|
|
|
index_granularity_bytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|