2013-02-08 17:06:29 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2015-10-05 01:11:12 +00:00
|
|
|
|
#include <DB/Common/OptimizedRegularExpression.h>
|
2013-02-08 17:06:29 +00:00
|
|
|
|
|
|
|
|
|
#include <DB/Interpreters/Context.h>
|
|
|
|
|
#include <DB/Storages/IStorage.h>
|
2015-04-16 06:12:35 +00:00
|
|
|
|
#include <DB/Storages/MergeTree/BackgroundProcessingPool.h>
|
2013-02-08 17:06:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2013-05-15 12:32:40 +00:00
|
|
|
|
/** То и дело объединяет таблицы, подходящие под регэксп, в таблицы типа Chunks.
|
2013-02-08 17:06:29 +00:00
|
|
|
|
* После объндинения заменяет исходные таблицы таблицами типа ChunkRef.
|
|
|
|
|
* При чтении ведет себя как таблица типа Merge.
|
|
|
|
|
*/
|
|
|
|
|
class StorageChunkMerger : public IStorage
|
|
|
|
|
{
|
2014-02-11 18:38:21 +00:00
|
|
|
|
typedef std::vector<StoragePtr> Storages;
|
2013-02-08 17:06:29 +00:00
|
|
|
|
public:
|
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const std::string & this_database_,/// Имя БД для этой таблицы.
|
|
|
|
|
const std::string & name_, /// Имя таблицы.
|
|
|
|
|
NamesAndTypesListPtr columns_, /// Список столбцов.
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
2013-02-08 17:06:29 +00:00
|
|
|
|
const String & source_database_, /// В какой БД искать таблицы-источники.
|
|
|
|
|
const String & table_name_regexp_, /// Регексп имён таблиц-источников.
|
|
|
|
|
const std::string & destination_name_prefix_, /// Префикс имен создаваемых таблиц типа Chunks.
|
|
|
|
|
size_t chunks_to_merge_, /// Сколько чанков сливать в одну группу.
|
2013-05-05 18:02:05 +00:00
|
|
|
|
Context & context_); /// Известные таблицы.
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
std::string getName() const override { return "ChunkMerger"; }
|
|
|
|
|
std::string getTableName() const override { return name; }
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2015-01-16 15:22:12 +00:00
|
|
|
|
bool supportsParallelReplicas() const override { return true; }
|
|
|
|
|
|
2014-11-12 10:37:47 +00:00
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
2014-10-03 17:55:36 +00:00
|
|
|
|
NameAndTypePair getColumn(const String & column_name) const override;
|
|
|
|
|
bool hasColumn(const String & column_name) const override;
|
2014-01-16 14:52:13 +00:00
|
|
|
|
|
2013-02-08 17:06:29 +00:00
|
|
|
|
BlockInputStreams read(
|
|
|
|
|
const Names & column_names,
|
|
|
|
|
ASTPtr query,
|
2014-12-17 11:53:17 +00:00
|
|
|
|
const Context & context,
|
2013-02-08 17:06:29 +00:00
|
|
|
|
const Settings & settings,
|
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
|
size_t max_block_size = DEFAULT_BLOCK_SIZE,
|
2014-10-03 17:55:36 +00:00
|
|
|
|
unsigned threads = 1) override;
|
2013-09-30 01:29:19 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
void shutdown() override;
|
2014-02-11 18:38:21 +00:00
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
~StorageChunkMerger() override;
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2013-02-08 17:06:29 +00:00
|
|
|
|
private:
|
2015-03-23 08:42:29 +00:00
|
|
|
|
const String this_database;
|
|
|
|
|
const String name;
|
2013-02-08 17:06:29 +00:00
|
|
|
|
NamesAndTypesListPtr columns;
|
2015-03-23 08:42:29 +00:00
|
|
|
|
const String source_database;
|
2013-02-08 17:06:29 +00:00
|
|
|
|
OptimizedRegularExpression table_name_regexp;
|
|
|
|
|
std::string destination_name_prefix;
|
2015-03-23 08:42:29 +00:00
|
|
|
|
const size_t chunks_to_merge;
|
2013-05-05 18:02:05 +00:00
|
|
|
|
Context & context;
|
2013-09-14 05:14:22 +00:00
|
|
|
|
Settings settings;
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2013-02-08 17:06:29 +00:00
|
|
|
|
Logger * log;
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2014-01-27 13:52:01 +00:00
|
|
|
|
/// Название виртуального столбца, отвечающего за имя таблицы, из которой идет чтение. (Например "_table")
|
2014-01-16 14:52:13 +00:00
|
|
|
|
String _table_column_name;
|
|
|
|
|
|
2015-03-23 08:42:29 +00:00
|
|
|
|
class MergeTask;
|
|
|
|
|
using MergeTaskPtr = std::shared_ptr<MergeTask>;
|
|
|
|
|
MergeTaskPtr merge_task;
|
2015-04-16 06:12:35 +00:00
|
|
|
|
BackgroundProcessingPool::TaskHandle merge_task_handle;
|
2015-03-23 08:42:29 +00:00
|
|
|
|
|
2013-02-08 17:06:29 +00:00
|
|
|
|
StorageChunkMerger(
|
|
|
|
|
const std::string & this_database_,
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
2013-02-08 17:06:29 +00:00
|
|
|
|
const String & source_database_,
|
|
|
|
|
const String & table_name_regexp_,
|
|
|
|
|
const std::string & destination_name_prefix_,
|
|
|
|
|
size_t chunks_to_merge_,
|
|
|
|
|
Context & context_);
|
2014-10-03 17:55:36 +00:00
|
|
|
|
|
|
|
|
|
Block getBlockWithVirtualColumns(const Storages & selected_tables) const;
|
|
|
|
|
|
2013-05-15 12:32:40 +00:00
|
|
|
|
typedef std::set<std::string> TableNames;
|
|
|
|
|
/// Какие таблицы типа Chunks сейчас пишет хоть один ChunkMerger.
|
|
|
|
|
/// Нужно смотреть, залочив mutex из контекста.
|
|
|
|
|
static TableNames currently_written_groups;
|
2013-02-08 17:06:29 +00:00
|
|
|
|
};
|
2014-10-16 01:21:03 +00:00
|
|
|
|
|
2013-02-08 17:06:29 +00:00
|
|
|
|
}
|