raw_requests.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. #pragma once
  2. #include "raw_batch_request.h"
  3. #include <yt/cpp/mapreduce/common/fwd.h>
  4. #include <yt/cpp/mapreduce/http/context.h>
  5. #include <yt/cpp/mapreduce/interface/client_method_options.h>
  6. #include <yt/cpp/mapreduce/interface/operation.h>
  7. namespace NYT {
  8. ////////////////////////////////////////////////////////////////////////////////
  9. class IRequestRetryPolicy;
  10. struct TClientContext;
  11. struct TExecuteBatchOptions;
  12. ////////////////////////////////////////////////////////////////////////////////
  13. namespace NDetail::NRawClient {
  14. ////////////////////////////////////////////////////////////////////////////////
  15. TOperationAttributes ParseOperationAttributes(const TNode& node);
  16. TCheckPermissionResponse ParseCheckPermissionResponse(const TNode& node);
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //
  19. // marks `batchRequest' as executed
  20. void ExecuteBatch(
  21. IRequestRetryPolicyPtr retryPolicy,
  22. const TClientContext& context,
  23. TRawBatchRequest& batchRequest,
  24. const TExecuteBatchOptions& options = TExecuteBatchOptions());
  25. //
  26. // Cypress
  27. //
  28. TNode Get(
  29. const IRequestRetryPolicyPtr& retryPolicy,
  30. const TClientContext& context,
  31. const TTransactionId& transactionId,
  32. const TYPath& path,
  33. const TGetOptions& options = TGetOptions());
  34. TNode TryGet(
  35. const IRequestRetryPolicyPtr& retryPolicy,
  36. const TClientContext& context,
  37. const TTransactionId& transactionId,
  38. const TYPath& path,
  39. const TGetOptions& options);
  40. void Set(
  41. const IRequestRetryPolicyPtr& retryPolicy,
  42. const TClientContext& context,
  43. const TTransactionId& transactionId,
  44. const TYPath& path,
  45. const TNode& value,
  46. const TSetOptions& options = TSetOptions());
  47. void MultisetAttributes(
  48. const IRequestRetryPolicyPtr& retryPolicy,
  49. const TClientContext& context,
  50. const TTransactionId& transactionId,
  51. const TYPath& path,
  52. const TNode::TMapType& value,
  53. const TMultisetAttributesOptions& options = TMultisetAttributesOptions());
  54. bool Exists(
  55. const IRequestRetryPolicyPtr& retryPolicy,
  56. const TClientContext& context,
  57. const TTransactionId& transactionId,
  58. const TYPath& path,
  59. const TExistsOptions& options = TExistsOptions());
  60. TNodeId Create(
  61. const IRequestRetryPolicyPtr& retryPolicy,
  62. const TClientContext& context,
  63. const TTransactionId& transactionId,
  64. const TYPath& path,
  65. const ENodeType& type,
  66. const TCreateOptions& options = TCreateOptions());
  67. TNodeId CopyWithoutRetries(
  68. const TClientContext& context,
  69. const TTransactionId& transactionId,
  70. const TYPath& sourcePath,
  71. const TYPath& destinationPath,
  72. const TCopyOptions& options = TCopyOptions());
  73. TNodeId CopyInsideMasterCell(
  74. const IRequestRetryPolicyPtr& retryPolicy,
  75. const TClientContext& context,
  76. const TTransactionId& transactionId,
  77. const TYPath& sourcePath,
  78. const TYPath& destinationPath,
  79. const TCopyOptions& options = TCopyOptions());
  80. TNodeId MoveWithoutRetries(
  81. const TClientContext& context,
  82. const TTransactionId& transactionId,
  83. const TYPath& sourcePath,
  84. const TYPath& destinationPath,
  85. const TMoveOptions& options = TMoveOptions());
  86. TNodeId MoveInsideMasterCell(
  87. const IRequestRetryPolicyPtr& retryPolicy,
  88. const TClientContext& context,
  89. const TTransactionId& transactionId,
  90. const TYPath& sourcePath,
  91. const TYPath& destinationPath,
  92. const TMoveOptions& options = TMoveOptions());
  93. void Remove(
  94. const IRequestRetryPolicyPtr& retryPolicy,
  95. const TClientContext& context,
  96. const TTransactionId& transactionId,
  97. const TYPath& path,
  98. const TRemoveOptions& options = TRemoveOptions());
  99. TNode::TListType List(
  100. const IRequestRetryPolicyPtr& retryPolicy,
  101. const TClientContext& context,
  102. const TTransactionId& transactionId,
  103. const TYPath& path,
  104. const TListOptions& options = TListOptions());
  105. TNodeId Link(
  106. const IRequestRetryPolicyPtr& retryPolicy,
  107. const TClientContext& context,
  108. const TTransactionId& transactionId,
  109. const TYPath& targetPath,
  110. const TYPath& linkPath,
  111. const TLinkOptions& options = TLinkOptions());
  112. TLockId Lock(
  113. const IRequestRetryPolicyPtr& retryPolicy,
  114. const TClientContext& context,
  115. const TTransactionId& transactionId,
  116. const TYPath& path,
  117. ELockMode mode,
  118. const TLockOptions& options = TLockOptions());
  119. void Unlock(
  120. IRequestRetryPolicyPtr retryPolicy,
  121. const TClientContext& context,
  122. const TTransactionId& transactionId,
  123. const TYPath& path,
  124. const TUnlockOptions& options = TUnlockOptions());
  125. void Concatenate(
  126. const TClientContext& context,
  127. const TTransactionId& transactionId,
  128. const TVector<TRichYPath>& sourcePaths,
  129. const TRichYPath& destinationPath,
  130. const TConcatenateOptions& options = TConcatenateOptions());
  131. //
  132. // Transactions
  133. //
  134. void PingTx(
  135. const IRequestRetryPolicyPtr& retryPolicy,
  136. const TClientContext& context,
  137. const TTransactionId& transactionId);
  138. //
  139. // Operations
  140. //
  141. TOperationAttributes GetOperation(
  142. const IRequestRetryPolicyPtr& retryPolicy,
  143. const TClientContext& context,
  144. const TOperationId& operationId,
  145. const TGetOperationOptions& options = TGetOperationOptions());
  146. TOperationAttributes GetOperation(
  147. const IRequestRetryPolicyPtr& retryPolicy,
  148. const TClientContext& context,
  149. const TString& operationId,
  150. const TGetOperationOptions& options = TGetOperationOptions());
  151. void AbortOperation(
  152. const IRequestRetryPolicyPtr& retryPolicy,
  153. const TClientContext& context,
  154. const TOperationId& operationId);
  155. void CompleteOperation(
  156. const IRequestRetryPolicyPtr& retryPolicy,
  157. const TClientContext& context,
  158. const TOperationId& operationId);
  159. void SuspendOperation(
  160. const IRequestRetryPolicyPtr& retryPolicy,
  161. const TClientContext& context,
  162. const TOperationId& operationId,
  163. const TSuspendOperationOptions& options = TSuspendOperationOptions());
  164. void ResumeOperation(
  165. const IRequestRetryPolicyPtr& retryPolicy,
  166. const TClientContext& context,
  167. const TOperationId& operationId,
  168. const TResumeOperationOptions& options = TResumeOperationOptions());
  169. TListOperationsResult ListOperations(
  170. const IRequestRetryPolicyPtr& retryPolicy,
  171. const TClientContext& context,
  172. const TListOperationsOptions& options = TListOperationsOptions());
  173. void UpdateOperationParameters(
  174. const IRequestRetryPolicyPtr& retryPolicy,
  175. const TClientContext& context,
  176. const TOperationId& operationId,
  177. const TUpdateOperationParametersOptions& options = TUpdateOperationParametersOptions());
  178. //
  179. // Jobs
  180. //
  181. TJobAttributes GetJob(
  182. const IRequestRetryPolicyPtr& retryPolicy,
  183. const TClientContext& context,
  184. const TOperationId& operationId,
  185. const TJobId& jobId,
  186. const TGetJobOptions& options = TGetJobOptions());
  187. TListJobsResult ListJobs(
  188. const IRequestRetryPolicyPtr& retryPolicy,
  189. const TClientContext& context,
  190. const TOperationId& operationId,
  191. const TListJobsOptions& options = TListJobsOptions());
  192. ::TIntrusivePtr<IFileReader> GetJobInput(
  193. const TClientContext& context,
  194. const TJobId& jobId,
  195. const TGetJobInputOptions& options = TGetJobInputOptions());
  196. ::TIntrusivePtr<IFileReader> GetJobFailContext(
  197. const TClientContext& context,
  198. const TOperationId& operationId,
  199. const TJobId& jobId,
  200. const TGetJobFailContextOptions& options = TGetJobFailContextOptions());
  201. TString GetJobStderrWithRetries(
  202. const IRequestRetryPolicyPtr& retryPolicy,
  203. const TClientContext& context,
  204. const TOperationId& operationId,
  205. const TJobId& jobId,
  206. const TGetJobStderrOptions& /* options */ = TGetJobStderrOptions());
  207. ::TIntrusivePtr<IFileReader> GetJobStderr(
  208. const TClientContext& context,
  209. const TOperationId& operationId,
  210. const TJobId& jobId,
  211. const TGetJobStderrOptions& options = TGetJobStderrOptions());
  212. //
  213. // File cache
  214. //
  215. TMaybe<TYPath> GetFileFromCache(
  216. const IRequestRetryPolicyPtr& retryPolicy,
  217. const TClientContext& context,
  218. const TTransactionId& transactionId,
  219. const TString& md5Signature,
  220. const TYPath& cachePath,
  221. const TGetFileFromCacheOptions& options = TGetFileFromCacheOptions());
  222. TYPath PutFileToCache(
  223. const IRequestRetryPolicyPtr& retryPolicy,
  224. const TClientContext& context,
  225. const TTransactionId& transactionId,
  226. const TYPath& filePath,
  227. const TString& md5Signature,
  228. const TYPath& cachePath,
  229. const TPutFileToCacheOptions& options = TPutFileToCacheOptions());
  230. //
  231. // SkyShare
  232. //
  233. TNode::TListType SkyShareTable(
  234. const IRequestRetryPolicyPtr& retryPolicy,
  235. const TClientContext& context,
  236. const std::vector<TYPath>& tablePaths,
  237. const TSkyShareTableOptions& options);
  238. //
  239. // Misc
  240. //
  241. TCheckPermissionResponse CheckPermission(
  242. const IRequestRetryPolicyPtr& retryPolicy,
  243. const TClientContext& context,
  244. const TString& user,
  245. EPermission permission,
  246. const TYPath& path,
  247. const TCheckPermissionOptions& options = TCheckPermissionOptions());
  248. TVector<TTabletInfo> GetTabletInfos(
  249. const IRequestRetryPolicyPtr& retryPolicy,
  250. const TClientContext& context,
  251. const TYPath& path,
  252. const TVector<int>& tabletIndexes,
  253. const TGetTabletInfosOptions& options);
  254. TVector<TTableColumnarStatistics> GetTableColumnarStatistics(
  255. const IRequestRetryPolicyPtr& retryPolicy,
  256. const TClientContext& context,
  257. const TTransactionId& transactionId,
  258. const TVector<TRichYPath>& paths,
  259. const TGetTableColumnarStatisticsOptions& options);
  260. TMultiTablePartitions GetTablePartitions(
  261. const IRequestRetryPolicyPtr& retryPolicy,
  262. const TClientContext& context,
  263. const TTransactionId& transactionId,
  264. const TVector<TRichYPath>& paths,
  265. const TGetTablePartitionsOptions& options);
  266. TRichYPath CanonizeYPath(
  267. const IRequestRetryPolicyPtr& retryPolicy,
  268. const TClientContext& context,
  269. const TRichYPath& path);
  270. TVector<TRichYPath> CanonizeYPaths(
  271. const IRequestRetryPolicyPtr& retryPolicy,
  272. const TClientContext& context,
  273. const TVector<TRichYPath>& paths);
  274. //
  275. // Tables
  276. //
  277. void AlterTable(
  278. const IRequestRetryPolicyPtr& retryPolicy,
  279. const TClientContext& context,
  280. const TTransactionId& transactionId,
  281. const TYPath& path,
  282. const TAlterTableOptions& options);
  283. void AlterTableReplica(
  284. const IRequestRetryPolicyPtr& retryPolicy,
  285. const TClientContext& context,
  286. const TReplicaId& replicaId,
  287. const TAlterTableReplicaOptions& options);
  288. void DeleteRows(
  289. const IRequestRetryPolicyPtr& retryPolicy,
  290. const TClientContext& context,
  291. const TYPath& path,
  292. const TNode::TListType& keys,
  293. const TDeleteRowsOptions& options);
  294. void FreezeTable(
  295. const IRequestRetryPolicyPtr& retryPolicy,
  296. const TClientContext& context,
  297. const TYPath& path,
  298. const TFreezeTableOptions& options);
  299. void UnfreezeTable(
  300. const IRequestRetryPolicyPtr& retryPolicy,
  301. const TClientContext& context,
  302. const TYPath& path,
  303. const TUnfreezeTableOptions& options);
  304. // Transactions
  305. void AbortTransaction(
  306. const IRequestRetryPolicyPtr& retryPolicy,
  307. const TClientContext& context,
  308. const TTransactionId& transactionId);
  309. void CommitTransaction(
  310. const IRequestRetryPolicyPtr& retryPolicy,
  311. const TClientContext& context,
  312. const TTransactionId& transactionId);
  313. TTransactionId StartTransaction(
  314. const IRequestRetryPolicyPtr& retryPolicy,
  315. const TClientContext& context,
  316. const TTransactionId& parentId,
  317. const TStartTransactionOptions& options);
  318. ////////////////////////////////////////////////////////////////////////////////
  319. template<typename TSrc, typename TBatchAdder>
  320. auto BatchTransform(
  321. const IRequestRetryPolicyPtr& retryPolicy,
  322. const TClientContext& context,
  323. const TSrc& src,
  324. TBatchAdder batchAdder,
  325. const TExecuteBatchOptions& executeBatchOptions = {})
  326. {
  327. TRawBatchRequest batch(context.Config);
  328. using TFuture = decltype(batchAdder(batch, *std::begin(src)));
  329. TVector<TFuture> futures;
  330. for (const auto& el : src) {
  331. futures.push_back(batchAdder(batch, el));
  332. }
  333. ExecuteBatch(retryPolicy, context, batch, executeBatchOptions);
  334. using TDst = decltype(futures[0].ExtractValueSync());
  335. TVector<TDst> result;
  336. result.reserve(std::size(src));
  337. for (auto& future : futures) {
  338. result.push_back(future.ExtractValueSync());
  339. }
  340. return result;
  341. }
  342. ////////////////////////////////////////////////////////////////////////////////
  343. } // namespace NDetail::NRawClient
  344. } // namespace NYT