2021-07-15 16:15:16 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Processors/QueryPlan/ISourceStep.h>
|
|
|
|
#include <Core/QueryProcessingStage.h>
|
2021-12-09 10:39:28 +00:00
|
|
|
#include <Client/IConnections.h>
|
2021-07-15 16:15:16 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
|
|
|
#include <Interpreters/StorageID.h>
|
2022-06-02 09:46:33 +00:00
|
|
|
#include <Interpreters/ClusterProxy/SelectStreamFactory.h>
|
2021-12-09 10:39:28 +00:00
|
|
|
#include <Storages/MergeTree/ParallelReplicasReadingCoordinator.h>
|
2021-07-15 16:15:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ConnectionPoolWithFailover;
|
|
|
|
using ConnectionPoolWithFailoverPtr = std::shared_ptr<ConnectionPoolWithFailover>;
|
|
|
|
|
|
|
|
class Throttler;
|
|
|
|
using ThrottlerPtr = std::shared_ptr<Throttler>;
|
|
|
|
|
2021-07-16 10:56:13 +00:00
|
|
|
/// Reading step from remote servers.
|
|
|
|
/// Unite query results from several shards.
|
2021-07-15 16:15:16 +00:00
|
|
|
class ReadFromRemote final : public ISourceStep
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadFromRemote(
|
2022-06-02 09:46:33 +00:00
|
|
|
ClusterProxy::SelectStreamFactory::Shards shards_,
|
2021-07-15 16:15:16 +00:00
|
|
|
Block header_,
|
|
|
|
QueryProcessingStage::Enum stage_,
|
|
|
|
StorageID main_table_,
|
|
|
|
ASTPtr table_func_ptr_,
|
|
|
|
ContextPtr context_,
|
|
|
|
ThrottlerPtr throttler_,
|
|
|
|
Scalars scalars_,
|
|
|
|
Tables external_tables_,
|
2021-07-31 07:45:26 +00:00
|
|
|
Poco::Logger * log_,
|
2022-05-31 14:43:38 +00:00
|
|
|
UInt32 shard_count_,
|
|
|
|
std::shared_ptr<const StorageLimitsList> storage_limits_);
|
2021-07-15 16:15:16 +00:00
|
|
|
|
|
|
|
String getName() const override { return "ReadFromRemote"; }
|
|
|
|
|
2021-09-14 16:28:41 +00:00
|
|
|
void initializePipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;
|
2021-07-15 16:15:16 +00:00
|
|
|
|
|
|
|
private:
|
2021-12-09 10:39:28 +00:00
|
|
|
enum class Mode
|
|
|
|
{
|
|
|
|
PerReplica,
|
|
|
|
PerShard
|
|
|
|
};
|
|
|
|
|
2022-06-02 09:46:33 +00:00
|
|
|
ClusterProxy::SelectStreamFactory::Shards shards;
|
2021-07-15 16:15:16 +00:00
|
|
|
QueryProcessingStage::Enum stage;
|
|
|
|
|
|
|
|
StorageID main_table;
|
|
|
|
ASTPtr table_func_ptr;
|
|
|
|
|
|
|
|
ContextPtr context;
|
|
|
|
|
|
|
|
ThrottlerPtr throttler;
|
|
|
|
Scalars scalars;
|
|
|
|
Tables external_tables;
|
|
|
|
|
2022-05-31 14:43:38 +00:00
|
|
|
std::shared_ptr<const StorageLimitsList> storage_limits;
|
|
|
|
|
2021-07-15 16:15:16 +00:00
|
|
|
Poco::Logger * log;
|
|
|
|
|
2021-07-31 07:45:26 +00:00
|
|
|
UInt32 shard_count;
|
2022-06-02 09:46:33 +00:00
|
|
|
void addLazyPipe(Pipes & pipes, const ClusterProxy::SelectStreamFactory::Shard & shard);
|
|
|
|
void addPipe(Pipes & pipes, const ClusterProxy::SelectStreamFactory::Shard & shard);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ReadFromParallelRemoteReplicasStep : public ISourceStep
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadFromParallelRemoteReplicasStep(
|
|
|
|
ParallelReplicasReadingCoordinatorPtr coordinator_,
|
|
|
|
ClusterProxy::SelectStreamFactory::Shard shard,
|
|
|
|
Block header_,
|
|
|
|
QueryProcessingStage::Enum stage_,
|
|
|
|
StorageID main_table_,
|
|
|
|
ASTPtr table_func_ptr_,
|
|
|
|
ContextPtr context_,
|
|
|
|
ThrottlerPtr throttler_,
|
|
|
|
Scalars scalars_,
|
|
|
|
Tables external_tables_,
|
|
|
|
Poco::Logger * log_,
|
2022-06-02 19:38:47 +00:00
|
|
|
std::shared_ptr<const StorageLimitsList> storage_limits_);
|
2022-06-02 09:46:33 +00:00
|
|
|
|
|
|
|
String getName() const override { return "ReadFromRemoteParallelReplicas"; }
|
|
|
|
|
|
|
|
void initializePipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void addPipeForSingeReplica(Pipes & pipes, std::shared_ptr<ConnectionPoolWithFailover> pool, IConnections::ReplicaInfo replica_info);
|
|
|
|
|
|
|
|
ParallelReplicasReadingCoordinatorPtr coordinator;
|
|
|
|
ClusterProxy::SelectStreamFactory::Shard shard;
|
|
|
|
QueryProcessingStage::Enum stage;
|
|
|
|
|
|
|
|
StorageID main_table;
|
|
|
|
ASTPtr table_func_ptr;
|
|
|
|
|
|
|
|
ContextPtr context;
|
|
|
|
|
|
|
|
ThrottlerPtr throttler;
|
|
|
|
Scalars scalars;
|
|
|
|
Tables external_tables;
|
|
|
|
|
2022-06-02 19:38:47 +00:00
|
|
|
std::shared_ptr<const StorageLimitsList> storage_limits;
|
|
|
|
|
2022-06-02 09:46:33 +00:00
|
|
|
Poco::Logger * log;
|
2021-07-15 16:15:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|