diff --git a/ydb/core/tx/limiter/grouped_memory/service/allocation.cpp b/ydb/core/tx/limiter/grouped_memory/service/allocation.cpp index 2d04be2c9cef..1dfe27953eb8 100644 --- a/ydb/core/tx/limiter/grouped_memory/service/allocation.cpp +++ b/ydb/core/tx/limiter/grouped_memory/service/allocation.cpp @@ -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 diff --git a/ydb/core/tx/limiter/grouped_memory/service/allocation.h b/ydb/core/tx/limiter/grouped_memory/service/allocation.h index 3edd6c97e0a1..14b7316ac760 100644 --- a/ydb/core/tx/limiter/grouped_memory/service/allocation.h +++ b/ydb/core/tx/limiter/grouped_memory/service/allocation.h @@ -23,7 +23,7 @@ class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounterFree(AllocatedVolume, GetAllocationStatus() == EAllocationStatus::Allocated); } @@ -52,6 +52,7 @@ class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounterOnAllocationImpossible(allocationResult.GetErrorMessage()); + Allocation = nullptr; return false; } const bool result = Allocation->OnAllocated( diff --git a/ydb/core/tx/limiter/grouped_memory/usage/abstract.h b/ydb/core/tx/limiter/grouped_memory/usage/abstract.h index b0b1b11dce83..43ef21bf0bcc 100644 --- a/ydb/core/tx/limiter/grouped_memory/usage/abstract.h +++ b/ydb/core/tx/limiter/grouped_memory/usage/abstract.h @@ -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 { @@ -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); @@ -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); } @@ -156,7 +156,7 @@ class TStageFeatures { Waiting.Sub(volume); } - if (Owner) { + if (withOwner && Owner) { Owner->Free(volume, allocated); } }