Skip to content

Commit a2c6b53

Browse files
committed
Polish
1 parent 862eeac commit a2c6b53

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

ydb/library/yql/providers/dq/actors/result_actor_base.h

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,63 @@
1616

1717
namespace NYql::NDqs::NExecutionHelpers {
1818

19+
struct TQueueItem {
20+
TQueueItem(NDq::TDqSerializedBatch&& data, const TString& messageId)
21+
: Data(std::move(data))
22+
, MessageId(messageId)
23+
, SentProcessedEvent(false)
24+
, IsFinal(false)
25+
, Size(Data.Size())
26+
{
27+
}
28+
29+
static TQueueItem Final() {
30+
TQueueItem item({}, "FinalMessage");
31+
item.SentProcessedEvent = true;
32+
item.IsFinal = true;
33+
return item;
34+
}
35+
36+
NDq::TDqSerializedBatch Data;
37+
const TString MessageId;
38+
bool SentProcessedEvent = false;
39+
bool IsFinal = false;
40+
ui64 Size = 0;
41+
};
42+
43+
struct TWriteQueue {
44+
TQueue<TQueueItem> Queue;
45+
ui64 ByteSize = 0;
46+
47+
template< class... Args >
48+
decltype(auto) emplace( Args&&... args) {
49+
Queue.emplace(std::forward<Args>(args)...);
50+
ByteSize += Queue.back().Size;
51+
}
52+
53+
auto& front() {
54+
return Queue.front();
55+
}
56+
57+
auto& back() {
58+
return Queue.back();
59+
}
60+
61+
auto pop() {
62+
ByteSize -= Queue.front().Size;
63+
return Queue.pop();
64+
}
65+
66+
auto empty() const {
67+
return Queue.empty();
68+
}
69+
70+
void clear() {
71+
Queue.clear();
72+
ByteSize = 0;
73+
}
74+
};
75+
1976
template <class TDerived>
2077
class TResultActorBase : public NYql::TSynchronizableRichActor<TDerived>, public NYql::TCounters {
2178
protected:
@@ -76,7 +133,6 @@ namespace NYql::NDqs::NExecutionHelpers {
76133
}
77134

78135
WriteQueue.emplace(std::move(data), messageId);
79-
InflightBytes += WriteQueue.back().Size;
80136
if (FullResultTableEnabled && FullResultWriterID) {
81137
TryWriteToFullResultTable();
82138
} else {
@@ -181,6 +237,10 @@ namespace NYql::NDqs::NExecutionHelpers {
181237
}
182238
}
183239

240+
ui64 InflightBytes() {
241+
return WriteQueue.ByteSize;
242+
}
243+
184244
private:
185245
void OnQueryResult(TEvQueryResponse::TPtr& ev, const NActors::TActorContext&) {
186246
YQL_LOG_CTX_ROOT_SESSION_SCOPE(TraceId);
@@ -215,7 +275,6 @@ namespace NYql::NDqs::NExecutionHelpers {
215275
} else {
216276
WaitingAckFromFRW = false;
217277
WriteQueue.clear();
218-
InflightBytes = 0;
219278
Y_ABORT_UNLESS(ev->Get()->Record.GetStatusCode() != NYql::NDqProto::StatusIds::SUCCESS);
220279
TBase::Send(ExecuterID, ev->Release().Release());
221280
}
@@ -236,7 +295,6 @@ namespace NYql::NDqs::NExecutionHelpers {
236295
if (!WriteQueue.front().SentProcessedEvent) { // messages, received before limits exceeded, are already been reported
237296
TBase::Send(TBase::SelfId(), MakeHolder<TEvMessageProcessed>(WriteQueue.front().MessageId));
238297
}
239-
InflightBytes -= WriteQueue.back().Size;
240298
WriteQueue.pop();
241299

242300
if (WriteQueue.empty()) {
@@ -352,44 +410,18 @@ namespace NYql::NDqs::NExecutionHelpers {
352410
TBase::Send(FullResultWriterID, std::move(req));
353411
}
354412

355-
private:
356-
struct TQueueItem {
357-
TQueueItem(NDq::TDqSerializedBatch&& data, const TString& messageId)
358-
: Data(std::move(data))
359-
, MessageId(messageId)
360-
, SentProcessedEvent(false)
361-
, IsFinal(false)
362-
, Size(Data.Size())
363-
{
364-
}
365-
366-
static TQueueItem Final() {
367-
TQueueItem item({}, "FinalMessage");
368-
item.SentProcessedEvent = true;
369-
item.IsFinal = true;
370-
return item;
371-
}
372-
373-
NDq::TDqSerializedBatch Data;
374-
const TString MessageId;
375-
bool SentProcessedEvent = false;
376-
bool IsFinal = false;
377-
ui64 Size = 0;
378-
};
379-
380413
protected:
381414
const NActors::TActorId ExecuterID;
382415
const TString TraceId;
383416
TDqConfiguration::TPtr Settings;
384417
bool FinishCalled;
385418
bool EarlyFinish;
386-
ui64 InflightBytes = 0;
387419

388420
private:
389421
const bool FullResultTableEnabled;
390422
const NActors::TActorId GraphExecutionEventsId;
391423
const bool Discard;
392-
TQueue<TQueueItem> WriteQueue;
424+
TWriteQueue WriteQueue;
393425
ui64 SizeLimit;
394426
TMaybe<ui64> RowsLimit;
395427
ui64 Rows;

ydb/library/yql/providers/dq/actors/result_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TResultReceiver: public NYql::NDqs::NExecutionHelpers::TResultActorBase<TR
103103
auto req = MakeHolder<NDq::TEvDqCompute::TEvChannelDataAck>();
104104
req->Record.SetChannelId(message->Get()->Record.GetChannelData().GetChannelId());
105105
req->Record.SetSeqNo(message->Get()->Record.GetSeqNo());
106-
req->Record.SetFreeSpace(256_MB - InflightBytes);
106+
req->Record.SetFreeSpace(256_MB - InflightBytes());
107107
req->Record.SetFinish(EarlyFinish); // set if premature finish started (when response limit reached and FullResultTable not enabled)
108108

109109
Send(message->Sender, req.Release());

0 commit comments

Comments
 (0)