Skip to content

Commit

Permalink
fix allocation cleaning race from separated thread after scope cleani… (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Oct 5, 2024
1 parent 516adee commit 66e070c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 5 additions & 4 deletions ydb/core/tx/limiter/grouped_memory/service/allocation.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <ydb/core/tx/columnshard/counters/common/object_counter.h>
#include <ydb/core/tx/limiter/grouped_memory/usage/abstract.h>

namespace NKikimr::NOlap::NGroupedMemoryManager {
Expand All @@ -9,7 +10,7 @@ enum class EAllocationStatus {
Failed
};

class TAllocationInfo {
class TAllocationInfo: public NColumnShard::TMonitoringObjectsCounter<TAllocationInfo> {
private:
std::shared_ptr<IAllocation> Allocation;
YDB_READONLY(ui64, AllocationInternalGroupId, 0);
Expand All @@ -25,7 +26,7 @@ class TAllocationInfo {
if (GetAllocationStatus() != EAllocationStatus::Failed) {
Stage->Free(AllocatedVolume, GetAllocationStatus() == EAllocationStatus::Allocated);
}

AFL_TRACE(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "destroy")("allocation_id", Identifier)("stage", Stage->GetName());
}

Expand Down Expand Up @@ -69,8 +70,8 @@ class TAllocationInfo {
}
}

TAllocationInfo(const ui64 processId, const ui64 scopeId, const ui64 allocationInternalGroupId, const std::shared_ptr<IAllocation>& allocation,
const std::shared_ptr<TStageFeatures>& stage);
TAllocationInfo(const ui64 processId, const ui64 scopeId, const ui64 allocationInternalGroupId,
const std::shared_ptr<IAllocation>& allocation, const std::shared_ptr<TStageFeatures>& stage);
};

} // namespace NKikimr::NOlap::NGroupedMemoryManager
4 changes: 3 additions & 1 deletion ydb/core/tx/limiter/grouped_memory/service/group.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once
#include "allocation.h"

#include <ydb/core/tx/columnshard/counters/common/object_counter.h>

namespace NKikimr::NOlap::NGroupedMemoryManager {

class TProcessMemoryScope;

class TGrouppedAllocations {
class TGrouppedAllocations: public NColumnShard::TMonitoringObjectsCounter<TGrouppedAllocations> {
private:
THashMap<ui64, std::shared_ptr<TAllocationInfo>> Allocations;

Expand Down
16 changes: 11 additions & 5 deletions ydb/core/tx/limiter/grouped_memory/service/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include "group.h"
#include "ids.h"

#include <ydb/core/tx/columnshard/counters/common/object_counter.h>

#include <ydb/library/accessor/validator.h>

namespace NKikimr::NOlap::NGroupedMemoryManager {

class TProcessMemoryScope {
class TProcessMemoryScope: public NColumnShard::TMonitoringObjectsCounter<TProcessMemoryScope> {
private:
const ui64 ExternalProcessId;
const ui64 ExternalScopeId;
Expand Down Expand Up @@ -63,6 +65,8 @@ class TProcessMemoryScope {
}
GroupIds.Clear();
AllocationInfo.clear();
AFL_INFO(NKikimrServices::GROUPED_MEMORY_LIMITER)("event", "scope_cleaned")("process_id", ExternalProcessId)(
"external_scope_id", ExternalScopeId);
return true;
}

Expand Down Expand Up @@ -106,7 +110,11 @@ class TProcessMemoryScope {
bool UnregisterAllocation(const ui64 allocationId) {
ui64 memoryAllocated = 0;
auto it = AllocationInfo.find(allocationId);
AFL_VERIFY(it != AllocationInfo.end());
if (it == AllocationInfo.end()) {
AFL_WARN(NKikimrServices::GROUPED_MEMORY_LIMITER)("reason", "allocation_cleaned_in_previous_scope_id_live")(
"allocation_id", allocationId)("process_id", ExternalProcessId)("external_scope_id", ExternalScopeId);
return true;
}
bool waitFlag = false;
const ui64 internalGroupId = it->second->GetAllocationInternalGroupId();
switch (it->second->GetAllocationStatus()) {
Expand Down Expand Up @@ -144,7 +152,7 @@ class TProcessMemoryScope {
}
};

class TProcessMemory {
class TProcessMemory: public NColumnShard::TMonitoringObjectsCounter<TProcessMemory> {
private:
const ui64 ExternalProcessId;

Expand Down Expand Up @@ -217,7 +225,6 @@ class TProcessMemory {
if (it->second->Unregister()) {
AllocationScopes.erase(it);
}

}

void RegisterScope(const ui64 externalScopeId) {
Expand All @@ -227,7 +234,6 @@ class TProcessMemory {
} else {
it->second->Register();
}

}

void SetPriorityProcess() {
Expand Down

0 comments on commit 66e070c

Please sign in to comment.