33
44namespace NKikimr ::NOlap::NGranule::NPortionsIndex {
55
6- TPortionsIndex::TPortionIntervals TPortionsIndex::GetIntervalFeatures (const TPortionInfo& inputPortion, const THashSet<ui64>& skipPortions) const {
7- auto itFrom = Points.find (inputPortion.IndexKeyStart ());
8- AFL_VERIFY (itFrom != Points.end ());
9- auto itTo = Points.find (inputPortion.IndexKeyEnd ());
10- AFL_VERIFY (itTo != Points.end ());
11- TPortionIntervals portionExcludeIntervals;
12- while (true ) {
13- std::optional<NArrow::TReplaceKey> nextKey;
14- for (auto && [p, _] : itFrom->second .GetPortionIds ()) {
15- if (skipPortions.contains (p)) {
16- continue ;
17- }
18- const auto & portionCross = Owner.GetPortionVerified (p);
19- if (!portionCross.CrossSSWith (inputPortion)) {
20- continue ;
21- }
22- if (!nextKey || *nextKey < portionCross.IndexKeyEnd ()) {
23- nextKey = portionCross.IndexKeyEnd ();
24- }
6+ bool TPortionsIndex::HasOlderIntervals (const TPortionInfo& inputPortion, const THashSet<ui64>& skipPortions) const {
7+ for (auto && [_, p] : Portions) {
8+ if (p->GetPortionId () == inputPortion.GetPortionId ()) {
9+ continue ;
2510 }
26- if (nextKey) {
27- nextKey = std::min (inputPortion.IndexKeyEnd (), *nextKey);
28- portionExcludeIntervals.Add (itFrom->first , *nextKey);
29- auto itFromNext = Points.find (*nextKey);
30- AFL_VERIFY (itFromNext != Points.end ());
31- if (itFromNext == itTo) {
32- break ;
33- }
34- if (itFromNext == itFrom) {
35- ++itFrom;
36- } else {
37- itFrom = itFromNext;
38- }
39- AFL_VERIFY (itFrom != Points.end ());
40- } else {
41- if (itFrom == itTo) {
42- break ;
43- }
44- ++itFrom;
45- AFL_VERIFY (itFrom != Points.end ());
11+ if (inputPortion.IndexKeyEnd () < p->IndexKeyStart ()) {
12+ continue ;
4613 }
47-
48- }
49- return portionExcludeIntervals;
50- }
51-
52- void TPortionsIndex::RemovePortion (const std::shared_ptr<TPortionInfo>& p) {
53- auto itFrom = Points.find (p->IndexKeyStart ());
54- AFL_VERIFY (itFrom != Points.end ());
55- auto itTo = Points.find (p->IndexKeyEnd ());
56- AFL_VERIFY (itTo != Points.end ());
57- {
58- const TPortionInfoStat stat (p);
59- auto it = itFrom;
60- while (true ) {
61- RemoveFromMemoryUsageControl (it->second .GetIntervalStats ());
62- it->second .RemoveContained (stat);
63- RawMemoryUsage.Add (it->second .GetIntervalStats ().GetMinRawBytes ());
64- BlobMemoryUsage.Add (it->second .GetIntervalStats ().GetBlobBytes ());
65- if (it == itTo) {
66- break ;
67- }
68- AFL_VERIFY (++it != Points.end ());
69- }
70- }
71- if (itFrom != itTo) {
72- itFrom->second .RemoveStart (p);
73- if (itFrom->second .IsEmpty ()) {
74- RemoveFromMemoryUsageControl (itFrom->second .GetIntervalStats ());
75- Points.erase (itFrom);
14+ if (p->IndexKeyEnd () < inputPortion.IndexKeyStart ()) {
15+ continue ;
7616 }
77- itTo->second .RemoveFinish (p);
78- if (itTo->second .IsEmpty ()) {
79- RemoveFromMemoryUsageControl (itTo->second .GetIntervalStats ());
80- Points.erase (itTo);
17+ if (skipPortions.contains (p->GetPortionId ())) {
18+ continue ;
8119 }
82- } else {
83- itTo->second .RemoveStart (p);
84- itTo->second .RemoveFinish (p);
85- if (itTo->second .IsEmpty ()) {
86- RemoveFromMemoryUsageControl (itTo->second .GetIntervalStats ());
87- Points.erase (itTo);
88- }
89- }
90- RawMemoryUsage.FlushCounters ();
91- BlobMemoryUsage.FlushCounters ();
92- }
93-
94- void TPortionsIndex::AddPortion (const std::shared_ptr<TPortionInfo>& p) {
95- auto itFrom = InsertPoint (p->IndexKeyStart ());
96- itFrom->second .AddStart (p);
97- auto itTo = InsertPoint (p->IndexKeyEnd ());
98- itTo->second .AddFinish (p);
99-
100- auto it = itFrom;
101- const TPortionInfoStat stat (p);
102- while (true ) {
103- RemoveFromMemoryUsageControl (it->second .GetIntervalStats ());
104- it->second .AddContained (stat);
105- RawMemoryUsage.Add (it->second .GetIntervalStats ().GetMinRawBytes ());
106- BlobMemoryUsage.Add (it->second .GetIntervalStats ().GetBlobBytes ());
107- if (it == itTo) {
108- break ;
20+ if (inputPortion.RecordSnapshotMax () < p->RecordSnapshotMin ()) {
21+ continue ;
10922 }
110- AFL_VERIFY (++it != Points. end ()) ;
23+ return true ;
11124 }
112- RawMemoryUsage.FlushCounters ();
113- BlobMemoryUsage.FlushCounters ();
25+ return false ;
11426}
11527
11628}
0 commit comments