Skip to content

Commit deb925a

Browse files
committed
remove duplication
1 parent d42c83c commit deb925a

File tree

3 files changed

+66
-142
lines changed

3 files changed

+66
-142
lines changed

ydb/core/tablet_flat/flat_part_charge.h

+45-108
Original file line numberDiff line numberDiff line change
@@ -42,68 +42,8 @@ namespace NTable {
4242
}
4343
}
4444

45-
bool Do(const TRowId row1, const TRowId row2,
45+
TResult Do(const TCells key1, const TCells key2, const TRowId row1, const TRowId row2,
4646
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override
47-
{
48-
auto index = Index.TryLoadRaw();
49-
if (!index) {
50-
return false;
51-
}
52-
53-
auto startRow = row1;
54-
auto endRow = row2;
55-
56-
// Page that contains row1
57-
auto first = index->LookupRow(row1);
58-
if (Y_UNLIKELY(!first)) {
59-
return true; // already out of bounds, nothing to precharge
60-
}
61-
62-
// Page that contains row2
63-
auto last = index->LookupRow(row2, first);
64-
if (Y_UNLIKELY(last < first)) {
65-
last = first;
66-
endRow = Min(endRow, index->GetLastRowId(last));
67-
}
68-
69-
return DoPrecharge(TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
70-
}
71-
72-
bool DoReverse(const TRowId row1, const TRowId row2,
73-
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override
74-
{
75-
auto index = Index.TryLoadRaw();
76-
if (!index) {
77-
return false;
78-
}
79-
80-
auto startRow = row1;
81-
auto endRow = row2;
82-
83-
// Page that contains row1
84-
auto first = index->LookupRow(row1);
85-
if (Y_UNLIKELY(!first)) {
86-
// Looks like row1 is out of bounds, start from the last row
87-
startRow = Min(row1, index->GetEndRowId() - 1);
88-
first = --(*index)->End();
89-
if (Y_UNLIKELY(!first)) {
90-
return true; // empty index?
91-
}
92-
}
93-
94-
// Page that contains row2
95-
auto last = index->LookupRow(row2, first);
96-
if (Y_UNLIKELY(last > first)) {
97-
last = first; // will not go past the first page
98-
endRow = Max(endRow, last->GetRowId());
99-
}
100-
101-
return DoPrechargeReverse(TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
102-
}
103-
104-
TResult Do(const TCells key1, const TCells key2, const TRowId row1,
105-
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
106-
ui64 bytesLimit) const noexcept override
10747
{
10848
auto index = Index.TryLoadRaw();
10949
if (!index) {
@@ -164,14 +104,14 @@ namespace NTable {
164104
}
165105
}
166106

167-
bool ready = DoPrecharge(key1, key2, key1Page, key2Page, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
107+
bool ready = DoPrecharge(key1, key2, key1Page, key2Page, first, last,
108+
startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
168109

169110
return { ready, overshot };
170111
}
171112

172-
TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
173-
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
174-
ui64 bytesLimit) const noexcept override
113+
TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1, const TRowId row2,
114+
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override
175115
{
176116
auto index = Index.TryLoadRaw();
177117
if (!index) {
@@ -237,7 +177,8 @@ namespace NTable {
237177
}
238178
}
239179

240-
bool ready = DoPrechargeReverse(key1, key2, key1Page, key2Page, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
180+
bool ready = DoPrechargeReverse(key1, key2, key1Page, key2Page, first, last,
181+
startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
241182

242183
return { ready, overshot };
243184
}
@@ -254,10 +195,8 @@ namespace NTable {
254195
*
255196
* If @param key1Page specified, @param first should be the same.
256197
*/
257-
bool DoPrecharge(const TCells key1, const TCells key2,
258-
const TIter key1Page, const TIter key2Page,
259-
const TIter first, const TIter last,
260-
TRowId startRowId, TRowId endRowId,
198+
bool DoPrecharge(const TCells key1, const TCells key2, const TIter key1Page, const TIter key2Page,
199+
const TIter first, const TIter last, TRowId startRowId, TRowId endRowId,
261200
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
262201
{
263202
bool ready = true;
@@ -352,10 +291,8 @@ namespace NTable {
352291
*
353292
* If @param key1Page specified, @param first should be the same.
354293
*/
355-
bool DoPrechargeReverse(const TCells key1, const TCells key2,
356-
const TIter key1Page, const TIter key2Page,
357-
TIter first, TIter last,
358-
TRowId startRowId, TRowId endRowId,
294+
bool DoPrechargeReverse(const TCells key1, const TCells key2, const TIter key1Page, const TIter key2Page,
295+
TIter first, TIter last, TRowId startRowId, TRowId endRowId,
359296
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
360297
{
361298
bool ready = true;
@@ -562,8 +499,8 @@ namespace NTable {
562499
/**
563500
* Precharges pages that contain row1 to row2 inclusive
564501
*/
565-
bool DoPrechargeGroup(TGroupState& g, TRowId row1, TRowId row2, ui64& bytes) const noexcept {
566-
auto groupIndex = g.GroupIndex.TryLoadRaw();
502+
bool DoPrechargeGroup(TGroupState& group, TRowId row1, TRowId row2, ui64& bytes) const noexcept {
503+
auto groupIndex = group.GroupIndex.TryLoadRaw();
567504
if (!groupIndex) {
568505
if (bytes) {
569506
// Note: we can't continue if we have bytes limit
@@ -574,29 +511,29 @@ namespace NTable {
574511

575512
bool ready = true;
576513

577-
if (!g.Index || row1 < g.Index->GetRowId() || row1 > g.LastRowId) {
578-
g.Index = groupIndex->LookupRow(row1, g.Index);
579-
if (Y_UNLIKELY(!g.Index)) {
514+
if (!group.Index || row1 < group.Index->GetRowId() || row1 > group.LastRowId) {
515+
group.Index = groupIndex->LookupRow(row1, group.Index);
516+
if (Y_UNLIKELY(!group.Index)) {
580517
// Looks like row1 doesn't even exist
581-
g.LastRowId = Max<TRowId>();
518+
group.LastRowId = Max<TRowId>();
582519
return ready;
583520
}
584-
g.LastRowId = groupIndex->GetLastRowId(g.Index);
585-
auto pageId = g.Index->GetPageId();
586-
ready &= bool(Env->TryGetPage(Part, pageId, g.GroupId));
587-
bytes += Part->GetPageSize(pageId, g.GroupId);
521+
group.LastRowId = groupIndex->GetLastRowId(group.Index);
522+
auto pageId = group.Index->GetPageId();
523+
ready &= bool(Env->TryGetPage(Part, pageId, group.GroupId));
524+
bytes += Part->GetPageSize(pageId, group.GroupId);
588525
}
589526

590-
while (g.LastRowId < row2) {
591-
if (!++g.Index) {
527+
while (group.LastRowId < row2) {
528+
if (!++group.Index) {
592529
// Looks like row2 doesn't even exist
593-
g.LastRowId = Max<TRowId>();
530+
group.LastRowId = Max<TRowId>();
594531
return ready;
595532
}
596-
g.LastRowId = groupIndex->GetLastRowId(g.Index);
597-
auto pageId = g.Index->GetPageId();
598-
ready &= bool(Env->TryGetPage(Part, pageId, g.GroupId));
599-
bytes += Part->GetPageSize(pageId, g.GroupId);
533+
group.LastRowId = groupIndex->GetLastRowId(group.Index);
534+
auto pageId = group.Index->GetPageId();
535+
ready &= bool(Env->TryGetPage(Part, pageId, group.GroupId));
536+
bytes += Part->GetPageSize(pageId, group.GroupId);
600537
}
601538

602539
return ready;
@@ -605,8 +542,8 @@ namespace NTable {
605542
/**
606543
* Precharges pages that contain row1 to row2 inclusive in reverse
607544
*/
608-
bool DoPrechargeGroupReverse(TGroupState& g, TRowId row1, TRowId row2, ui64& bytes) const noexcept {
609-
auto groupIndex = g.GroupIndex.TryLoadRaw();
545+
bool DoPrechargeGroupReverse(TGroupState& group, TRowId row1, TRowId row2, ui64& bytes) const noexcept {
546+
auto groupIndex = group.GroupIndex.TryLoadRaw();
610547
if (!groupIndex) {
611548
if (bytes) {
612549
// Note: we can't continue if we have bytes limit
@@ -617,29 +554,29 @@ namespace NTable {
617554

618555
bool ready = true;
619556

620-
if (!g.Index || row1 < g.Index->GetRowId() || row1 > g.LastRowId) {
621-
g.Index = groupIndex->LookupRow(row1, g.Index);
622-
if (Y_UNLIKELY(!g.Index)) {
557+
if (!group.Index || row1 < group.Index->GetRowId() || row1 > group.LastRowId) {
558+
group.Index = groupIndex->LookupRow(row1, group.Index);
559+
if (Y_UNLIKELY(!group.Index)) {
623560
// Looks like row1 doesn't even exist
624-
g.LastRowId = Max<TRowId>();
561+
group.LastRowId = Max<TRowId>();
625562
return ready;
626563
}
627-
g.LastRowId = groupIndex->GetLastRowId(g.Index);
628-
auto pageId = g.Index->GetPageId();
629-
ready &= bool(Env->TryGetPage(Part, pageId, g.GroupId));
630-
bytes += Part->GetPageSize(pageId, g.GroupId);
564+
group.LastRowId = groupIndex->GetLastRowId(group.Index);
565+
auto pageId = group.Index->GetPageId();
566+
ready &= bool(Env->TryGetPage(Part, pageId, group.GroupId));
567+
bytes += Part->GetPageSize(pageId, group.GroupId);
631568
}
632569

633-
while (g.Index->GetRowId() > row2) {
634-
if (g.Index.Off() == 0) {
570+
while (group.Index->GetRowId() > row2) {
571+
if (group.Index.Off() == 0) {
635572
// This was the last page we could precharge
636573
return ready;
637574
}
638-
g.LastRowId = g.Index->GetRowId() - 1;
639-
--g.Index;
640-
auto pageId = g.Index->GetPageId();
641-
ready &= bool(Env->TryGetPage(Part, pageId, g.GroupId));
642-
bytes += Part->GetPageSize(pageId, g.GroupId);
575+
group.LastRowId = group.Index->GetRowId() - 1;
576+
--group.Index;
577+
auto pageId = group.Index->GetPageId();
578+
ready &= bool(Env->TryGetPage(Part, pageId, group.GroupId));
579+
bytes += Part->GetPageSize(pageId, group.GroupId);
643580
}
644581

645582
return ready;

ydb/core/tablet_flat/flat_part_charge_btree_index.h

+5-24
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,7 @@ namespace NKikimr::NTable {
1515
Y_UNUSED(includeHistory);
1616
}
1717

18-
virtual bool Do(const TRowId row1, const TRowId row2,
19-
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override {
20-
// TODO: implement
21-
Y_UNUSED(row1);
22-
Y_UNUSED(row2);
23-
Y_UNUSED(keyDefaults);
24-
Y_UNUSED(itemsLimit);
25-
Y_UNUSED(bytesLimit);
26-
return true;
27-
}
28-
29-
virtual bool DoReverse(const TRowId row1, const TRowId row2,
30-
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept override {
31-
// TODO: implement
32-
Y_UNUSED(row1);
33-
Y_UNUSED(row2);
34-
Y_UNUSED(keyDefaults);
35-
Y_UNUSED(itemsLimit);
36-
Y_UNUSED(bytesLimit);
37-
return true;
38-
}
39-
40-
virtual TResult Do(const TCells key1, const TCells key2, const TRowId row1,
18+
TResult Do(const TCells key1, const TCells key2, const TRowId row1,
4119
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
4220
ui64 bytesLimit) const noexcept override {
4321
// TODO: implement
@@ -51,7 +29,7 @@ namespace NKikimr::NTable {
5129
return {true, false};
5230
}
5331

54-
virtual TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
32+
TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
5533
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
5634
ui64 bytesLimit) const noexcept override {
5735
// TODO: implement
@@ -64,6 +42,9 @@ namespace NKikimr::NTable {
6442
Y_UNUSED(bytesLimit);
6543
return {true, false};
6644
}
45+
46+
private:
47+
6748
};
6849

6950
}

ydb/core/tablet_flat/flat_part_charge_iface.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,36 @@ namespace NKikimr::NTable {
1717
*
1818
* Important caveat: assumes iteration won't touch any row > row2
1919
*/
20-
virtual bool Do(const TRowId row1, const TRowId row2,
21-
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept = 0;
20+
bool Do(const TRowId row1, const TRowId row2,
21+
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
22+
{
23+
return Do(TCells{}, TCells{}, row1, row2,
24+
keyDefaults, itemsLimit, bytesLimit).Ready;
25+
}
2226

2327
/**
2428
* Precharges data for rows between row1 and row2 inclusive in reverse
2529
*
2630
* Important caveat: assumes iteration won't touch any row > row2
2731
*/
28-
virtual bool DoReverse(const TRowId row1, const TRowId row2,
29-
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept = 0;
32+
bool DoReverse(const TRowId row1, const TRowId row2,
33+
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept
34+
{
35+
return DoReverse(TCells{}, TCells{}, row1, row2,
36+
keyDefaults, itemsLimit, bytesLimit).Ready;
37+
}
3038

3139
/**
3240
* Precharges data for rows between max(key1, row1) and min(key2, row2) inclusive
3341
*/
34-
virtual TResult Do(const TCells key1, const TCells key2, const TRowId row1,
35-
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
36-
ui64 bytesLimit) const noexcept = 0;
42+
virtual TResult Do(const TCells key1, const TCells key2, const TRowId row1, const TRowId row2,
43+
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept = 0;
3744

3845
/**
3946
* Precharges data for rows between min(key1, row1) and max(key2, row2) inclusive in reverse
4047
*/
41-
virtual TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
42-
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
43-
ui64 bytesLimit) const noexcept = 0;
48+
virtual TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1, const TRowId row2,
49+
const TKeyCellDefaults &keyDefaults, ui64 itemsLimit, ui64 bytesLimit) const noexcept = 0;
4450

4551
virtual ~ICharge() = default;
4652
};

0 commit comments

Comments
 (0)