2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/MergeList.h>
|
|
|
|
#include <Common/CurrentMetrics.h>
|
2016-12-23 20:23:46 +00:00
|
|
|
#include <Poco/Ext/ThreadNumber.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
|
|
|
|
2016-12-30 16:22:37 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const Metric MemoryTrackingForMerges;
|
2016-12-30 16:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-16 16:13:52 +00:00
|
|
|
MergeListElement::MergeListElement(const std::string & database, const std::string & table, const std::string & result_part_name,
|
2017-04-01 07:20:54 +00:00
|
|
|
const MergeTreeData::DataPartsVector & source_parts)
|
|
|
|
: database{database}, table{table}, result_part_name{result_part_name}, num_parts{source_parts.size()},
|
|
|
|
thread_number{Poco::ThreadNumber::get()}
|
2016-12-23 20:23:46 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
for (const auto & source_part : source_parts)
|
|
|
|
source_part_names.emplace_back(source_part->name);
|
2018-09-13 03:34:58 +00:00
|
|
|
|
2018-09-11 11:16:40 +00:00
|
|
|
if (!source_parts.empty())
|
|
|
|
partition_id = source_parts[0]->info.partition_id;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-11 19:14:50 +00:00
|
|
|
num_parts = source_parts.size();
|
|
|
|
|
|
|
|
for (const MergeTreeData::DataPartPtr & part : source_parts)
|
|
|
|
{
|
|
|
|
std::shared_lock<std::shared_mutex> part_lock(part->columns_lock);
|
|
|
|
|
|
|
|
total_size_bytes_compressed += part->bytes_on_disk;
|
|
|
|
total_size_marks += part->marks_count;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Each merge is executed into separate background processing pool thread
|
2018-06-01 15:32:27 +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
|
|
|
{
|
|
|
|
memory_tracker.setMetric(CurrentMetrics::MemoryTrackingForMerges);
|
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;
|
|
|
|
res.database = database;
|
|
|
|
res.table = table;
|
|
|
|
res.result_part_name = result_part_name;
|
2018-09-11 11:16:40 +00:00
|
|
|
res.partition_id = partition_id;
|
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;
|
|
|
|
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();
|
|
|
|
res.thread_number = thread_number;
|
|
|
|
|
|
|
|
for (const auto & source_part_name : source_part_names)
|
|
|
|
res.source_part_names.emplace_back(source_part_name);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|