ClickHouse/dbms/include/DB/Storages/MergeTree/MergeList.h

82 lines
1.6 KiB
C
Raw Normal View History

2014-09-10 11:34:26 +00:00
#pragma once
#include <statdaemons/Stopwatch.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>
namespace DB
{
class MergeList
{
friend class Entry;
struct MergeInfo
{
const std::string database;
const std::string table;
const std::string result_part_name;
Stopwatch watch;
Float64 progress{};
2014-09-10 11:34:26 +00:00
std::uint64_t num_parts{};
2014-09-12 16:05:29 +00:00
std::uint64_t total_size_bytes_compressed{};
2014-09-10 11:34:26 +00:00
std::uint64_t total_size_marks{};
2014-09-12 16:05:29 +00:00
std::uint64_t bytes_read_uncompressed{};
2014-09-10 11:34:26 +00:00
std::uint64_t rows_read{};
2014-09-12 16:05:29 +00:00
std::uint64_t bytes_written_uncompressed{};
2014-09-10 11:34:26 +00:00
std::uint64_t rows_written{};
2014-09-10 11:34:26 +00:00
MergeInfo(const std::string & database, const std::string & table, const std::string & result_part_name)
: database{database}, table{table}, result_part_name{result_part_name}
{
}
};
using container_t = std::list<MergeInfo>;
mutable std::mutex mutex;
container_t merges;
public:
class Entry
{
MergeList & list;
container_t::iterator it;
public:
Entry(const Entry &) = delete;
Entry & operator=(const Entry &) = delete;
Entry(MergeList & list, const container_t::iterator it) : list(list), it{it} {}
~Entry()
{
std::lock_guard<std::mutex> lock{list.mutex};
list.merges.erase(it);
}
MergeInfo * operator->() { return &*it; }
};
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
}
container_t get() const
{
std::lock_guard<std::mutex> lock{mutex};
return merges;
}
};
}