raw_batch_request.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #pragma once
  2. #include <yt/cpp/mapreduce/common/fwd.h>
  3. #include <yt/cpp/mapreduce/interface/batch_request.h>
  4. #include <yt/cpp/mapreduce/interface/fwd.h>
  5. #include <yt/cpp/mapreduce/interface/node.h>
  6. #include <yt/cpp/mapreduce/interface/retry_policy.h>
  7. #include <yt/cpp/mapreduce/http/requests.h>
  8. #include <library/cpp/threading/future/future.h>
  9. #include <util/generic/ptr.h>
  10. #include <util/generic/deque.h>
  11. #include <exception>
  12. namespace NYT::NDetail {
  13. struct TResponseInfo;
  14. }
  15. namespace NYT::NDetail::NRawClient {
  16. ////////////////////////////////////////////////////////////////////////////////
  17. class TRawBatchRequest
  18. : public TThrRefBase
  19. {
  20. public:
  21. struct IResponseItemParser
  22. : public TThrRefBase
  23. {
  24. ~IResponseItemParser() = default;
  25. virtual void SetResponse(TMaybe<TNode> node) = 0;
  26. virtual void SetException(std::exception_ptr e) = 0;
  27. };
  28. public:
  29. TRawBatchRequest(const TConfigPtr& config);
  30. ~TRawBatchRequest();
  31. bool IsExecuted() const;
  32. void MarkExecuted();
  33. void FillParameterList(size_t maxSize, TNode* result, TInstant* nextTry) const;
  34. size_t BatchSize() const;
  35. void ParseResponse(
  36. const TResponseInfo& requestResult,
  37. const IRequestRetryPolicyPtr& retryPolicy,
  38. TRawBatchRequest* retryBatch,
  39. TInstant now = TInstant::Now());
  40. void ParseResponse(
  41. TNode response,
  42. const TString& requestId,
  43. const IRequestRetryPolicyPtr& retryPolicy,
  44. TRawBatchRequest* retryBatch,
  45. TInstant now = TInstant::Now());
  46. void SetErrorResult(std::exception_ptr e) const;
  47. ::NThreading::TFuture<TNodeId> Create(
  48. const TTransactionId& transaction,
  49. const TYPath& path,
  50. ENodeType type,
  51. const TCreateOptions& options);
  52. ::NThreading::TFuture<void> Remove(
  53. const TTransactionId& transaction,
  54. const TYPath& path,
  55. const TRemoveOptions& options);
  56. ::NThreading::TFuture<bool> Exists(
  57. const TTransactionId& transaction,
  58. const TYPath& path,
  59. const TExistsOptions& options);
  60. ::NThreading::TFuture<TNode> Get(
  61. const TTransactionId& transaction,
  62. const TYPath& path,
  63. const TGetOptions& options);
  64. ::NThreading::TFuture<void> Set(
  65. const TTransactionId& transaction,
  66. const TYPath& path,
  67. const TNode& value,
  68. const TSetOptions& options);
  69. ::NThreading::TFuture<TNode::TListType> List(
  70. const TTransactionId& transaction,
  71. const TYPath& path,
  72. const TListOptions& options);
  73. ::NThreading::TFuture<TNodeId> Copy(
  74. const TTransactionId& transaction,
  75. const TYPath& sourcePath,
  76. const TYPath& destinationPath,
  77. const TCopyOptions& options);
  78. ::NThreading::TFuture<TNodeId> Move(
  79. const TTransactionId& transaction,
  80. const TYPath& sourcePath,
  81. const TYPath& destinationPath,
  82. const TMoveOptions& options);
  83. ::NThreading::TFuture<TNodeId> Link(
  84. const TTransactionId& transaction,
  85. const TYPath& targetPath,
  86. const TYPath& linkPath,
  87. const TLinkOptions& options);
  88. ::NThreading::TFuture<TLockId> Lock(
  89. const TTransactionId& transaction,
  90. const TYPath& path,
  91. ELockMode mode,
  92. const TLockOptions& options);
  93. ::NThreading::TFuture<void> Unlock(
  94. const TTransactionId& transaction,
  95. const TYPath& path,
  96. const TUnlockOptions& options);
  97. ::NThreading::TFuture<TMaybe<TYPath>> GetFileFromCache(
  98. const TTransactionId& transactionId,
  99. const TString& md5Signature,
  100. const TYPath& cachePath,
  101. const TGetFileFromCacheOptions& options);
  102. ::NThreading::TFuture<TYPath> PutFileToCache(
  103. const TTransactionId& transactionId,
  104. const TYPath& filePath,
  105. const TString& md5Signature,
  106. const TYPath& cachePath,
  107. const TPutFileToCacheOptions& options);
  108. ::NThreading::TFuture<TCheckPermissionResponse> CheckPermission(
  109. const TString& user,
  110. EPermission permission,
  111. const TYPath& path,
  112. const TCheckPermissionOptions& options);
  113. ::NThreading::TFuture<TOperationAttributes> GetOperation(
  114. const TOperationId& operationId,
  115. const TGetOperationOptions& options);
  116. ::NThreading::TFuture<void> AbortOperation(const TOperationId& operationId);
  117. ::NThreading::TFuture<void> CompleteOperation(const TOperationId& operationId);
  118. ::NThreading::TFuture<void> SuspendOperation(
  119. const TOperationId& operationId,
  120. const TSuspendOperationOptions& options);
  121. ::NThreading::TFuture<void> ResumeOperation(
  122. const TOperationId& operationId,
  123. const TResumeOperationOptions& options);
  124. ::NThreading::TFuture<void> UpdateOperationParameters(
  125. const TOperationId& operationId,
  126. const TUpdateOperationParametersOptions& options);
  127. ::NThreading::TFuture<TRichYPath> CanonizeYPath(const TRichYPath& path);
  128. ::NThreading::TFuture<TVector<TTableColumnarStatistics>> GetTableColumnarStatistics(
  129. const TTransactionId& transaction,
  130. const TVector<TRichYPath>& paths,
  131. const TGetTableColumnarStatisticsOptions& options);
  132. ::NThreading::TFuture<TMultiTablePartitions> GetTablePartitions(
  133. const TTransactionId& transaction,
  134. const TVector<TRichYPath>& paths,
  135. const TGetTablePartitionsOptions& options);
  136. private:
  137. struct TBatchItem {
  138. TNode Parameters;
  139. ::TIntrusivePtr<IResponseItemParser> ResponseParser;
  140. TInstant NextTry;
  141. TBatchItem(TNode parameters, ::TIntrusivePtr<IResponseItemParser> responseParser);
  142. TBatchItem(const TBatchItem& batchItem, TInstant nextTry);
  143. };
  144. private:
  145. template <typename TResponseParser>
  146. typename TResponseParser::TFutureResult AddRequest(
  147. const TString& command,
  148. TNode parameters,
  149. TMaybe<TNode> input);
  150. template <typename TResponseParser>
  151. typename TResponseParser::TFutureResult AddRequest(
  152. const TString& command,
  153. TNode parameters,
  154. TMaybe<TNode> input,
  155. ::TIntrusivePtr<TResponseParser> parser);
  156. void AddRequest(TBatchItem batchItem);
  157. private:
  158. TConfigPtr Config_;
  159. TDeque<TBatchItem> BatchItemList_;
  160. bool Executed_ = false;
  161. };
  162. ////////////////////////////////////////////////////////////////////////////////
  163. } // namespace NYT::NDetail::NRawClient