ClickHouse/dbms/include/DB/Storages/StorageDistributed.h

76 lines
3.0 KiB
C
Raw Normal View History

2012-05-21 20:38:34 +00:00
#pragma once
#include <DB/Storages/IStorage.h>
#include <DB/Client/ConnectionPool.h>
#include <DB/Client/ConnectionPoolWithFailover.h>
2012-07-26 20:16:57 +00:00
#include <DB/Interpreters/Settings.h>
2012-05-21 20:38:34 +00:00
namespace DB
{
/** Распределённая таблица, находящаяся на нескольких серверах.
* Использует данные заданной БД и таблицы на каждом сервере.
2012-05-30 04:45:49 +00:00
*
* Можно передать один адрес, а не несколько.
* В этом случае, таблицу можно считать удалённой, а не распределённой.
2012-05-21 20:38:34 +00:00
*/
class StorageDistributed : public IStorage
{
public:
/// Массив шардов. Каждый шард - адреса одного сервера.
2012-05-21 20:38:34 +00:00
typedef std::vector<Poco::Net::SocketAddress> Addresses;
/// Массив шардов. Для каждого шарда - массив адресов реплик (серверов, считающихся идентичными).
typedef std::vector<Addresses> AddressesWithFailover;
2012-05-21 20:38:34 +00:00
StorageDistributed(
const std::string & name_, /// Имя таблицы.
NamesAndTypesListPtr columns_, /// Список столбцов.
const Addresses & addresses, /// Адреса удалённых серверов.
2012-05-21 20:38:34 +00:00
const String & remote_database_, /// БД на удалённых серверах.
const String & remote_table_, /// Имя таблицы на удалённых серверах.
2012-08-02 17:33:31 +00:00
const DataTypeFactory & data_type_factory_,
const Settings & settings);
2012-05-21 20:38:34 +00:00
/// Использовать реплики для отказоустойчивости.
StorageDistributed(
const std::string & name_, /// Имя таблицы.
NamesAndTypesListPtr columns_, /// Список столбцов.
const AddressesWithFailover & addresses, /// Адреса удалённых серверов с учётом реплик.
const String & remote_database_, /// БД на удалённых серверах.
const String & remote_table_, /// Имя таблицы на удалённых серверах.
const DataTypeFactory & data_type_factory_,
const Settings & settings);
2012-05-21 20:38:34 +00:00
std::string getName() const { return "Distributed"; }
std::string getTableName() const { return name; }
2012-12-15 04:39:13 +00:00
bool supportsSampling() const { return true; }
2012-05-21 20:38:34 +00:00
const NamesAndTypesList & getColumnsList() const { return *columns; }
bool isRemote() const { return true; }
2012-05-21 20:38:34 +00:00
BlockInputStreams read(
const Names & column_names,
ASTPtr query,
2012-05-22 18:32:45 +00:00
QueryProcessingStage::Enum & processed_stage,
2012-05-21 20:38:34 +00:00
size_t max_block_size = DEFAULT_BLOCK_SIZE,
2012-05-30 04:45:49 +00:00
unsigned threads = 1);
2012-05-21 20:38:34 +00:00
void drop() {}
2012-06-18 06:19:13 +00:00
void rename(const String & new_path_to_db, const String & new_name) { name = new_name; }
2012-05-21 20:38:34 +00:00
private:
2012-06-18 06:19:13 +00:00
String name;
2012-05-21 20:38:34 +00:00
NamesAndTypesListPtr columns;
String remote_database;
String remote_table;
2012-08-02 17:33:31 +00:00
const DataTypeFactory & data_type_factory;
2012-05-21 20:38:34 +00:00
/// Соединения с удалёнными серверами.
ConnectionPools pools;
2012-05-21 20:38:34 +00:00
};
}