ClickHouse/dbms/Storages/MergeTree/DataPartsExchange.h

84 lines
2.3 KiB
C++
Raw Normal View History

2016-01-28 01:00:27 +00:00
#pragma once
#include <Interpreters/InterserverIOHandler.h>
#include <Storages/MergeTree/MergeTreeData.h>
#include <Storages/IStorage_fwd.h>
#include <IO/HashingWriteBuffer.h>
#include <IO/copyData.h>
#include <IO/ConnectionTimeouts.h>
#include <IO/ReadWriteBufferFromHTTP.h>
2016-01-28 01:00:27 +00:00
namespace DB
{
namespace DataPartsExchange
{
2017-04-16 15:00:33 +00:00
/** Service for sending parts from the table *MergeTree.
2016-01-28 01:00:27 +00:00
*/
class Service final : public InterserverIOEndpoint
{
public:
2020-01-14 14:27:48 +00:00
Service(MergeTreeData & data_)
: data(data_), log(&Logger::get(data.getLogName() + " (Replicated PartsService)")) {}
2016-01-28 01:00:27 +00:00
Service(const Service &) = delete;
Service & operator=(const Service &) = delete;
2016-01-28 01:00:27 +00:00
std::string getId(const std::string & node_id) const override;
void processQuery(const Poco::Net::HTMLForm & params, ReadBuffer & body, WriteBuffer & out, Poco::Net::HTTPServerResponse & response) override;
2016-01-28 01:00:27 +00:00
private:
MergeTreeData::DataPartPtr findPart(const String & name);
2016-01-28 01:00:27 +00:00
private:
2020-01-14 14:27:48 +00:00
/// StorageReplicatedMergeTree::shutdown() waits for all parts exchange handlers to finish,
/// so Service will never access dangling reference to storage
MergeTreeData & data;
Logger * log;
2016-01-28 01:00:27 +00:00
};
2017-04-16 15:00:33 +00:00
/** Client for getting the parts from the table *MergeTree.
2016-01-28 01:00:27 +00:00
*/
class Fetcher final
{
public:
Fetcher(MergeTreeData & data_) : data(data_), log(&Logger::get("Fetcher")) {}
2016-01-28 01:00:27 +00:00
Fetcher(const Fetcher &) = delete;
Fetcher & operator=(const Fetcher &) = delete;
2016-01-28 01:00:27 +00:00
2017-04-16 15:00:33 +00:00
/// Downloads a part to tmp_directory. If to_detached - downloads to the `detached` directory.
MergeTreeData::MutableDataPartPtr fetchPart(
const String & part_name,
const String & replica_path,
const String & host,
int port,
const ConnectionTimeouts & timeouts,
const String & user,
const String & password,
const String & interserver_scheme,
bool to_detached = false,
const String & tmp_prefix_ = "");
2016-01-28 01:00:27 +00:00
/// You need to stop the data transfer.
ActionBlocker blocker;
2016-01-28 01:00:27 +00:00
private:
MergeTreeData::MutableDataPartPtr downloadPart(
const String & part_name,
const String & replica_path,
bool to_detached,
const String & tmp_prefix_,
2019-11-27 09:39:44 +00:00
const ReservationPtr reservation,
PooledReadWriteBufferFromHTTP & in);
MergeTreeData & data;
Logger * log;
2016-01-28 01:00:27 +00:00
};
}
}