2012-05-17 19:15:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-11-20 04:15:43 +00:00
|
|
|
#include <optional>
|
2017-04-17 16:16:04 +00:00
|
|
|
|
2015-09-29 19:19:54 +00:00
|
|
|
#include <common/logger_useful.h>
|
2012-10-16 18:12:29 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Throttler.h>
|
|
|
|
#include <Client/ConnectionPool.h>
|
|
|
|
#include <Client/MultiplexedConnections.h>
|
|
|
|
#include <Interpreters/Cluster.h>
|
2016-10-10 08:44:52 +00:00
|
|
|
|
2020-06-02 16:27:05 +00:00
|
|
|
#include <DataStreams/RemoteQueryExecutor.h>
|
2012-05-17 19:15:53 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-12-10 22:05:02 +00:00
|
|
|
class Context;
|
|
|
|
|
2018-02-22 11:40:23 +00:00
|
|
|
/** This class allows one to launch queries on remote replicas of one shard and get results
|
2012-05-17 19:15:53 +00:00
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class RemoteBlockInputStream : public IBlockInputStream
|
2012-05-17 19:15:53 +00:00
|
|
|
{
|
2014-04-07 00:09:19 +00:00
|
|
|
public:
|
2017-07-31 15:03:22 +00:00
|
|
|
/// Takes already set connection.
|
2017-07-28 19:34:25 +00:00
|
|
|
RemoteBlockInputStream(
|
|
|
|
Connection & connection,
|
2020-12-10 22:05:02 +00:00
|
|
|
const String & query_, const Block & header_, const Context & context_,
|
2019-10-19 20:36:35 +00:00
|
|
|
const ThrottlerPtr & throttler = nullptr, const Scalars & scalars_ = Scalars(), const Tables & external_tables_ = Tables(),
|
2017-07-28 19:34:25 +00:00
|
|
|
QueryProcessingStage::Enum stage_ = QueryProcessingStage::Complete);
|
|
|
|
|
|
|
|
/// Accepts several connections already taken from pool.
|
|
|
|
RemoteBlockInputStream(
|
|
|
|
std::vector<IConnectionPool::Entry> && connections,
|
2020-12-10 22:05:02 +00:00
|
|
|
const String & query_, const Block & header_, const Context & context_,
|
2019-10-19 20:36:35 +00:00
|
|
|
const ThrottlerPtr & throttler = nullptr, const Scalars & scalars_ = Scalars(), const Tables & external_tables_ = Tables(),
|
2017-07-28 19:34:25 +00:00
|
|
|
QueryProcessingStage::Enum stage_ = QueryProcessingStage::Complete);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 15:03:22 +00:00
|
|
|
/// Takes a pool and gets one or several connections from it.
|
2017-07-28 19:34:25 +00:00
|
|
|
RemoteBlockInputStream(
|
|
|
|
const ConnectionPoolWithFailoverPtr & pool,
|
2020-12-10 22:05:02 +00:00
|
|
|
const String & query_, const Block & header_, const Context & context_,
|
2019-10-19 20:36:35 +00:00
|
|
|
const ThrottlerPtr & throttler = nullptr, const Scalars & scalars_ = Scalars(), const Tables & external_tables_ = Tables(),
|
2017-07-28 19:34:25 +00:00
|
|
|
QueryProcessingStage::Enum stage_ = QueryProcessingStage::Complete);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-07-05 16:50:44 +00:00
|
|
|
/// Set the query_id. For now, used by performance test to later find the query
|
2020-06-02 16:27:05 +00:00
|
|
|
/// in the server query_log. Must be called before sending the query to the server.
|
|
|
|
void setQueryId(const std::string & query_id) { query_executor.setQueryId(query_id); }
|
2019-07-05 16:50:44 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Specify how we allocate connections on a shard.
|
2020-06-02 16:27:05 +00:00
|
|
|
void setPoolMode(PoolMode pool_mode) { query_executor.setPoolMode(pool_mode); }
|
2017-04-17 16:16:04 +00:00
|
|
|
|
2020-06-02 16:27:05 +00:00
|
|
|
void setMainTable(StorageID main_table_) { query_executor.setMainTable(std::move(main_table_)); }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// Sends query (initiates calculation) before read()
|
|
|
|
void readPrefix() override;
|
|
|
|
|
2020-06-02 16:27:05 +00:00
|
|
|
/// Prevent default progress notification because progress' callback is called by its own.
|
2017-12-01 18:36:55 +00:00
|
|
|
void progress(const Progress & /*value*/) override {}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-05 21:09:39 +00:00
|
|
|
void cancel(bool kill) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String getName() const override { return "Remote"; }
|
|
|
|
|
2020-06-02 16:27:05 +00:00
|
|
|
Block getHeader() const override { return query_executor.getHeader(); }
|
2020-06-02 16:37:30 +00:00
|
|
|
Block getTotals() override { return query_executor.getTotals(); }
|
|
|
|
Block getExtremes() override { return query_executor.getExtremes(); }
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
|
|
|
void readSuffixImpl() override;
|
2013-09-13 20:33:09 +00:00
|
|
|
|
2015-02-21 13:59:15 +00:00
|
|
|
private:
|
2020-06-02 16:27:05 +00:00
|
|
|
RemoteQueryExecutor query_executor;
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("RemoteBlockInputStream");
|
2020-06-02 16:27:05 +00:00
|
|
|
|
|
|
|
void init();
|
2012-05-17 19:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|