Skip to content

Commit d47fd48

Browse files
fix
1 parent 9f3569f commit d47fd48

File tree

11 files changed

+38
-21
lines changed

11 files changed

+38
-21
lines changed

ydb/core/protos/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ message TLimiterConfig {
634634
message TGroupedMemoryLimiterConfig {
635635
optional bool Enabled = 1 [default = true];
636636
optional uint64 MemoryLimit = 2;
637+
optional uint64 HardMemoryLimit = 3;
637638
}
638639

639640
message TExternalIndexConfig {

ydb/core/tx/columnshard/engines/reader/abstract/read_context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class TReadContext {
6464

6565
void AbortWithError(const TString& errorMessage) {
6666
if (AtomicCas(&AbortFlag, 1, 0)) {
67-
NActors::TActivationContext::Send(ScanActorId, std::make_unique<NColumnShard::TEvPrivate::TEvTaskProcessedResult>(errorMessage));
67+
NActors::TActivationContext::Send(
68+
ScanActorId, std::make_unique<NColumnShard::TEvPrivate::TEvTaskProcessedResult>(TConclusionStatus::Fail(errorMessage)));
6869
}
6970
}
7071

ydb/core/tx/columnshard/engines/reader/plain_reader/iterator/fetching.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ TAllocateMemoryStep::TFetchingStepAllocation::TFetchingStepAllocation(
189189
, TasksGuard(source->GetContext()->GetCommonContext()->GetCounters().GetResourcesAllocationTasksGuard()) {
190190
}
191191

192+
void TAllocateMemoryStep::TFetchingStepAllocation::DoOnAllocationImpossible(const TString& errorMessage) {
193+
auto sourcePtr = Source.lock();
194+
if (sourcePtr) {
195+
sourcePtr->GetContext()->GetCommonContext()->AbortWithError(
196+
"cannot allocate memory for step " + Step.GetName() + ": '" + errorMessage + "'");
197+
}
198+
}
199+
192200
TConclusion<bool> TAllocateMemoryStep::DoExecuteInplace(
193201
const std::shared_ptr<IDataSource>& source, const TFetchingScriptCursor& step) const {
194202

ydb/core/tx/columnshard/engines/reader/plain_reader/iterator/fetching.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ class TAllocateMemoryStep: public IFetchingStep {
237237
NColumnShard::TCounterGuard TasksGuard;
238238
virtual bool DoOnAllocated(std::shared_ptr<NGroupedMemoryManager::TAllocationGuard>&& guard,
239239
const std::shared_ptr<NGroupedMemoryManager::IAllocation>& allocation) override;
240-
virtual void DoOnAllocationImpossible(const TString& errorMessage) override {
241-
Source->GetContext()->GetCommonContext()->AbortWithError("cannot allocate memory for step " + Step.GetName() + ": '" + errorMessage + "'");
242-
}
240+
virtual void DoOnAllocationImpossible(const TString& errorMessage) override;
243241
public:
244242
TFetchingStepAllocation(const std::shared_ptr<IDataSource>& source, const ui64 mem, const TFetchingScriptCursor& step);
245243
};

ydb/core/tx/columnshard/engines/reader/sys_view/chunks/chunks.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,8 @@ TStatsIterator::TFetchingAccessorAllocation::TFetchingAccessorAllocation(
199199
, Context(context) {
200200
}
201201

202+
void TStatsIterator::TFetchingAccessorAllocation::DoOnAllocationImpossible(const TString& errorMessage) {
203+
Context->AbortWithError("cannot allocate memory for take accessors info: " + errorMessage);
204+
}
205+
202206
} // namespace NKikimr::NOlap::NReader::NSysView::NChunks

ydb/core/tx/columnshard/engines/reader/sys_view/chunks/chunks.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ class TStatsIterator: public NAbstract::TStatsIterator<NKikimr::NSysView::Schema
117117
AccessorsManager->AskData(std::move(Request));
118118
return true;
119119
}
120-
virtual void DoOnAllocationImpossible(const TString& errorMessage) override {
121-
Context->AbortWithError("cannot allocate memory for take accessors info: " + errorMessage);
122-
}
120+
virtual void DoOnAllocationImpossible(const TString& errorMessage) override;
123121

124122
virtual void DoOnRequestsFinished(TDataAccessorsResult&& result) override {
125123
if (result.HasErrors()) {

ydb/core/tx/limiter/grouped_memory/service/allocation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounter<TAllocatio
4848
AFL_TRACE(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "allocated")("allocation_id", Identifier)("stage", Stage->GetName());
4949
AFL_VERIFY(Allocation)("status", GetAllocationStatus())("volume", AllocatedVolume)("id", Identifier)("stage", Stage->GetName())(
5050
"allocation_internal_group_id", AllocationInternalGroupId);
51-
if (!Stage->Allocate(AllocatedVolume)) {
51+
auto allocationResult = Stage->Allocate(AllocatedVolume);
52+
if (allocationResult.IsFail()) {
5253
AllocationFailed = true;
53-
Allocation->OnAllocationImpossible();
54+
Allocation->OnAllocationImpossible(allocationResult.GetErrorMessage());
5455
return false;
5556
}
5657
const bool result = Allocation->OnAllocated(

ydb/core/tx/limiter/grouped_memory/usage/abstract.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ydb/library/actors/core/actor.h>
66
#include <ydb/library/actors/core/actorid.h>
77
#include <ydb/library/actors/core/log.h>
8+
#include <ydb/library/conclusion/status.h>
89

910
namespace NKikimr::NOlap::NGroupedMemoryManager {
1011

@@ -94,8 +95,8 @@ class TPositiveControlInteger {
9495
class TStageFeatures {
9596
private:
9697
YDB_READONLY_DEF(TString, Name);
97-
YDB_READONLY(ui64, HardLimit, 0);
9898
YDB_READONLY(ui64, Limit, 0);
99+
YDB_READONLY(ui64, HardLimit, 0);
99100
YDB_ACCESSOR_DEF(TPositiveControlInteger, Usage);
100101
YDB_ACCESSOR_DEF(TPositiveControlInteger, Waiting);
101102
std::shared_ptr<TStageFeatures> Owner;
@@ -124,9 +125,9 @@ class TStageFeatures {
124125
, Counters(counters) {
125126
}
126127

127-
[[nodiscard]] bool Allocate(const ui64 volume) {
128+
[[nodiscard]] TConclusionStatus Allocate(const ui64 volume) {
128129
if (HardLimit < Usage.Val() + volume) {
129-
return false;
130+
return TConclusionStatus::Fail(TStringBuilder() << "limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ";");
130131
}
131132
Waiting.Sub(volume);
132133
Usage.Add(volume);
@@ -135,12 +136,13 @@ class TStageFeatures {
135136
Counters->Sub(volume, false);
136137
}
137138
if (Owner) {
138-
if (!Owner->Allocate(volume)) {
139+
const auto ownerResult = Owner->Allocate(volume);
140+
if (ownerResult.IsFail()) {
139141
Free(volume, true);
140-
return false;
142+
return ownerResult;
141143
}
142144
}
143-
return true;
145+
return TConclusionStatus::Success();
144146
}
145147

146148
void Free(const ui64 volume, const bool allocated) {
@@ -208,7 +210,7 @@ class IAllocation {
208210
YDB_READONLY(ui64, Identifier, Counter.Inc());
209211
YDB_READONLY(ui64, Memory, 0);
210212
bool Allocated = false;
211-
virtual void DoOnAllocationImpossible() = 0;
213+
virtual void DoOnAllocationImpossible(const TString& errorMessage) = 0;
212214
virtual bool DoOnAllocated(
213215
std::shared_ptr<TAllocationGuard>&& guard, const std::shared_ptr<NGroupedMemoryManager::IAllocation>& allocation) = 0;
214216

@@ -226,8 +228,8 @@ class IAllocation {
226228
return Allocated;
227229
}
228230

229-
void OnAllocationImpossible() {
230-
DoOnAllocationImpossible();
231+
void OnAllocationImpossible(const TString& errorMessage) {
232+
DoOnAllocationImpossible(errorMessage);
231233
}
232234

233235
[[nodiscard]] bool OnAllocated(

ydb/core/tx/limiter/grouped_memory/usage/config.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ bool TConfig::DeserializeFromProto(const NKikimrConfig::TGroupedMemoryLimiterCon
77
if (config.HasMemoryLimit()) {
88
MemoryLimit = config.GetMemoryLimit();
99
}
10+
if (config.HasHardMemoryLimit()) {
11+
HardMemoryLimit = config.GetHardMemoryLimit();
12+
}
1013
Enabled = config.GetEnabled();
1114
return true;
1215
}
1316

1417
TString TConfig::DebugString() const {
1518
TStringBuilder sb;
16-
sb << "MemoryLimit=" << MemoryLimit << ";Enabled=" << Enabled << ";";
19+
sb << "MemoryLimit=" << MemoryLimit << ";HardMemoryLimit=" << HardMemoryLimit << ";Enabled=" << Enabled << ";";
1720
return sb;
1821
}
1922

ydb/core/tx/limiter/grouped_memory/usage/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TConfig {
88
private:
99
YDB_READONLY(bool, Enabled, true);
1010
YDB_READONLY(ui64, MemoryLimit, ui64(3) << 30);
11+
YDB_READONLY(ui64, HardMemoryLimit, ui64(10) << 30);
1112

1213
public:
1314

0 commit comments

Comments
 (0)