1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#pragma once
#include <yt/cpp/mapreduce/common/retry_lib.h>
#include <yt/cpp/mapreduce/interface/raw_batch_request.h>
#include <queue>
namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
class TRpcRawBatchRequest
: public IRawBatchRequest
{
public:
TRpcRawBatchRequest(
IRawClientPtr rawClient,
const TConfigPtr& config);
void ExecuteBatch(const TExecuteBatchOptions& options = {}) override;
::NThreading::TFuture<TNodeId> Create(
const TTransactionId& transactionId,
const TYPath& path,
ENodeType type,
const TCreateOptions& options = {}) override;
::NThreading::TFuture<void> Remove(
const TTransactionId& transactionId,
const TYPath& path,
const TRemoveOptions& options = {}) override;
::NThreading::TFuture<bool> Exists(
const TTransactionId& transactionId,
const TYPath& path,
const TExistsOptions& options = {}) override;
::NThreading::TFuture<TNode> Get(
const TTransactionId& transactionId,
const TYPath& path,
const TGetOptions& options = {}) override;
::NThreading::TFuture<void> Set(
const TTransactionId& transactionId,
const TYPath& path,
const TNode& value,
const TSetOptions& options = {}) override;
::NThreading::TFuture<TNode::TListType> List(
const TTransactionId& transactionId,
const TYPath& path,
const TListOptions& options = {}) override;
::NThreading::TFuture<TNodeId> Copy(
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TCopyOptions& options = {}) override;
::NThreading::TFuture<TNodeId> Move(
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TMoveOptions& options = {}) override;
::NThreading::TFuture<TNodeId> Link(
const TTransactionId& transactionId,
const TYPath& targetPath,
const TYPath& linkPath,
const TLinkOptions& options = {}) override;
::NThreading::TFuture<TLockId> Lock(
const TTransactionId& transactionId,
const TYPath& path,
ELockMode mode,
const TLockOptions& options = {}) override;
::NThreading::TFuture<void> Unlock(
const TTransactionId& transactionId,
const TYPath& path,
const TUnlockOptions& options = {}) override;
::NThreading::TFuture<TMaybe<TYPath>> GetFileFromCache(
const TTransactionId& transactionId,
const TString& md5Signature,
const TYPath& cachePath,
const TGetFileFromCacheOptions& options = {}) override;
::NThreading::TFuture<TYPath> PutFileToCache(
const TTransactionId& transactionId,
const TYPath& filePath,
const TString& md5Signature,
const TYPath& cachePath,
const TPutFileToCacheOptions& options = {}) override;
::NThreading::TFuture<TCheckPermissionResponse> CheckPermission(
const TString& user,
EPermission permission,
const TYPath& path,
const TCheckPermissionOptions& options = {}) override;
::NThreading::TFuture<TOperationAttributes> GetOperation(
const TOperationId& operationId,
const TGetOperationOptions& options = {}) override;
::NThreading::TFuture<void> AbortOperation(const TOperationId& operationId) override;
::NThreading::TFuture<void> CompleteOperation(const TOperationId& operationId) override;
::NThreading::TFuture<void> SuspendOperation(
const TOperationId& operationId,
const TSuspendOperationOptions& options = {}) override;
::NThreading::TFuture<void> ResumeOperation(
const TOperationId& operationId,
const TResumeOperationOptions& options = {}) override;
::NThreading::TFuture<void> UpdateOperationParameters(
const TOperationId& operationId,
const TUpdateOperationParametersOptions& options = {}) override;
::NThreading::TFuture<TRichYPath> CanonizeYPath(const TRichYPath& path) override;
::NThreading::TFuture<TVector<TTableColumnarStatistics>> GetTableColumnarStatistics(
const TTransactionId& transactionId,
const TVector<TRichYPath>& paths,
const TGetTableColumnarStatisticsOptions& options = {}) override;
::NThreading::TFuture<TMultiTablePartitions> GetTablePartitions(
const TTransactionId& transactionId,
const TVector<TRichYPath>& paths,
const TGetTablePartitionsOptions& options = {}) override;
private:
struct ISingleRequest
: public TThrRefBase
{
virtual void Invoke() = 0;
};
template <typename TResultType>
class TSingleRequest
: public ISingleRequest
{
public:
TSingleRequest(
IRequestRetryPolicyPtr retryPolicy,
std::function<TResultType(TMutationId&)> request);
::NThreading::TFuture<TResultType> GetFuture();
void Invoke() override;
private:
const IRequestRetryPolicyPtr RequestRetryPolicy_;
::NThreading::TPromise<TResultType> Result_;
std::function<TResultType(TMutationId&)> Request_;
};
private:
const IRawClientPtr RawClient_;
const TConfigPtr Config_;
std::queue<TIntrusivePtr<ISingleRequest>> Requests_;
bool Executed_ = false;
template<typename TRequest>
auto AddRequest(TRequest&& request) -> decltype(request->GetFuture())
{
Y_ENSURE(!Executed_, "Cannot add request: batch request is already executed");
auto future = request->GetFuture();
Requests_.emplace(std::forward<decltype(request)>(request));
return future;
}
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail
|