ClickHouse/src/Storages/StorageExternalDistributed.h

69 lines
2.1 KiB
C++
Raw Normal View History

2021-03-27 14:35:44 +00:00
#pragma once
#include "config_core.h"
2021-10-02 07:13:14 +00:00
#include <base/shared_ptr_helper.h>
2021-03-27 14:35:44 +00:00
#include <Storages/IStorage.h>
namespace DB
{
2021-09-15 22:45:43 +00:00
struct ExternalDataSourceConfiguration;
/// 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.
2021-03-27 21:11:10 +00:00
/// Replicas on each shard have the same priority, traversed replicas are moved to the end of the queue.
2021-09-15 22:45:43 +00:00
/// Similar approach is used for URL storage.
2021-06-15 19:55:21 +00:00
class StorageExternalDistributed final : public shared_ptr_helper<StorageExternalDistributed>, public DB::IStorage
2021-03-27 14:35:44 +00:00
{
2021-06-15 19:55:21 +00:00
friend struct shared_ptr_helper<StorageExternalDistributed>;
2021-03-27 14:35:44 +00:00
public:
2021-03-28 10:27:37 +00:00
enum class ExternalStorageEngine
{
MySQL,
PostgreSQL,
2021-04-21 12:32:57 +00:00
URL
2021-03-28 10:27:37 +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,
ContextPtr context,
2021-03-27 14:35:44 +00:00
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
unsigned num_streams) override;
protected:
StorageExternalDistributed(
2021-03-27 14:35:44 +00:00
const StorageID & table_id_,
2021-03-28 10:27:37 +00:00
ExternalStorageEngine table_engine,
2021-03-27 14:35:44 +00:00
const String & cluster_description,
2021-09-15 22:45:43 +00:00
const ExternalDataSourceConfiguration & configuration,
2021-03-27 14:35:44 +00:00
const ColumnsDescription & columns_,
const ConstraintsDescription & constraints_,
2021-04-23 12:18:23 +00:00
const String & comment,
ContextPtr context_);
2021-03-27 14:35:44 +00:00
2021-04-21 12:32:57 +00:00
StorageExternalDistributed(
2021-04-21 19:53:38 +00:00
const String & addresses_description,
2021-04-21 12:32:57 +00:00
const StorageID & table_id,
const String & format_name,
const std::optional<FormatSettings> & format_settings,
const String & compression_method,
const ColumnsDescription & columns,
const ConstraintsDescription & constraints,
ContextPtr context);
2021-03-27 14:35:44 +00:00
private:
using Shards = std::unordered_set<StoragePtr>;
2021-03-27 14:35:44 +00:00
Shards shards;
};
}