1
1
#pragma once
2
2
3
- #include " defs.h"
4
3
#include " flat_table_part.h"
5
4
#include " flat_part_iface.h"
6
- #include " flat_part_slice.h"
7
5
#include " flat_part_index_iter.h"
6
+ #include " flat_part_charge_iface.h"
8
7
9
8
#include < util/generic/bitmap.h>
10
9
11
10
namespace NKikimr {
12
11
namespace NTable {
13
12
14
- class TCharge {
13
+ class TCharge : public ICharge {
15
14
public:
16
- using TCells = NPage::TCells;
17
15
using TIter = NPage::TIndex::TIter;
18
16
using TDataPage = NPage::TDataPage;
19
17
using TGroupId = NPage::TGroupId;
20
-
21
- struct TResult {
22
- bool Ready; /* All required pages are already in memory */
23
- bool Overshot; /* Search may start outside of bounds */
24
- };
25
18
26
19
TCharge (IPages *env, const TPart &part, TTagsRef tags, bool includeHistory = false )
27
20
: Env(env)
@@ -49,131 +42,8 @@ namespace NTable {
49
42
}
50
43
}
51
44
52
- static bool Range (IPages *env, const TCells key1, const TCells key2,
53
- const TRun &run, const TKeyCellDefaults &keyDefaults, TTagsRef tags,
54
- ui64 items, ui64 bytes, bool includeHistory = false ) noexcept
55
- {
56
- if (run.size () == 1 ) {
57
- auto pos = run.begin ();
58
- TRowId row1 = pos->Slice .BeginRowId ();
59
- TRowId row2 = pos->Slice .EndRowId () - 1 ;
60
- return TCharge (env, *pos->Part , tags, includeHistory).Do (key1, key2, row1, row2, keyDefaults, items, bytes).Ready ;
61
- }
62
-
63
- bool ready = true ;
64
- auto pos = run.LowerBound (key1);
65
-
66
- if (pos == run.end ())
67
- return true ;
68
-
69
- bool fromStart = TSlice::CompareSearchKeyFirstKey (key1, pos->Slice , keyDefaults) <= 0 ;
70
-
71
- while (pos != run.end ()) {
72
- TRowId row1 = pos->Slice .BeginRowId ();
73
- TRowId row2 = pos->Slice .EndRowId () - 1 ;
74
-
75
- const int cmp = TSlice::CompareLastKeySearchKey (pos->Slice , key2, keyDefaults);
76
-
77
- TArrayRef<const TCell> key1r;
78
- if (!fromStart) {
79
- key1r = key1;
80
- }
81
- TArrayRef<const TCell> key2r;
82
- if (cmp > 0 /* slice->LastKey > key2 */ ) {
83
- key2r = key2;
84
- }
85
-
86
- auto r = TCharge (env, *pos->Part , tags, includeHistory).Do (key1r, key2r, row1, row2, keyDefaults, items, bytes);
87
- ready &= r.Ready ;
88
-
89
- if (cmp >= 0 /* slice->LastKey >= key2 */ ) {
90
- if (r.Overshot && ++pos != run.end ()) {
91
- // Unfortunately key > key2 might be at the start of the next slice
92
- TRowId firstRow = pos->Slice .BeginRowId ();
93
- // Precharge the first row on the next slice
94
- TCharge (env, *pos->Part , tags, includeHistory).Do (firstRow, firstRow, keyDefaults, items, bytes);
95
- }
96
-
97
- break ;
98
- }
99
-
100
- // Will consume this slice before encountering key2
101
- fromStart = true ;
102
- ++pos;
103
- }
104
-
105
- return ready;
106
- }
107
-
108
- static bool RangeReverse (IPages *env, const TCells key1, const TCells key2,
109
- const TRun &run, const TKeyCellDefaults &keyDefaults, TTagsRef tags,
110
- ui64 items, ui64 bytes, bool includeHistory = false ) noexcept
111
- {
112
- if (run.size () == 1 ) {
113
- auto pos = run.begin ();
114
- TRowId row1 = pos->Slice .EndRowId () - 1 ;
115
- TRowId row2 = pos->Slice .BeginRowId ();
116
- return TCharge (env, *pos->Part , tags, includeHistory).DoReverse (key1, key2, row1, row2, keyDefaults, items, bytes).Ready ;
117
- }
118
-
119
- bool ready = true ;
120
- auto pos = run.LowerBoundReverse (key1);
121
-
122
- if (pos == run.end ())
123
- return true ;
124
-
125
- bool fromEnd = TSlice::CompareLastKeySearchKey (pos->Slice , key1, keyDefaults) <= 0 ;
126
-
127
- for (;;) {
128
- TRowId row1 = pos->Slice .EndRowId () - 1 ;
129
- TRowId row2 = pos->Slice .BeginRowId ();
130
-
131
- // N.B. empty key2 is like -inf during reverse iteration
132
- const int cmp = key2 ? TSlice::CompareSearchKeyFirstKey (key2, pos->Slice , keyDefaults) : -1 ;
133
-
134
- TArrayRef<const TCell> key1r;
135
- if (!fromEnd) {
136
- key1r = key1;
137
- }
138
- TArrayRef<const TCell> key2r;
139
- if (cmp > 0 /* key2 > slice->FirstKey */ ) {
140
- key2r = key2;
141
- }
142
-
143
- auto r = TCharge (env, *pos->Part , tags, includeHistory).DoReverse (key1r, key2r, row1, row2, keyDefaults, items, bytes);
144
- ready &= r.Ready ;
145
-
146
- if (pos == run.begin ()) {
147
- break ;
148
- }
149
-
150
- if (cmp >= 0 /* key2 >= slice->FirstKey */ ) {
151
- if (r.Overshot ) {
152
- --pos;
153
- // Unfortunately key <= key2 might be at the end of the previous slice
154
- TRowId lastRow = pos->Slice .EndRowId () - 1 ;
155
- // Precharge the last row on the previous slice
156
- TCharge (env, *pos->Part , tags, includeHistory).DoReverse (lastRow, lastRow, keyDefaults, items, bytes);
157
- }
158
-
159
- break ;
160
- }
161
-
162
- // Will consume this slice before encountering key2
163
- fromEnd = true ;
164
- --pos;
165
- }
166
-
167
- return ready;
168
- }
169
-
170
- /* *
171
- * Precharges data for rows between row1 and row2 inclusive
172
- *
173
- * Important caveat: assumes iteration won't touch any row > row2
174
- */
175
45
bool Do (const TRowId row1, const TRowId row2,
176
- const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
46
+ const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override
177
47
{
178
48
auto index = Index.TryLoadRaw ();
179
49
if (!index ) {
@@ -199,13 +69,8 @@ namespace NTable {
199
69
return DoPrecharge (TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
200
70
}
201
71
202
- /* *
203
- * Precharges data for rows between row1 and row2 inclusive in reverse
204
- *
205
- * Important caveat: assumes iteration won't touch any row > row2
206
- */
207
72
bool DoReverse (const TRowId row1, const TRowId row2,
208
- const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
73
+ const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override
209
74
{
210
75
auto index = Index.TryLoadRaw ();
211
76
if (!index ) {
@@ -236,12 +101,9 @@ namespace NTable {
236
101
return DoPrechargeReverse (TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
237
102
}
238
103
239
- /* *
240
- * Precharges data for rows between max(key1, row1) and min(key2, row2) inclusive
241
- */
242
104
TResult Do (const TCells key1, const TCells key2, const TRowId row1,
243
105
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
244
- ui64 bytesLimit) const noexcept
106
+ ui64 bytesLimit) const noexcept override
245
107
{
246
108
auto index = Index.TryLoadRaw ();
247
109
if (!index ) {
@@ -307,12 +169,9 @@ namespace NTable {
307
169
return { ready, overshot };
308
170
}
309
171
310
- /* *
311
- * Precharges data for rows between min(key1, row1) and max(key2, row2) inclusive in reverse
312
- */
313
172
TResult DoReverse (const TCells key1, const TCells key2, const TRowId row1,
314
173
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
315
- ui64 bytesLimit) const noexcept
174
+ ui64 bytesLimit) const noexcept override
316
175
{
317
176
auto index = Index.TryLoadRaw ();
318
177
if (!index ) {
0 commit comments