1 | #pragma once |
2 | |
3 | #include <Interpreters/InterserverIOHandler.h> |
4 | #include <Storages/MergeTree/MergeTreeData.h> |
5 | #include <Storages/IStorage_fwd.h> |
6 | #include <IO/HashingWriteBuffer.h> |
7 | #include <IO/copyData.h> |
8 | #include <IO/ConnectionTimeouts.h> |
9 | #include <IO/ReadWriteBufferFromHTTP.h> |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | |
15 | namespace DataPartsExchange |
16 | { |
17 | |
18 | /** Service for sending parts from the table *MergeTree. |
19 | */ |
20 | class Service final : public InterserverIOEndpoint |
21 | { |
22 | public: |
23 | Service(MergeTreeData & data_, StoragePtr & storage_) : data(data_), |
24 | storage(storage_), log(&Logger::get(data.getLogName() + " (Replicated PartsService)" )) {} |
25 | |
26 | Service(const Service &) = delete; |
27 | Service & operator=(const Service &) = delete; |
28 | |
29 | std::string getId(const std::string & node_id) const override; |
30 | void processQuery(const Poco::Net::HTMLForm & params, ReadBuffer & body, WriteBuffer & out, Poco::Net::HTTPServerResponse & response) override; |
31 | |
32 | private: |
33 | MergeTreeData::DataPartPtr findPart(const String & name); |
34 | |
35 | private: |
36 | MergeTreeData & data; |
37 | StorageWeakPtr storage; |
38 | Logger * log; |
39 | }; |
40 | |
41 | /** Client for getting the parts from the table *MergeTree. |
42 | */ |
43 | class Fetcher final |
44 | { |
45 | public: |
46 | Fetcher(MergeTreeData & data_) : data(data_), log(&Logger::get("Fetcher" )) {} |
47 | |
48 | Fetcher(const Fetcher &) = delete; |
49 | Fetcher & operator=(const Fetcher &) = delete; |
50 | |
51 | /// Downloads a part to tmp_directory. If to_detached - downloads to the `detached` directory. |
52 | MergeTreeData::MutableDataPartPtr fetchPart( |
53 | const String & part_name, |
54 | const String & replica_path, |
55 | const String & host, |
56 | int port, |
57 | const ConnectionTimeouts & timeouts, |
58 | const String & user, |
59 | const String & password, |
60 | const String & interserver_scheme, |
61 | bool to_detached = false, |
62 | const String & tmp_prefix_ = "" ); |
63 | |
64 | /// You need to stop the data transfer. |
65 | ActionBlocker blocker; |
66 | |
67 | private: |
68 | MergeTreeData::MutableDataPartPtr downloadPart( |
69 | const String & part_name, |
70 | const String & replica_path, |
71 | bool to_detached, |
72 | const String & tmp_prefix_, |
73 | const ReservationPtr reservation, |
74 | PooledReadWriteBufferFromHTTP & in); |
75 | |
76 | MergeTreeData & data; |
77 | Logger * log; |
78 | }; |
79 | |
80 | } |
81 | |
82 | } |
83 | |