batch_request.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #pragma once
  2. #include "fwd.h"
  3. #include "client_method_options.h"
  4. #include <library/cpp/threading/future/future.h>
  5. #include <util/generic/ptr.h>
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////
  8. /// Helper base of @ref NYT::IBatchRequest holding most of useful methods.
  9. class IBatchRequestBase
  10. : public TThrRefBase
  11. {
  12. public:
  13. virtual ~IBatchRequestBase() = default;
  14. ///
  15. /// @brief Create cypress node.
  16. ///
  17. /// @see NYT::ICypressClient::Create
  18. virtual ::NThreading::TFuture<TNodeId> Create(
  19. const TYPath& path,
  20. ENodeType type,
  21. const TCreateOptions& options = TCreateOptions()) = 0;
  22. ///
  23. /// @brief Remove cypress node.
  24. ///
  25. /// @see NYT::ICypressClient::Remove
  26. virtual ::NThreading::TFuture<void> Remove(
  27. const TYPath& path,
  28. const TRemoveOptions& options = TRemoveOptions()) = 0;
  29. ///
  30. /// @brief Check wether cypress node exists.
  31. ///
  32. /// @see NYT::ICypressClient::Exists
  33. virtual ::NThreading::TFuture<bool> Exists(
  34. const TYPath& path,
  35. const TExistsOptions& options = TExistsOptions()) = 0;
  36. ///
  37. /// @brief Get cypress node.
  38. ///
  39. /// @see NYT::ICypressClient::Get
  40. virtual ::NThreading::TFuture<TNode> Get(
  41. const TYPath& path,
  42. const TGetOptions& options = TGetOptions()) = 0;
  43. ///
  44. /// @brief Set cypress node.
  45. ///
  46. /// @see NYT::ICypressClient::Set
  47. virtual ::NThreading::TFuture<void> Set(
  48. const TYPath& path,
  49. const TNode& node,
  50. const TSetOptions& options = TSetOptions()) = 0;
  51. ///
  52. /// @brief List cypress directory.
  53. ///
  54. /// @see NYT::ICypressClient::List
  55. virtual ::NThreading::TFuture<TNode::TListType> List(
  56. const TYPath& path,
  57. const TListOptions& options = TListOptions()) = 0;
  58. ///
  59. /// @brief Copy cypress node.
  60. ///
  61. /// @see NYT::ICypressClient::Copy
  62. virtual ::NThreading::TFuture<TNodeId> Copy(
  63. const TYPath& sourcePath,
  64. const TYPath& destinationPath,
  65. const TCopyOptions& options = TCopyOptions()) = 0;
  66. ///
  67. /// @brief Move cypress node.
  68. ///
  69. /// @see NYT::ICypressClient::Move
  70. virtual ::NThreading::TFuture<TNodeId> Move(
  71. const TYPath& sourcePath,
  72. const TYPath& destinationPath,
  73. const TMoveOptions& options = TMoveOptions()) = 0;
  74. ///
  75. /// @brief Create symbolic link.
  76. ///
  77. /// @see NYT::ICypressClient::Link.
  78. virtual ::NThreading::TFuture<TNodeId> Link(
  79. const TYPath& targetPath,
  80. const TYPath& linkPath,
  81. const TLinkOptions& options = TLinkOptions()) = 0;
  82. ///
  83. /// @brief Lock cypress node.
  84. ///
  85. /// @see NYT::ICypressClient::Lock
  86. virtual ::NThreading::TFuture<ILockPtr> Lock(
  87. const TYPath& path,
  88. ELockMode mode,
  89. const TLockOptions& options = TLockOptions()) = 0;
  90. ///
  91. /// @brief Unlock cypress node.
  92. ///
  93. /// @see NYT::ICypressClient::Unlock
  94. virtual ::NThreading::TFuture<void> Unlock(
  95. const TYPath& path,
  96. const TUnlockOptions& options = TUnlockOptions()) = 0;
  97. ///
  98. /// @brief Abort operation.
  99. ///
  100. /// @see NYT::IClient::AbortOperation
  101. virtual ::NThreading::TFuture<void> AbortOperation(const TOperationId& operationId) = 0;
  102. ///
  103. /// @brief Force complete operation.
  104. ///
  105. /// @see NYT::IClient::CompleteOperation
  106. virtual ::NThreading::TFuture<void> CompleteOperation(const TOperationId& operationId) = 0;
  107. ///
  108. /// @brief Suspend operation.
  109. ///
  110. /// @see NYT::IClient::SuspendOperation
  111. virtual ::NThreading::TFuture<void> SuspendOperation(
  112. const TOperationId& operationId,
  113. const TSuspendOperationOptions& options = TSuspendOperationOptions()) = 0;
  114. ///
  115. /// @brief Resume operation.
  116. ///
  117. /// @see NYT::IClient::ResumeOperation
  118. virtual ::NThreading::TFuture<void> ResumeOperation(
  119. const TOperationId& operationId,
  120. const TResumeOperationOptions& options = TResumeOperationOptions()) = 0;
  121. ///
  122. /// @brief Update parameters of running operation.
  123. ///
  124. /// @see NYT::IClient::UpdateOperationParameters
  125. virtual ::NThreading::TFuture<void> UpdateOperationParameters(
  126. const TOperationId& operationId,
  127. const TUpdateOperationParametersOptions& options = TUpdateOperationParametersOptions()) = 0;
  128. ///
  129. /// @brief Canonize cypress path
  130. ///
  131. /// @see NYT::ICypressClient::CanonizeYPath
  132. virtual ::NThreading::TFuture<TRichYPath> CanonizeYPath(const TRichYPath& path) = 0;
  133. ///
  134. /// @brief Get table columnar statistic
  135. ///
  136. /// @see NYT::ICypressClient::GetTableColumnarStatistics
  137. virtual ::NThreading::TFuture<TVector<TTableColumnarStatistics>> GetTableColumnarStatistics(
  138. const TVector<TRichYPath>& paths,
  139. const TGetTableColumnarStatisticsOptions& options = {}) = 0;
  140. ///
  141. /// @brief Check permission for given path.
  142. ///
  143. /// @see NYT::IClient::CheckPermission
  144. virtual ::NThreading::TFuture<TCheckPermissionResponse> CheckPermission(
  145. const TString& user,
  146. EPermission permission,
  147. const TYPath& path,
  148. const TCheckPermissionOptions& options = TCheckPermissionOptions()) = 0;
  149. };
  150. ///
  151. /// @brief Batch request object.
  152. ///
  153. /// Allows to send multiple lightweight requests at once significantly
  154. /// reducing time of their execution.
  155. ///
  156. /// Methods of this class accept same arguments as @ref NYT::IClient methods but
  157. /// return TFuture that is set after execution of @ref NYT::IBatchRequest::ExecuteBatch
  158. ///
  159. /// @see [Example of usage](https://a.yandex-team.ru/arc/trunk/arcadia/yt/cpp/mapreduce/examples/tutorial/batch_request/main.cpp)
  160. class IBatchRequest
  161. : public IBatchRequestBase
  162. {
  163. public:
  164. ///
  165. /// @brief Temporary override current transaction.
  166. ///
  167. /// Using WithTransaction user can temporary override default transaction.
  168. /// Example of usage:
  169. /// TBatchRequest batchRequest;
  170. /// auto noTxResult = batchRequest.Get("//some/path");
  171. /// auto txResult = batchRequest.WithTransaction(tx).Get("//some/path");
  172. virtual IBatchRequestBase& WithTransaction(const TTransactionId& transactionId) = 0;
  173. IBatchRequestBase& WithTransaction(const ITransactionPtr& transaction);
  174. ///
  175. /// @brief Executes all subrequests of batch request.
  176. ///
  177. /// After execution of this method all TFuture objects returned by subrequests will
  178. /// be filled with either result or error.
  179. ///
  180. /// @note It is undefined in which order these requests are executed.
  181. ///
  182. /// @note This method doesn't throw if subrequest emits error.
  183. /// Instead corresponding future is set with exception.
  184. /// So it is always important to check TFuture status.
  185. ///
  186. /// Single TBatchRequest instance may be executed only once
  187. /// and cannot be modified (filled with additional requests) after execution.
  188. /// Exception is thrown on attempt to modify executed batch request
  189. /// or execute it again.
  190. virtual void ExecuteBatch(const TExecuteBatchOptions& options = TExecuteBatchOptions()) = 0;
  191. };
  192. ////////////////////////////////////////////////////////////////////
  193. } // namespace NYT