Skip to content

Commit 0fddef1

Browse files
dont reallocate memory after merge through incorrect memory consumpti… (#12623)
1 parent b40adfb commit 0fddef1

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ std::unique_ptr<NArrow::NMerger::TMergePartialStream> TSpecialReadContext::Build
1313
ui64 TSpecialReadContext::GetMemoryForSources(const THashMap<ui32, std::shared_ptr<IDataSource>>& sources) {
1414
ui64 result = 0;
1515
for (auto&& i : sources) {
16-
auto fetchingPlan = GetColumnsFetchingPlan(i.second);
1716
AFL_VERIFY(i.second->GetIntervalsCount());
1817
const ui64 sourceMemory = std::max<ui64>(1, i.second->GetResourceGuardsMemory() / i.second->GetIntervalsCount());
1918
result += sourceMemory;

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

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ TConclusion<bool> TAllocateMemoryStep::DoExecuteInplace(const std::shared_ptr<ID
222222
}
223223
size += sizeLocal;
224224
}
225+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "TAllocateMemoryStep::DoExecuteInplace")("source", source->GetSourceIdx())("memory", size);
225226

226227
auto allocation = std::make_shared<TFetchingStepAllocation>(source, size, step, StageIndex);
227228
NGroupedMemoryManager::TScanMemoryLimiterOperator::SendToAllocation(source->GetContext()->GetProcessMemoryControlId(),

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ void TFetchingInterval::ConstructResult() {
1010
if (ready != WaitSourcesCount) {
1111
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "skip_construct_result")("interval_idx", IntervalIdx)(
1212
"count", WaitSourcesCount)("ready", ready)("interval_id", GetIntervalId());
13-
return;
14-
} else {
15-
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "start_construct_result")("interval_idx", IntervalIdx)(
16-
"interval_id", GetIntervalId());
17-
}
18-
if (AtomicCas(&SourcesFinalized, 1, 0)) {
13+
} else if (AtomicCas(&SourcesFinalized, 1, 0)) {
1914
IntervalStateGuard.SetStatus(NColumnShard::TScanCounters::EIntervalStatus::WaitMergerStart);
2015

2116
MergingContext->SetIntervalChunkMemory(Context->GetMemoryForSources(Sources));
17+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "start_construct_result")("interval_idx", IntervalIdx)(
18+
"interval_id", GetIntervalId())("memory", MergingContext->GetIntervalChunkMemory())("count", WaitSourcesCount);
2219

2320
auto task = std::make_shared<TStartMergeTask>(MergingContext, Context, std::move(Sources));
2421
task->SetPriority(NConveyor::ITask::EPriority::High);
@@ -81,6 +78,8 @@ void TFetchingInterval::OnPartSendingComplete() {
8178
}
8279
IntervalStateGuard.SetStatus(NColumnShard::TScanCounters::EIntervalStatus::WaitMergerContinue);
8380

81+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "continue_construct_result")("interval_idx", IntervalIdx)(
82+
"interval_id", GetIntervalId())("memory", MergingContext->GetIntervalChunkMemory())("count", WaitSourcesCount);
8483
auto task = std::make_shared<TContinueMergeTask>(MergingContext, Context, std::move(Merger));
8584
task->SetPriority(NConveyor::ITask::EPriority::High);
8685
NGroupedMemoryManager::TScanMemoryLimiterOperator::SendToAllocation(Context->GetProcessMemoryControlId(),

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ void TBaseMergeTask::PrepareResultBatch() {
3333
LastPK = nullptr;
3434
return;
3535
}
36+
const ui64 dataSizeBefore = NArrow::GetTableDataSize(ResultBatch);
37+
const ui64 memorySizeBefore = NArrow::GetTableMemorySize(ResultBatch);
3638
{
3739
ResultBatch = NArrow::TColumnOperator().VerifyIfAbsent().Extract(ResultBatch, Context->GetProgramInputColumns()->GetColumnNamesVector());
3840
AFL_VERIFY((ui32)ResultBatch->num_columns() == Context->GetProgramInputColumns()->GetColumnNamesVector().size());
@@ -45,7 +47,10 @@ void TBaseMergeTask::PrepareResultBatch() {
4547
} else {
4648
ShardedBatch = NArrow::TShardedRecordBatch(ResultBatch);
4749
}
48-
AllocationGuard->Update(NArrow::GetTableMemorySize(ResultBatch));
50+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "update_memory_merger")("before_data", dataSizeBefore)(
51+
"before_memory", memorySizeBefore)("after_memory", NArrow::GetTableMemorySize(ResultBatch))(
52+
"after_data", NArrow::GetTableDataSize(ResultBatch))("guard", AllocationGuard->GetMemory());
53+
// AllocationGuard->Update(NArrow::GetTableMemorySize(ResultBatch));
4954
AFL_VERIFY(!!LastPK == !!ShardedBatch->GetRecordsCount())("lpk", !!LastPK)("sb", ShardedBatch->GetRecordsCount());
5055
} else {
5156
AllocationGuard = nullptr;

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

+7
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ class TStageFeatures {
129129
Waiting.Sub(volume);
130130
if (HardLimit < Usage.Val() + volume) {
131131
Counters->OnCannotAllocate();
132+
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "cannot_allocate")("limit", HardLimit)(
133+
"usage", Usage.Val())(
134+
"delta", volume);
132135
return TConclusionStatus::Fail(TStringBuilder() << Name << "::(limit:" << HardLimit << ";val:" << Usage.Val() << ";delta=" << volume << ");");
133136
}
134137
Usage.Add(volume);
138+
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "allocate")("usage", Usage.Val())("delta", volume);
135139
if (Counters) {
136140
Counters->Add(volume, true);
137141
Counters->Sub(volume, false);
@@ -155,6 +159,7 @@ class TStageFeatures {
155159
} else {
156160
Waiting.Sub(volume);
157161
}
162+
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "free")("usage", Usage.Val())("delta", volume);
158163

159164
if (withOwner && Owner) {
160165
Owner->Free(volume, allocated);
@@ -166,6 +171,8 @@ class TStageFeatures {
166171
Counters->Sub(from, allocated);
167172
Counters->Add(to, allocated);
168173
}
174+
AFL_DEBUG(NKikimrServices::GROUPED_MEMORY_LIMITER)("name", Name)("event", "update")("usage", Usage.Val())("waiting", Waiting.Val())(
175+
"allocated", allocated)("from", from)("to", to);
169176
if (allocated) {
170177
Usage.Sub(from);
171178
Usage.Add(to);

0 commit comments

Comments
 (0)