Skip to content

Commit 57ae447

Browse files
Fix allocation race to 24-3-9-cs (#10169)
Co-authored-by: ivanmorozov333 <[email protected]>
1 parent 374e145 commit 57ae447

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <ydb/core/tx/columnshard/counters/common/object_counter.h>
23
#include <ydb/core/tx/limiter/grouped_memory/usage/abstract.h>
34

45
namespace NKikimr::NOlap::NGroupedMemoryManager {
@@ -9,7 +10,7 @@ enum class EAllocationStatus {
910
Failed
1011
};
1112

12-
class TAllocationInfo {
13+
class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounter<TAllocationInfo> {
1314
private:
1415
std::shared_ptr<IAllocation> Allocation;
1516
YDB_READONLY(ui64, AllocationInternalGroupId, 0);
@@ -25,7 +26,7 @@ class TAllocationInfo {
2526
if (GetAllocationStatus() != EAllocationStatus::Failed) {
2627
Stage->Free(AllocatedVolume, GetAllocationStatus() == EAllocationStatus::Allocated);
2728
}
28-
29+
2930
AFL_TRACE(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "destroy")("allocation_id", Identifier)("stage", Stage->GetName());
3031
}
3132

@@ -69,8 +70,8 @@ class TAllocationInfo {
6970
}
7071
}
7172

72-
TAllocationInfo(const ui64 processId, const ui64 scopeId, const ui64 allocationInternalGroupId, const std::shared_ptr<IAllocation>& allocation,
73-
const std::shared_ptr<TStageFeatures>& stage);
73+
TAllocationInfo(const ui64 processId, const ui64 scopeId, const ui64 allocationInternalGroupId,
74+
const std::shared_ptr<IAllocation>& allocation, const std::shared_ptr<TStageFeatures>& stage);
7475
};
7576

7677
} // namespace NKikimr::NOlap::NGroupedMemoryManager

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22
#include "allocation.h"
33

4+
#include <ydb/core/tx/columnshard/counters/common/object_counter.h>
5+
46
namespace NKikimr::NOlap::NGroupedMemoryManager {
57

68
class TProcessMemoryScope;
79

8-
class TGrouppedAllocations {
10+
class TGrouppedAllocations: public NColumnShard::TMonitoringObjectsCounter<TGrouppedAllocations> {
911
private:
1012
THashMap<ui64, std::shared_ptr<TAllocationInfo>> Allocations;
1113

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include "group.h"
33
#include "ids.h"
44

5+
#include <ydb/core/tx/columnshard/counters/common/object_counter.h>
6+
57
#include <ydb/library/accessor/validator.h>
68

79
namespace NKikimr::NOlap::NGroupedMemoryManager {
810

9-
class TProcessMemoryScope {
11+
class TProcessMemoryScope: public NColumnShard::TMonitoringObjectsCounter<TProcessMemoryScope> {
1012
private:
1113
const ui64 ExternalProcessId;
1214
const ui64 ExternalScopeId;
@@ -63,6 +65,8 @@ class TProcessMemoryScope {
6365
}
6466
GroupIds.Clear();
6567
AllocationInfo.clear();
68+
AFL_INFO(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "scope_cleaned")("process_id", ExternalProcessId)(
69+
"external_scope_id", ExternalScopeId);
6670
return true;
6771
}
6872

@@ -106,7 +110,11 @@ class TProcessMemoryScope {
106110
bool UnregisterAllocation(const ui64 allocationId) {
107111
ui64 memoryAllocated = 0;
108112
auto it = AllocationInfo.find(allocationId);
109-
AFL_VERIFY(it != AllocationInfo.end());
113+
if (it == AllocationInfo.end()) {
114+
AFL_WARN(NKikimrServices::GROUPED_MEMORY_LIMITER)("reason", "allocation_cleaned_in_previous_scope_id_live")(
115+
"allocation_id", allocationId)("process_id", ExternalProcessId)("external_scope_id", ExternalScopeId);
116+
return true;
117+
}
110118
bool waitFlag = false;
111119
const ui64 internalGroupId = it->second->GetAllocationInternalGroupId();
112120
switch (it->second->GetAllocationStatus()) {
@@ -144,7 +152,7 @@ class TProcessMemoryScope {
144152
}
145153
};
146154

147-
class TProcessMemory {
155+
class TProcessMemory: public NColumnShard::TMonitoringObjectsCounter<TProcessMemory> {
148156
private:
149157
const ui64 ExternalProcessId;
150158

@@ -217,7 +225,6 @@ class TProcessMemory {
217225
if (it->second->Unregister()) {
218226
AllocationScopes.erase(it);
219227
}
220-
221228
}
222229

223230
void RegisterScope(const ui64 externalScopeId) {
@@ -227,7 +234,6 @@ class TProcessMemory {
227234
} else {
228235
it->second->Register();
229236
}
230-
231237
}
232238

233239
void SetPriorityProcess() {

0 commit comments

Comments
 (0)