retry_heavy_write_request.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <yt/cpp/mapreduce/client/transaction.h>
  3. #include <yt/cpp/mapreduce/common/fwd.h>
  4. #include <yt/cpp/mapreduce/http/context.h>
  5. #include <yt/cpp/mapreduce/http/requests.h>
  6. namespace NYT {
  7. ///////////////////////////////////////////////////////////////////////////////
  8. class THeavyRequestRetrier
  9. {
  10. public:
  11. struct TParameters
  12. {
  13. IClientRetryPolicyPtr ClientRetryPolicy;
  14. ITransactionPingerPtr TransactionPinger;
  15. TClientContext Context;
  16. TTransactionId TransactionId;
  17. THttpHeader Header;
  18. };
  19. using TStreamFactory = std::function<THolder<IInputStream>()>;
  20. public:
  21. explicit THeavyRequestRetrier(TParameters parameters);
  22. ~THeavyRequestRetrier();
  23. void Update(TStreamFactory streamFactory);
  24. void Finish();
  25. private:
  26. void Retry(const std::function<void()>& function);
  27. void TryStartAttempt();
  28. private:
  29. const TParameters Parameters_;
  30. const IRequestRetryPolicyPtr RequestRetryPolicy_;
  31. struct TAttempt
  32. {
  33. std::unique_ptr<TPingableTransaction> Transaction;
  34. TString RequestId;
  35. NHttpClient::IHttpRequestPtr Request;
  36. ssize_t Offset = 0;
  37. };
  38. std::unique_ptr<TAttempt> Attempt_;
  39. TStreamFactory StreamFactory_;
  40. };
  41. ///////////////////////////////////////////////////////////////////////////////
  42. void RetryHeavyWriteRequest(
  43. const IClientRetryPolicyPtr& clientRetryPolicy,
  44. const ITransactionPingerPtr& transactionPinger,
  45. const TClientContext& context,
  46. const TTransactionId& parentId,
  47. THttpHeader& header,
  48. std::function<THolder<IInputStream>()> streamMaker);
  49. ////////////////////////////////////////////////////////////////////////////////
  50. } // namespace NYT