progress_merger.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "progress_merger.h"
  2. namespace NYql::NProgressMerger {
  3. //////////////////////////////////////////////////////////////////////////////
  4. // TNodeProgressBase
  5. //////////////////////////////////////////////////////////////////////////////
  6. TNodeProgressBase::TNodeProgressBase(const TOperationProgress& p)
  7. : Progress_(p)
  8. , StartedAt_(TInstant::Now())
  9. , FinishedAt_(p.State == EState::Finished ? StartedAt_ : TInstant::Max())
  10. , Dirty_(true)
  11. {
  12. if (!p.Stage.first.empty()) {
  13. Stages_.emplace_back(p.Stage);
  14. }
  15. }
  16. TNodeProgressBase::TNodeProgressBase(
  17. const TOperationProgress& p,
  18. TInstant startedAt,
  19. TInstant finishedAt,
  20. const TVector<TOperationProgress::TStage>& stages)
  21. : Progress_(p)
  22. , StartedAt_(startedAt)
  23. , FinishedAt_(finishedAt)
  24. , Stages_(stages)
  25. , Dirty_(true)
  26. {}
  27. bool TNodeProgressBase::MergeWith(const TOperationProgress& p) {
  28. bool dirty = false;
  29. // (1) remote id
  30. if (!p.RemoteId.empty() && p.RemoteId != Progress_.RemoteId) {
  31. Progress_.RemoteId = p.RemoteId;
  32. dirty = true;
  33. }
  34. // (2) state
  35. if (p.State != Progress_.State) {
  36. Progress_.State = p.State;
  37. dirty = true;
  38. }
  39. // (3) counters
  40. if (p.Counters && (!Progress_.Counters || *p.Counters != *Progress_.Counters)) {
  41. Progress_.Counters = p.Counters;
  42. dirty = true;
  43. }
  44. // (4) finished time
  45. if (Progress_.State == EState::Finished) {
  46. FinishedAt_ = TInstant::Now();
  47. dirty = true;
  48. }
  49. // (5) stage
  50. if (!p.Stage.first.empty() && Progress_.Stage != p.Stage) {
  51. Progress_.Stage = p.Stage;
  52. Stages_.push_back(p.Stage);
  53. dirty = true;
  54. }
  55. // (6) remote data
  56. if (!p.RemoteData.empty() && p.RemoteData != Progress_.RemoteData) {
  57. Progress_.RemoteData = p.RemoteData;
  58. dirty = true;
  59. }
  60. return Dirty_ = dirty;
  61. }
  62. void TNodeProgressBase::Abort() {
  63. Progress_.State = EState::Aborted;
  64. FinishedAt_ = TInstant::Now();
  65. Dirty_ = true;
  66. }
  67. bool TNodeProgressBase::IsUnfinished() const {
  68. return Progress_.State == EState::Started ||
  69. Progress_.State == EState::InProgress;
  70. }
  71. bool TNodeProgressBase::IsDirty() const {
  72. return Dirty_;
  73. }
  74. void TNodeProgressBase::SetDirty(bool dirty) {
  75. Dirty_ = dirty;
  76. }
  77. } // namespace NYql::NProgressMerger