2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/MergeList.h>
|
2019-01-13 22:02:33 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataMergerMutator.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/CurrentMetrics.h>
|
2020-02-02 02:35:47 +00:00
|
|
|
#include <common/getThreadId.h>
|
2018-06-01 15:32:27 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
2018-02-01 17:55:08 +00:00
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-06-06 12:24:49 +00:00
|
|
|
MergeListElement::MergeListElement(const StorageID & table_id_, const FutureMergedMutatedPart & future_part)
|
|
|
|
: table_id{table_id_}
|
2020-09-03 13:00:13 +00:00
|
|
|
, partition_id{future_part.part_info.partition_id}
|
2019-01-14 12:25:25 +00:00
|
|
|
, result_part_name{future_part.name}
|
2019-11-24 05:47:39 +00:00
|
|
|
, result_part_path{future_part.path}
|
2019-01-14 12:25:25 +00:00
|
|
|
, result_data_version{future_part.part_info.getDataVersion()}
|
|
|
|
, num_parts{future_part.parts.size()}
|
2020-02-02 02:35:47 +00:00
|
|
|
, thread_id{getThreadId()}
|
2020-09-03 13:00:13 +00:00
|
|
|
, merge_type{future_part.merge_type}
|
2020-09-10 14:56:15 +00:00
|
|
|
, merge_algorithm{MergeAlgorithm::Undecided}
|
2016-12-23 20:23:46 +00:00
|
|
|
{
|
2019-01-13 22:02:33 +00:00
|
|
|
for (const auto & source_part : future_part.parts)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
source_part_names.emplace_back(source_part->name);
|
2019-11-20 08:51:52 +00:00
|
|
|
source_part_paths.emplace_back(source_part->getFullPath());
|
2018-09-13 03:34:58 +00:00
|
|
|
|
2020-03-23 13:32:02 +00:00
|
|
|
total_size_bytes_compressed += source_part->getBytesOnDisk();
|
2019-03-25 13:55:24 +00:00
|
|
|
total_size_marks += source_part->getMarksCount();
|
2019-03-26 12:37:42 +00:00
|
|
|
total_rows_count += source_part->index_granularity.getTotalRows();
|
2019-01-13 22:02:33 +00:00
|
|
|
}
|
2019-01-11 19:14:50 +00:00
|
|
|
|
2019-01-13 22:02:33 +00:00
|
|
|
if (!future_part.parts.empty())
|
2019-01-11 19:14:50 +00:00
|
|
|
{
|
2019-01-14 12:25:25 +00:00
|
|
|
source_data_version = future_part.parts[0]->info.getDataVersion();
|
|
|
|
is_mutation = (result_data_version != source_data_version);
|
2019-01-11 19:14:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Each merge is executed into separate background processing pool thread
|
2019-03-14 18:03:35 +00:00
|
|
|
background_thread_memory_tracker = CurrentThread::getMemoryTracker();
|
2018-02-01 17:55:08 +00:00
|
|
|
if (background_thread_memory_tracker)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2021-01-05 23:20:26 +00:00
|
|
|
/// From the query context it will be ("for thread") memory tracker with VariableContext::Thread level,
|
|
|
|
/// which does not have any limits and sampling settings configured.
|
|
|
|
/// And parent for this memory tracker should be ("(for query)") with VariableContext::Process level,
|
|
|
|
/// that has limits and sampling configured.
|
|
|
|
MemoryTracker * parent;
|
|
|
|
if (background_thread_memory_tracker->level == VariableContext::Thread &&
|
|
|
|
(parent = background_thread_memory_tracker->getParent()) &&
|
|
|
|
parent != &total_memory_tracker)
|
|
|
|
{
|
|
|
|
background_thread_memory_tracker = parent;
|
|
|
|
}
|
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
background_thread_memory_tracker_prev_parent = background_thread_memory_tracker->getParent();
|
|
|
|
background_thread_memory_tracker->setParent(&memory_tracker);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-23 20:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeInfo MergeListElement::getInfo() const
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeInfo res;
|
2021-06-06 12:24:49 +00:00
|
|
|
res.database = table_id.getDatabaseName();
|
|
|
|
res.table = table_id.getTableName();
|
2017-04-01 07:20:54 +00:00
|
|
|
res.result_part_name = result_part_name;
|
2019-11-20 08:51:52 +00:00
|
|
|
res.result_part_path = result_part_path;
|
2018-09-11 11:16:40 +00:00
|
|
|
res.partition_id = partition_id;
|
2019-01-13 22:02:33 +00:00
|
|
|
res.is_mutation = is_mutation;
|
2017-04-01 07:20:54 +00:00
|
|
|
res.elapsed = watch.elapsedSeconds();
|
2018-03-03 18:00:46 +00:00
|
|
|
res.progress = progress.load(std::memory_order_relaxed);
|
2017-04-01 07:20:54 +00:00
|
|
|
res.num_parts = num_parts;
|
|
|
|
res.total_size_bytes_compressed = total_size_bytes_compressed;
|
|
|
|
res.total_size_marks = total_size_marks;
|
2019-03-26 12:37:42 +00:00
|
|
|
res.total_rows_count = total_rows_count;
|
2017-04-01 07:20:54 +00:00
|
|
|
res.bytes_read_uncompressed = bytes_read_uncompressed.load(std::memory_order_relaxed);
|
|
|
|
res.bytes_written_uncompressed = bytes_written_uncompressed.load(std::memory_order_relaxed);
|
|
|
|
res.rows_read = rows_read.load(std::memory_order_relaxed);
|
|
|
|
res.rows_written = rows_written.load(std::memory_order_relaxed);
|
|
|
|
res.columns_written = columns_written.load(std::memory_order_relaxed);
|
|
|
|
res.memory_usage = memory_tracker.get();
|
2020-02-02 02:27:15 +00:00
|
|
|
res.thread_id = thread_id;
|
2020-09-03 13:00:13 +00:00
|
|
|
res.merge_type = toString(merge_type);
|
2020-10-27 15:27:12 +00:00
|
|
|
res.merge_algorithm = toString(merge_algorithm.load(std::memory_order_relaxed));
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
for (const auto & source_part_name : source_part_names)
|
|
|
|
res.source_part_names.emplace_back(source_part_name);
|
|
|
|
|
2019-11-20 08:51:52 +00:00
|
|
|
for (const auto & source_part_path : source_part_paths)
|
|
|
|
res.source_part_paths.emplace_back(source_part_path);
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2016-12-23 20:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeListElement::~MergeListElement()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Unplug memory_tracker from current background processing pool thread
|
2018-02-01 17:55:08 +00:00
|
|
|
if (background_thread_memory_tracker)
|
|
|
|
background_thread_memory_tracker->setParent(background_thread_memory_tracker_prev_parent);
|
2016-12-23 20:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|