Skip to content

Commit a63cf9a

Browse files
committed
void -> bool
1 parent 66380f6 commit a63cf9a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

ydb/library/yql/dq/actors/compute/dq_sync_compute_actor_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class TDqSyncComputeActorBase: public TDqComputeActorBase<TDerived, TComputeActo
236236
if (this->Task.GetEnableSpilling()) {
237237
TaskRunner->SetSpillerFactory(std::make_shared<TDqSpillerFactory>(execCtx.GetTxId(), NActors::TActivationContext::ActorSystem(), execCtx.GetWakeupCallback(), execCtx.GetErrorCallback()));
238238
TaskRunner->SetMemoryUsageReporter(std::make_shared<NKikimr::NMiniKQL::TMemoryUsageReporter>(
239-
[this](ui64 bytes){ this->MemoryLimits.MemoryQuotaManager->AllocateQuota(bytes); },
239+
[this](ui64 bytes){ return this->MemoryLimits.MemoryQuotaManager->AllocateQuota(bytes); },
240240
[this](ui64 bytes){ this->MemoryLimits.MemoryQuotaManager->FreeQuota(bytes); }
241241
));
242242
}

yql/essentials/minikql/computation/mkql_memory_usage_reporter.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ namespace NKikimr::NMiniKQL {
1010

1111
class TMemoryUsageReporter {
1212
public:
13-
using TReportCallback = std::function<void(ui64)>;
13+
using TAllocateReportCallback = std::function<bool(ui64)>;
14+
using TFreeReportCallback = std::function<void(ui64)>;
1415
using TPtr = std::shared_ptr<TMemoryUsageReporter>;
1516
public:
16-
TMemoryUsageReporter(TReportCallback reportAllocateCallback, TReportCallback reportFreeCallback): ReportAllocateCallback_(reportAllocateCallback), ReportFreeCallback_(reportFreeCallback) {}
17+
TMemoryUsageReporter(TAllocateReportCallback reportAllocateCallback, TFreeReportCallback reportFreeCallback): ReportAllocateCallback_(reportAllocateCallback), ReportFreeCallback_(reportFreeCallback) {}
1718
void ReportAllocate(ui64 bytes) {
1819
// Cerr << "[MISHA][ALLOC]: " << bytes << ", Total: " << BytesAllocated_ << Endl;
1920
Y_ENSURE(ReportAllocateCallback_ != nullptr);
20-
ReportAllocateCallback_(bytes);
21-
BytesAllocated_ += bytes;
21+
if (ReportAllocateCallback_(bytes)) {
22+
BytesAllocated_ += bytes;
23+
}
2224
}
2325

2426
void ReportFree(ui64 bytes) {
2527
// Cerr << "[MISHA][FREE]: " << bytes << ", Total: " << BytesAllocated_ << Endl;
2628
Y_ENSURE(ReportFreeCallback_ != nullptr);
27-
ReportFreeCallback_(bytes);
28-
Y_ENSURE(BytesAllocated_ >= bytes, "Trying to free more bytes than allocated");
29-
BytesAllocated_ -= bytes;
29+
ui64 toFree = std::min(BytesAllocated_, bytes);
30+
if (toFree) {
31+
ReportFreeCallback_(bytes);
32+
}
33+
BytesAllocated_ -= toFree;
3034
}
3135

3236
~TMemoryUsageReporter() {
@@ -43,8 +47,8 @@ class TMemoryUsageReporter {
4347

4448
private:
4549
ui64 BytesAllocated_{0};
46-
TReportCallback ReportAllocateCallback_{nullptr};
47-
TReportCallback ReportFreeCallback_{nullptr};
50+
TAllocateReportCallback ReportAllocateCallback_{nullptr};
51+
TFreeReportCallback ReportFreeCallback_{nullptr};
4852
};
4953

5054
}//namespace NKikimr::NMiniKQL

0 commit comments

Comments
 (0)