@@ -10,29 +10,41 @@ namespace NKikimr::NOlap::NGranule::NPortionsIndex {
10
10
11
11
class TPortionInfoStat {
12
12
private:
13
+ std::shared_ptr<TPortionInfo> PortionInfo;
13
14
YDB_READONLY (ui64, MinRawBytes, 0 );
14
15
YDB_READONLY (ui64, BlobBytes, 0 );
15
16
16
17
public:
17
- TPortionInfoStat () = default ;
18
-
19
- TPortionInfoStat (const ui64 rawBytes, const ui64 blobBytes)
20
- : MinRawBytes(rawBytes)
21
- , BlobBytes(blobBytes)
18
+ TPortionInfoStat (const std::shared_ptr<TPortionInfo>& portionInfo)
19
+ : PortionInfo(portionInfo)
20
+ , MinRawBytes(PortionInfo->GetMinMemoryForReadColumns ({}))
21
+ , BlobBytes(PortionInfo->GetTotalBlobBytes ())
22
22
{
23
23
24
24
}
25
25
26
+ const TPortionInfo& GetPortionInfoVerified () const {
27
+ AFL_VERIFY (PortionInfo);
28
+ return *PortionInfo;
29
+ }
30
+ };
31
+
32
+ class TIntervalInfoStat {
33
+ private:
34
+ YDB_READONLY (ui64, MinRawBytes, 0 );
35
+ YDB_READONLY (ui64, BlobBytes, 0 );
36
+
37
+ public:
26
38
void Add (const TPortionInfoStat& source) {
27
- MinRawBytes += source.MinRawBytes ;
28
- BlobBytes += source.BlobBytes ;
39
+ MinRawBytes += source.GetMinRawBytes () ;
40
+ BlobBytes += source.GetBlobBytes () ;
29
41
}
30
42
31
43
void Sub (const TPortionInfoStat& source) {
32
- AFL_VERIFY (MinRawBytes >= source.MinRawBytes );
33
- MinRawBytes -= source.MinRawBytes ;
34
- AFL_VERIFY (BlobBytes >= source.BlobBytes );
35
- BlobBytes -= source.BlobBytes ;
44
+ AFL_VERIFY (MinRawBytes >= source.GetMinRawBytes () );
45
+ MinRawBytes -= source.GetMinRawBytes () ;
46
+ AFL_VERIFY (BlobBytes >= source.GetBlobBytes () );
47
+ BlobBytes -= source.GetBlobBytes () ;
36
48
AFL_VERIFY (!!BlobBytes == !!MinRawBytes);
37
49
}
38
50
@@ -46,20 +58,20 @@ class TPortionsPKPoint {
46
58
THashMap<ui64, std::shared_ptr<TPortionInfo>> Start;
47
59
THashMap<ui64, std::shared_ptr<TPortionInfo>> Finish;
48
60
THashMap<ui64, TPortionInfoStat> PortionIds;
49
- YDB_READONLY_DEF (TPortionInfoStat , IntervalStats);
61
+ YDB_READONLY_DEF (TIntervalInfoStat , IntervalStats);
50
62
51
63
public:
52
64
const THashMap<ui64, std::shared_ptr<TPortionInfo>>& GetStart () const {
53
65
return Start;
54
66
}
55
67
56
68
void ProvidePortions (const TPortionsPKPoint& source) {
57
- IntervalStats = TPortionInfoStat ();
69
+ IntervalStats = TIntervalInfoStat ();
58
70
for (auto && [i, stat] : source.PortionIds ) {
59
71
if (source.Finish .contains (i)) {
60
72
continue ;
61
73
}
62
- AddContained (i, stat);
74
+ AddContained (stat);
63
75
}
64
76
}
65
77
@@ -71,17 +83,19 @@ class TPortionsPKPoint {
71
83
return Start.empty () && Finish.empty ();
72
84
}
73
85
74
- void AddContained (const ui32 portionId, const TPortionInfoStat& stat) {
75
- IntervalStats.Add (stat);
76
- AFL_VERIFY (PortionIds.emplace (portionId, stat).second );
86
+ void AddContained (const TPortionInfoStat& stat) {
87
+ if (!stat.GetPortionInfoVerified ().HasRemoveSnapshot ()) {
88
+ IntervalStats.Add (stat);
89
+ }
90
+ AFL_VERIFY (PortionIds.emplace (stat.GetPortionInfoVerified ().GetPortionId (), stat).second );
77
91
}
78
92
79
- void RemoveContained (const ui32 portionId, const TPortionInfoStat& stat) {
80
- IntervalStats.Sub (stat);
81
- AFL_VERIFY (PortionIds.erase (portionId));
82
- if (PortionIds.empty ()) {
83
- AFL_VERIFY (!IntervalStats);
93
+ void RemoveContained (const TPortionInfoStat& stat) {
94
+ if (!stat.GetPortionInfoVerified ().HasRemoveSnapshot ()) {
95
+ IntervalStats.Sub (stat);
84
96
}
97
+ AFL_VERIFY (PortionIds.erase (stat.GetPortionInfoVerified ().GetPortionId ()));
98
+ AFL_VERIFY (PortionIds.size () || !IntervalStats);
85
99
}
86
100
87
101
void RemoveStart (const std::shared_ptr<TPortionInfo>& p) {
@@ -162,7 +176,7 @@ class TPortionsIndex {
162
176
return it;
163
177
}
164
178
165
- void RemoveFromMemoryUsageControl (const TPortionInfoStat & stat) {
179
+ void RemoveFromMemoryUsageControl (const TIntervalInfoStat & stat) {
166
180
RawMemoryUsage.Remove (stat.GetMinRawBytes ());
167
181
BlobMemoryUsage.Remove (stat.GetBlobBytes ());
168
182
}
0 commit comments