abortable_registry.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <yt/cpp/mapreduce/interface/common.h>
  3. #include <yt/cpp/mapreduce/http/context.h>
  4. #include <yt/cpp/mapreduce/raw_client/raw_requests.h>
  5. #include <util/str_stl.h>
  6. #include <util/system/mutex.h>
  7. #include <util/generic/hash.h>
  8. namespace NYT {
  9. namespace NDetail {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. class IAbortable
  12. : public TThrRefBase
  13. {
  14. public:
  15. virtual void Abort() = 0;
  16. virtual TString GetType() const = 0;
  17. };
  18. using IAbortablePtr = ::TIntrusivePtr<IAbortable>;
  19. ////////////////////////////////////////////////////////////////////////////////
  20. class TTransactionAbortable
  21. : public IAbortable
  22. {
  23. public:
  24. TTransactionAbortable(const TClientContext& context, const TTransactionId& transactionId);
  25. void Abort() override;
  26. TString GetType() const override;
  27. private:
  28. TClientContext Context_;
  29. TTransactionId TransactionId_;
  30. };
  31. ////////////////////////////////////////////////////////////////////////////////
  32. class TOperationAbortable
  33. : public IAbortable
  34. {
  35. public:
  36. TOperationAbortable(IClientRetryPolicyPtr clientRetryPolicy, TClientContext context, const TOperationId& operationId);
  37. void Abort() override;
  38. TString GetType() const override;
  39. private:
  40. const IClientRetryPolicyPtr ClientRetryPolicy_;
  41. const TClientContext Context_;
  42. const TOperationId OperationId_;
  43. };
  44. ////////////////////////////////////////////////////////////////////////////////
  45. class TAbortableRegistry
  46. : public TThrRefBase
  47. {
  48. public:
  49. TAbortableRegistry() = default;
  50. static ::TIntrusivePtr<TAbortableRegistry> Get();
  51. void AbortAllAndBlockForever();
  52. void Add(const TGUID& id, IAbortablePtr abortable);
  53. void Remove(const TGUID& id);
  54. private:
  55. THashMap<TGUID, IAbortablePtr> ActiveAbortables_;
  56. TMutex Lock_;
  57. bool Running_ = true;
  58. };
  59. ////////////////////////////////////////////////////////////////////////////////
  60. } // namespace NDetail
  61. } // namespace NYT