2016-01-28 01:00:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterserverIOHandler.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <IO/HashingWriteBuffer.h>
|
|
|
|
#include <IO/copyData.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:
|
2017-04-01 07:20:54 +00:00
|
|
|
Service(MergeTreeData & data_, StoragePtr & storage_) : data(data_),
|
|
|
|
owned_storage(storage_), log(&Logger::get(data.getLogName() + " (Replicated PartsService)")) {}
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Service(const Service &) = delete;
|
|
|
|
Service & operator=(const Service &) = delete;
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getId(const std::string & node_id) const override;
|
2017-04-06 13:03:23 +00:00
|
|
|
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:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData::DataPartPtr findPart(const String & name);
|
|
|
|
MergeTreeData::DataPartPtr findShardedPart(const String & name, size_t shard_no);
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData & data;
|
|
|
|
StoragePtr owned_storage;
|
|
|
|
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:
|
2017-04-01 07:20:54 +00:00
|
|
|
Fetcher(MergeTreeData & data_) : data(data_), log(&Logger::get("Fetcher")) {}
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +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.
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData::MutableDataPartPtr fetchPart(
|
|
|
|
const String & part_name,
|
|
|
|
const String & replica_path,
|
|
|
|
const String & host,
|
|
|
|
int port,
|
|
|
|
bool to_detached = false);
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Method for resharding. Downloads a sharded part
|
|
|
|
/// from the specified shard to the `to_detached` folder.
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData::MutableDataPartPtr fetchShardedPart(
|
|
|
|
const InterserverIOEndpointLocation & location,
|
|
|
|
const String & part_name,
|
|
|
|
size_t shard_no);
|
2016-01-28 01:00:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void cancel() { is_cancelled = true; }
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData::MutableDataPartPtr fetchPartImpl(
|
|
|
|
const String & part_name,
|
|
|
|
const String & replica_path,
|
|
|
|
const String & host,
|
|
|
|
int port,
|
|
|
|
const String & shard_no,
|
|
|
|
bool to_detached);
|
2016-01-28 01:00:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData & data;
|
2017-04-16 15:00:33 +00:00
|
|
|
/// You need to stop the data transfer.
|
2017-04-01 07:20:54 +00:00
|
|
|
std::atomic<bool> is_cancelled {false};
|
|
|
|
Logger * log;
|
2016-01-28 01:00:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|