2021-03-27 14:35:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
2021-03-27 20:49:26 +00:00
|
|
|
#if USE_MYSQL || USE_LIBPQXX
|
2021-03-27 14:35:44 +00:00
|
|
|
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <mysqlxx/PoolWithFailover.h>
|
|
|
|
|
|
|
|
|
2021-03-27 20:49:26 +00:00
|
|
|
|
2021-03-27 14:35:44 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-03-27 17:12:47 +00:00
|
|
|
/// Storages MySQL and PostgreSQL use ConnectionPoolWithFailover and support multiple replicas.
|
2021-03-27 20:49:26 +00:00
|
|
|
/// This class unites multiple storages with replicas into multiple shards with replicas.
|
|
|
|
/// A query to external database is passed to one replica on each shard, the result is united.
|
|
|
|
/// Replicas on each shard have the same priority, unavailable replicas are moved to the end of
|
|
|
|
/// the queue. The queue is shuffled from time to time.
|
|
|
|
/// TODO: try `load_balancing` setting for replicas priorities same way as for table function `remote`
|
2021-03-27 17:12:47 +00:00
|
|
|
class StorageExternalDistributed final : public ext::shared_ptr_helper<StorageExternalDistributed>, public DB::IStorage
|
2021-03-27 14:35:44 +00:00
|
|
|
{
|
2021-03-27 17:12:47 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageExternalDistributed>;
|
2021-03-27 14:35:44 +00:00
|
|
|
|
|
|
|
public:
|
2021-03-27 17:12:47 +00:00
|
|
|
std::string getName() const override { return "ExternalDistributed"; }
|
2021-03-27 14:35:44 +00:00
|
|
|
|
|
|
|
Pipe read(
|
|
|
|
const Names & column_names,
|
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
|
|
|
SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
|
|
|
protected:
|
2021-03-27 17:12:47 +00:00
|
|
|
StorageExternalDistributed(
|
2021-03-27 14:35:44 +00:00
|
|
|
const StorageID & table_id_,
|
2021-03-27 17:12:47 +00:00
|
|
|
const String & engine_name_,
|
2021-03-27 14:35:44 +00:00
|
|
|
const String & cluster_description,
|
2021-03-27 17:12:47 +00:00
|
|
|
const String & remote_database_,
|
|
|
|
const String & remote_table_,
|
2021-03-27 14:35:44 +00:00
|
|
|
const String & username,
|
|
|
|
const String & password,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const ConstraintsDescription & constraints_,
|
|
|
|
const Context & context_);
|
|
|
|
|
|
|
|
private:
|
2021-03-27 17:12:47 +00:00
|
|
|
using Shards = std::unordered_set<StoragePtr>;
|
2021-03-27 14:35:44 +00:00
|
|
|
Shards shards;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|