2014-09-10 11:34:26 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-10-05 00:44:40 +00:00
|
|
|
#include <DB/Common/Stopwatch.h>
|
2016-01-21 01:47:28 +00:00
|
|
|
#include <DB/Common/CurrentMetrics.h>
|
2016-12-23 20:23:46 +00:00
|
|
|
#include <DB/Common/MemoryTracker.h>
|
|
|
|
#include <DB/Interpreters/Context.h>
|
2017-01-16 16:13:52 +00:00
|
|
|
#include <DB/Storages/MergeTree/MergeTreeData.h>
|
2015-02-10 21:10:58 +00:00
|
|
|
#include <memory>
|
2014-09-10 11:34:26 +00:00
|
|
|
#include <list>
|
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2016-10-27 22:50:02 +00:00
|
|
|
/** Maintains a list of currently running merges.
|
|
|
|
* For implementation of system.merges table.
|
|
|
|
*/
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
|
|
|
extern const Metric Merge;
|
|
|
|
}
|
|
|
|
|
2014-09-10 11:34:26 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
struct MergeInfo
|
2016-12-23 20:23:46 +00:00
|
|
|
{
|
|
|
|
std::string database;
|
|
|
|
std::string table;
|
|
|
|
std::string result_part_name;
|
2017-01-16 16:13:52 +00:00
|
|
|
Array source_part_names;
|
2016-12-23 20:23:46 +00:00
|
|
|
Float64 elapsed;
|
|
|
|
Float64 progress;
|
|
|
|
UInt64 num_parts;
|
|
|
|
UInt64 total_size_bytes_compressed;
|
|
|
|
UInt64 total_size_marks;
|
|
|
|
UInt64 bytes_read_uncompressed;
|
|
|
|
UInt64 bytes_written_uncompressed;
|
|
|
|
UInt64 rows_read;
|
|
|
|
UInt64 rows_written;
|
|
|
|
UInt64 columns_written;
|
|
|
|
UInt64 memory_usage;
|
|
|
|
UInt64 thread_number;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct MergeListElement : boost::noncopyable
|
2014-09-10 11:34:26 +00:00
|
|
|
{
|
2015-04-16 06:12:35 +00:00
|
|
|
const std::string database;
|
|
|
|
const std::string table;
|
|
|
|
const std::string result_part_name;
|
|
|
|
Stopwatch watch;
|
|
|
|
Float64 progress{};
|
2016-10-26 22:27:38 +00:00
|
|
|
UInt64 num_parts{};
|
2017-01-16 16:13:52 +00:00
|
|
|
Names source_part_names;
|
2016-10-26 22:27:38 +00:00
|
|
|
UInt64 total_size_bytes_compressed{};
|
|
|
|
UInt64 total_size_marks{};
|
|
|
|
std::atomic<UInt64> bytes_read_uncompressed{};
|
2016-11-24 19:08:54 +00:00
|
|
|
std::atomic<UInt64> bytes_written_uncompressed{};
|
2016-11-03 12:00:44 +00:00
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
/// In case of Vertical algorithm they are actual only for primary key columns
|
2016-11-03 12:00:44 +00:00
|
|
|
std::atomic<UInt64> rows_read{};
|
2016-10-26 22:27:38 +00:00
|
|
|
std::atomic<UInt64> rows_written{};
|
2016-11-22 19:34:36 +00:00
|
|
|
|
2016-11-03 12:00:44 +00:00
|
|
|
/// Updated only for Vertical algorithm
|
|
|
|
std::atomic<UInt64> columns_written{};
|
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
MemoryTracker memory_tracker;
|
|
|
|
MemoryTracker * background_pool_task_memory_tracker;
|
2016-07-31 03:53:16 +00:00
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
/// Poco thread number used in logs
|
|
|
|
UInt32 thread_number;
|
|
|
|
|
|
|
|
|
2017-01-16 16:13:52 +00:00
|
|
|
MergeListElement(const std::string & database, const std::string & table, const std::string & result_part_name,
|
|
|
|
const MergeTreeData::DataPartsVector & source_parts);
|
2016-12-23 20:23:46 +00:00
|
|
|
|
|
|
|
MergeInfo getInfo() const;
|
|
|
|
|
|
|
|
~MergeListElement();
|
2015-04-16 06:12:35 +00:00
|
|
|
};
|
2014-09-10 11:34:26 +00:00
|
|
|
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
class MergeList;
|
|
|
|
|
|
|
|
class MergeListEntry
|
|
|
|
{
|
|
|
|
MergeList & list;
|
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
using container_t = std::list<MergeListElement>;
|
2015-04-16 06:12:35 +00:00
|
|
|
container_t::iterator it;
|
2014-09-10 11:34:26 +00:00
|
|
|
|
2016-01-21 01:47:28 +00:00
|
|
|
CurrentMetrics::Increment num_merges {CurrentMetrics::Merge};
|
|
|
|
|
2014-09-10 11:34:26 +00:00
|
|
|
public:
|
2015-04-16 06:12:35 +00:00
|
|
|
MergeListEntry(const MergeListEntry &) = delete;
|
|
|
|
MergeListEntry & operator=(const MergeListEntry &) = delete;
|
|
|
|
|
|
|
|
MergeListEntry(MergeList & list, const container_t::iterator it) : list(list), it{it} {}
|
|
|
|
~MergeListEntry();
|
2014-09-10 11:34:26 +00:00
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
MergeListElement * operator->() { return &*it; }
|
2015-04-16 06:12:35 +00:00
|
|
|
};
|
2014-09-10 11:34:26 +00:00
|
|
|
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
class MergeList
|
|
|
|
{
|
|
|
|
friend class MergeListEntry;
|
2014-09-10 11:34:26 +00:00
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
using container_t = std::list<MergeListElement>;
|
|
|
|
using info_container_t = std::list<MergeInfo>;
|
2015-04-16 06:12:35 +00:00
|
|
|
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
container_t merges;
|
|
|
|
|
|
|
|
public:
|
|
|
|
using Entry = MergeListEntry;
|
2014-09-10 11:34:26 +00:00
|
|
|
using EntryPtr = std::unique_ptr<Entry>;
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
EntryPtr insert(Args &&... args)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock{mutex};
|
2015-02-10 21:10:58 +00:00
|
|
|
return std::make_unique<Entry>(*this, merges.emplace(merges.end(), std::forward<Args>(args)...));
|
2014-09-10 11:34:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 20:23:46 +00:00
|
|
|
info_container_t get() const
|
2014-09-10 11:34:26 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock{mutex};
|
2016-12-23 20:23:46 +00:00
|
|
|
info_container_t res;
|
|
|
|
for (const auto & merge_element : merges)
|
|
|
|
res.emplace_back(merge_element.getInfo());
|
|
|
|
return res;
|
2014-09-10 11:34:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
inline MergeListEntry::~MergeListEntry()
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock{list.mutex};
|
|
|
|
list.merges.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 11:34:26 +00:00
|
|
|
}
|