Skip to content

Commit

Permalink
fix allocations manager limits control (#12622)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Dec 14, 2024
1 parent 50faeec commit b40adfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ydb/core/tx/limiter/grouped_memory/service/allocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ TAllocationInfo::TAllocationInfo(const ui64 processId, const ui64 scopeId, const
AFL_VERIFY(Allocation);
AFL_INFO(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "add")("id", Allocation->GetIdentifier())("stage", Stage->GetName());
AllocatedVolume = Allocation->GetMemory();
Stage->Add(AllocatedVolume, Allocation->IsAllocated());
if (allocation->IsAllocated()) {
AFL_INFO(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "allocated_on_add")("allocation_id", Identifier)("stage", Stage->GetName());
Allocation = nullptr;
}
Stage->Add(AllocatedVolume, GetAllocationStatus() == EAllocationStatus::Allocated);
}

} // namespace NKikimr::NOlap::NGroupedMemoryManager
3 changes: 2 additions & 1 deletion ydb/core/tx/limiter/grouped_memory/service/allocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounter<TAllocatio

public:
~TAllocationInfo() {
if (GetAllocationStatus() == EAllocationStatus::Allocated) {
if (GetAllocationStatus() != EAllocationStatus::Failed) {
Stage->Free(AllocatedVolume, GetAllocationStatus() == EAllocationStatus::Allocated);
}

Expand Down Expand Up @@ -52,6 +52,7 @@ class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounter<TAllocatio
if (allocationResult.IsFail()) {
AllocationFailed = true;
Allocation->OnAllocationImpossible(allocationResult.GetErrorMessage());
Allocation = nullptr;
return false;
}
const bool result = Allocation->OnAllocated(
Expand Down
12 changes: 6 additions & 6 deletions ydb/core/tx/limiter/grouped_memory/usage/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TPositiveControlInteger {
Value += value;
}
void Sub(const ui64 value) {
AFL_VERIFY(value <= Value);
AFL_VERIFY(value <= Value)("base", Value)("delta", value);
Value -= value;
}
ui64 Val() const {
Expand Down Expand Up @@ -126,11 +126,11 @@ class TStageFeatures {
}

[[nodiscard]] TConclusionStatus Allocate(const ui64 volume) {
Waiting.Sub(volume);
if (HardLimit < Usage.Val() + volume) {
Counters->OnCannotAllocate();
return TConclusionStatus::Fail(TStringBuilder() << "limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ";");
return TConclusionStatus::Fail(TStringBuilder() << Name << "::(limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ");");
}
Waiting.Sub(volume);
Usage.Add(volume);
if (Counters) {
Counters->Add(volume, true);
Expand All @@ -139,14 +139,14 @@ class TStageFeatures {
if (Owner) {
const auto ownerResult = Owner->Allocate(volume);
if (ownerResult.IsFail()) {
Free(volume, true);
Free(volume, true, false);
return ownerResult;
}
}
return TConclusionStatus::Success();
}

void Free(const ui64 volume, const bool allocated) {
void Free(const ui64 volume, const bool allocated, const bool withOwner = true) {
if (Counters) {
Counters->Sub(volume, allocated);
}
Expand All @@ -156,7 +156,7 @@ class TStageFeatures {
Waiting.Sub(volume);
}

if (Owner) {
if (withOwner && Owner) {
Owner->Free(volume, allocated);
}
}
Expand Down

0 comments on commit b40adfb

Please sign in to comment.