1
1
#pragma once
2
+ #include < ydb/core/tx/columnshard/counters/engine_logs.h>
2
3
#include < ydb/core/tx/columnshard/engines/portions/portion_info.h>
3
4
4
5
namespace NKikimr ::NOlap {
@@ -11,35 +12,44 @@ class TPortionsPKPoint {
11
12
private:
12
13
THashMap<ui64, std::shared_ptr<TPortionInfo>> Start;
13
14
THashMap<ui64, std::shared_ptr<TPortionInfo>> Finish;
14
- THashSet<ui64> PortionIds;
15
+ THashMap<ui64, ui64> PortionIds;
16
+ YDB_READONLY (ui64, MinMemoryRead, 0 );
17
+
15
18
public:
16
19
const THashMap<ui64, std::shared_ptr<TPortionInfo>>& GetStart () const {
17
20
return Start;
18
21
}
19
22
20
23
void ProvidePortions (const TPortionsPKPoint& source) {
21
- for (auto && i : source.PortionIds ) {
24
+ MinMemoryRead = 0 ;
25
+ for (auto && [i, mem] : source.PortionIds ) {
22
26
if (source.Finish .contains (i)) {
23
27
continue ;
24
28
}
25
- AFL_VERIFY (PortionIds. emplace (i). second );
29
+ AddContained (i, mem );
26
30
}
27
31
}
28
32
29
- const THashSet< ui64>& GetPortionIds () const {
33
+ const THashMap<ui64, ui64>& GetPortionIds () const {
30
34
return PortionIds;
31
35
}
32
36
33
37
bool IsEmpty () const {
34
38
return Start.empty () && Finish.empty ();
35
39
}
36
40
37
- void AddContained (const ui64 portionId) {
38
- AFL_VERIFY (PortionIds.emplace (portionId).second );
41
+ void AddContained (const ui32 portionId, const ui64 minMemoryRead) {
42
+ MinMemoryRead += minMemoryRead;
43
+ AFL_VERIFY (PortionIds.emplace (portionId, minMemoryRead).second );
39
44
}
40
45
41
- void RemoveContained (const ui64 portionId) {
46
+ void RemoveContained (const ui32 portionId, const ui64 minMemoryRead) {
47
+ AFL_VERIFY (minMemoryRead <= MinMemoryRead);
48
+ MinMemoryRead -= minMemoryRead;
42
49
AFL_VERIFY (PortionIds.erase (portionId));
50
+ if (PortionIds.empty ()) {
51
+ AFL_VERIFY (!MinMemoryRead);
52
+ }
43
53
}
44
54
45
55
void RemoveStart (const std::shared_ptr<TPortionInfo>& p) {
@@ -64,7 +74,9 @@ class TPortionsPKPoint {
64
74
class TPortionsIndex {
65
75
private:
66
76
std::map<NArrow::TReplaceKey, TPortionsPKPoint> Points;
77
+ std::map<ui64, i32> CountMemoryUsages;
67
78
const TGranuleMeta& Owner;
79
+ const NColumnShard::TPortionsIndexCounters& Counters;
68
80
69
81
std::map<NArrow::TReplaceKey, TPortionsPKPoint>::iterator InsertPoint (const NArrow::TReplaceKey& key) {
70
82
auto it = Points.find (key);
@@ -75,17 +87,35 @@ class TPortionsIndex {
75
87
--itPred;
76
88
it->second .ProvidePortions (itPred->second );
77
89
}
90
+ ++CountMemoryUsages[it->second .GetMinMemoryRead ()];
78
91
}
79
92
return it;
80
93
}
81
94
95
+ void RemoveFromMemoryUsageControl (const ui64 mem) {
96
+ auto it = CountMemoryUsages.find (mem);
97
+ AFL_VERIFY (it != CountMemoryUsages.end ())(" mem" , mem);
98
+ if (!--it->second ) {
99
+ CountMemoryUsages.erase (it);
100
+ }
101
+ }
102
+
82
103
public:
83
- TPortionsIndex (const TGranuleMeta& owner)
104
+ TPortionsIndex (const TGranuleMeta& owner, const NColumnShard::TPortionsIndexCounters& counters )
84
105
: Owner(owner)
106
+ , Counters(counters)
85
107
{
86
108
87
109
}
88
110
111
+ ui64 GetMinMemoryRead () const {
112
+ if (CountMemoryUsages.empty ()) {
113
+ return 0 ;
114
+ } else {
115
+ return CountMemoryUsages.rbegin ()->second ;
116
+ }
117
+ }
118
+
89
119
const std::map<NArrow::TReplaceKey, TPortionsPKPoint>& GetPoints () const {
90
120
return Points;
91
121
}
0 commit comments