diff options
author | max42 <max42@yandex-team.com> | 2023-07-29 00:02:16 +0300 |
---|---|---|
committer | max42 <max42@yandex-team.com> | 2023-07-29 00:02:16 +0300 |
commit | 73b89de71748a21e102d27b9f3ed1bf658766cb5 (patch) | |
tree | 188bbd2d622fa91cdcbb1b6d6d77fbc84a0646f5 /yt/cpp/mapreduce/interface/job_counters.cpp | |
parent | 528e321bcc2a2b67b53aeba58c3bd88305a141ee (diff) | |
download | ydb-73b89de71748a21e102d27b9f3ed1bf658766cb5.tar.gz |
YT-19210: expose YQL shared library for YT.
After this, a new target libyqlplugin.so appears. in open-source cmake build.
Diff in open-source YDB repo looks like the following: https://paste.yandex-team.ru/f302bdb4-7ef2-4362-91c7-6ca45f329264
Diffstat (limited to 'yt/cpp/mapreduce/interface/job_counters.cpp')
-rw-r--r-- | yt/cpp/mapreduce/interface/job_counters.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/interface/job_counters.cpp b/yt/cpp/mapreduce/interface/job_counters.cpp new file mode 100644 index 0000000000..6d4a2a6fcb --- /dev/null +++ b/yt/cpp/mapreduce/interface/job_counters.cpp @@ -0,0 +1,164 @@ +#include "job_counters.h" + +namespace NYT { + +//////////////////////////////////////////////////////////////////// + +namespace { + ui64 CountTotal(const TNode& data) + { + if (data.IsMap()) { + if (auto totalPtr = data.AsMap().FindPtr("total")) { + return data["total"].IntCast<ui64>(); + } else { + ui64 total = 0; + for (const auto& keyVal: data.AsMap()) { + total += CountTotal(keyVal.second); + } + return total; + } + } else { + return data.IntCast<ui64>(); + } + } + + TNode GetNode(const TNode& data, const TStringBuf& key) + { + if (auto resPtr = data.AsMap().FindPtr(key)) { + return *resPtr; + } + return TNode(); + } +} // namespace + +//////////////////////////////////////////////////////////////////// + +TJobCounter::TJobCounter(TNode data) + : Data_(std::move(data)) +{ + if (Data_.HasValue()) { + Total_ = CountTotal(Data_); + } +} + +TJobCounter::TJobCounter(ui64 total) + : Total_(total) +{ } + +ui64 TJobCounter::GetTotal() const +{ + return Total_; +} + +ui64 TJobCounter::GetValue(const TStringBuf key) const +{ + if (Data_.HasValue()) { + return CountTotal(Data_[key]); + } + return 0; +} + +//////////////////////////////////////////////////////////////////// + +TJobCounters::TJobCounters(const NYT::TNode& counters) + : Total_(0) +{ + if (!counters.IsMap()) { + ythrow yexception() << "TJobCounters must be initialized with Map type TNode"; + } + auto abortedNode = GetNode(counters, "aborted"); + if (abortedNode.HasValue()) { + Aborted_ = TJobCounter(GetNode(abortedNode, "total")); + AbortedScheduled_ = TJobCounter(GetNode(abortedNode, "scheduled")); + AbortedNonScheduled_ = TJobCounter(GetNode(abortedNode, "non_scheduled")); + } + auto completedNode = GetNode(counters, "completed"); + if (completedNode.HasValue()) { + Completed_ = TJobCounter(GetNode(completedNode, "total")); + CompletedNonInterrupted_ = TJobCounter(GetNode(completedNode, "non-interrupted")); + CompletedInterrupted_ = TJobCounter(GetNode(completedNode, "interrupted")); + } + Lost_ = TJobCounter(GetNode(counters, "lost")); + Invalidated_ = TJobCounter(GetNode(counters, "invalidated")); + Failed_ = TJobCounter(GetNode(counters, "failed")); + Running_ = TJobCounter(GetNode(counters, "running")); + Suspended_ = TJobCounter(GetNode(counters, "suspended")); + Pending_ = TJobCounter(GetNode(counters, "pending")); + Blocked_ = TJobCounter(GetNode(counters, "blocked")); + Total_ = CountTotal(counters); +} + + +const TJobCounter& TJobCounters::GetAborted() const +{ + return Aborted_; +} + +const TJobCounter& TJobCounters::GetAbortedScheduled() const +{ + return AbortedScheduled_; +} + +const TJobCounter& TJobCounters::GetAbortedNonScheduled() const +{ + return AbortedNonScheduled_; +} + +const TJobCounter& TJobCounters::GetCompleted() const +{ + return Completed_; +} + +const TJobCounter& TJobCounters::GetCompletedNonInterrupted() const +{ + return CompletedNonInterrupted_; +} + +const TJobCounter& TJobCounters::GetCompletedInterrupted() const +{ + return CompletedInterrupted_; +} + +const TJobCounter& TJobCounters::GetLost() const +{ + return Lost_; +} + +const TJobCounter& TJobCounters::GetInvalidated() const +{ + return Invalidated_; +} + +const TJobCounter& TJobCounters::GetFailed() const +{ + return Failed_; +} + +const TJobCounter& TJobCounters::GetRunning() const +{ + return Running_; +} + +const TJobCounter& TJobCounters::GetSuspended() const +{ + return Suspended_; +} + +const TJobCounter& TJobCounters::GetPending() const +{ + return Pending_; +} + +const TJobCounter& TJobCounters::GetBlocked() const +{ + return Blocked_; +} + +ui64 TJobCounters::GetTotal() const +{ + return Total_; +} + +//////////////////////////////////////////////////////////////////// + +} // namespace NYT |