Skip to content

Commit e7f64cc

Browse files
committed
KIKIMR-19521 BTreeIndex Charge Interface
1 parent 897ada7 commit e7f64cc

17 files changed

+325
-167
lines changed

ydb/core/tablet_flat/CMakeLists.darwin-arm64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ target_sources(ydb-core-tablet_flat PRIVATE
107107
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_mem_warm.cpp
108108
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausagecache.cpp
109109
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausage_meta.cpp
110+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_create.cpp
111+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_range.cpp
110112
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_page_label.cpp
111113
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_dump.cpp
112114
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_iter_multi.cpp

ydb/core/tablet_flat/CMakeLists.darwin-x86_64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ target_sources(ydb-core-tablet_flat PRIVATE
107107
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_mem_warm.cpp
108108
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausagecache.cpp
109109
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausage_meta.cpp
110+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_create.cpp
111+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_range.cpp
110112
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_page_label.cpp
111113
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_dump.cpp
112114
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_iter_multi.cpp

ydb/core/tablet_flat/CMakeLists.linux-aarch64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ target_sources(ydb-core-tablet_flat PRIVATE
108108
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_mem_warm.cpp
109109
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausagecache.cpp
110110
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausage_meta.cpp
111+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_create.cpp
112+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_range.cpp
111113
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_page_label.cpp
112114
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_dump.cpp
113115
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_iter_multi.cpp

ydb/core/tablet_flat/CMakeLists.linux-x86_64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ target_sources(ydb-core-tablet_flat PRIVATE
108108
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_mem_warm.cpp
109109
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausagecache.cpp
110110
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausage_meta.cpp
111+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_create.cpp
112+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_range.cpp
111113
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_page_label.cpp
112114
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_dump.cpp
113115
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_iter_multi.cpp

ydb/core/tablet_flat/CMakeLists.windows-x86_64.txt

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ target_sources(ydb-core-tablet_flat PRIVATE
107107
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_mem_warm.cpp
108108
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausagecache.cpp
109109
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_sausage_meta.cpp
110+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_create.cpp
111+
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_charge_range.cpp
110112
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_page_label.cpp
111113
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_dump.cpp
112114
${CMAKE_SOURCE_DIR}/ydb/core/tablet_flat/flat_part_iter_multi.cpp

ydb/core/tablet_flat/benchmark/b_charge.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <benchmark/benchmark.h>
2-
#include <random>
32

43
#include <ydb/core/tablet_flat/flat_row_celled.h>
5-
#include <ydb/core/tablet_flat/flat_part_charge.h>
4+
#include <ydb/core/tablet_flat/flat_part_charge_range.h>
5+
#include <ydb/core/tablet_flat/flat_part_charge_create.h>
66
#include <ydb/core/tablet_flat/test/libs/rows/cook.h>
77
#include <ydb/core/tablet_flat/test/libs/rows/tool.h>
88
#include <ydb/core/tablet_flat/test/libs/table/model/large.h>
@@ -138,7 +138,7 @@ BENCHMARK_DEFINE_F(TModel, PrechargeByKeys)(benchmark::State& state) {
138138
const auto from = Tool.KeyCells(Mass.Saved[lower]);
139139
const auto to = Tool.KeyCells(Mass.Saved[upper]);
140140

141-
TCharge::Range(Env.Get(), from, to, *Run.Get(), keyDefaults, Tags, items, Max<ui64>());
141+
ChargeRange(Env.Get(), from, to, *Run.Get(), keyDefaults, Tags, items, Max<ui64>());
142142
}
143143

144144
state.counters["Touched"] = benchmark::Counter(Env->TouchedCount, benchmark::Counter::kAvgIterations);
@@ -154,7 +154,7 @@ BENCHMARK_DEFINE_F(TModel, PrechargeByRows)(benchmark::State& state) {
154154
ui32 lower = ++it % 50;
155155
ui32 upper = lower + items;
156156

157-
TCharge(Env.Get(), *(Run.Get())->begin()->Part, Tags, false).Do(lower, upper, keyDefaults, items, Max<ui64>());
157+
CreateCharge(Env.Get(), *(Run.Get())->begin()->Part, Tags, false)->Do(lower, upper, keyDefaults, items, Max<ui64>());
158158
}
159159

160160
state.counters["Touched"] = Env->TouchedCount / it;

ydb/core/tablet_flat/flat_part_charge.h

+6-147
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
#pragma once
22

3-
#include "defs.h"
43
#include "flat_table_part.h"
54
#include "flat_part_iface.h"
6-
#include "flat_part_slice.h"
75
#include "flat_part_index_iter.h"
6+
#include "flat_part_charge_iface.h"
87

98
#include <util/generic/bitmap.h>
109

1110
namespace NKikimr {
1211
namespace NTable {
1312

14-
class TCharge {
13+
class TCharge : public ICharge {
1514
public:
16-
using TCells = NPage::TCells;
1715
using TIter = NPage::TIndex::TIter;
1816
using TDataPage = NPage::TDataPage;
1917
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-
};
2518

2619
TCharge(IPages *env, const TPart &part, TTagsRef tags, bool includeHistory = false)
2720
: Env(env)
@@ -49,131 +42,8 @@ namespace NTable {
4942
}
5043
}
5144

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-
*/
17545
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
17747
{
17848
auto index = Index.TryLoadRaw();
17949
if (!index) {
@@ -199,13 +69,8 @@ namespace NTable {
19969
return DoPrecharge(TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
20070
}
20171

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-
*/
20772
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
20974
{
21075
auto index = Index.TryLoadRaw();
21176
if (!index) {
@@ -236,12 +101,9 @@ namespace NTable {
236101
return DoPrechargeReverse(TCells{}, TCells{}, TIter{}, TIter{}, first, last, startRow, endRow, keyDefaults, itemsLimit, bytesLimit);
237102
}
238103

239-
/**
240-
* Precharges data for rows between max(key1, row1) and min(key2, row2) inclusive
241-
*/
242104
TResult Do(const TCells key1, const TCells key2, const TRowId row1,
243105
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
244-
ui64 bytesLimit) const noexcept
106+
ui64 bytesLimit) const noexcept override
245107
{
246108
auto index = Index.TryLoadRaw();
247109
if (!index) {
@@ -307,12 +169,9 @@ namespace NTable {
307169
return { ready, overshot };
308170
}
309171

310-
/**
311-
* Precharges data for rows between min(key1, row1) and max(key2, row2) inclusive in reverse
312-
*/
313172
TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
314173
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
315-
ui64 bytesLimit) const noexcept
174+
ui64 bytesLimit) const noexcept override
316175
{
317176
auto index = Index.TryLoadRaw();
318177
if (!index) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma once
2+
3+
#include "flat_table_part.h"
4+
#include "flat_part_iface.h"
5+
#include "flat_part_charge_iface.h"
6+
7+
namespace NKikimr::NTable {
8+
9+
class TChargeBTreeIndex : public ICharge {
10+
public:
11+
TChargeBTreeIndex(IPages *env, const TPart &part, TTagsRef tags, bool includeHistory = false) {
12+
Y_UNUSED(env);
13+
Y_UNUSED(part);
14+
Y_UNUSED(tags);
15+
Y_UNUSED(includeHistory);
16+
}
17+
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,
41+
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
42+
ui64 bytesLimit) const noexcept override {
43+
// TODO: implement
44+
Y_UNUSED(key1);
45+
Y_UNUSED(key2);
46+
Y_UNUSED(row1);
47+
Y_UNUSED(row2);
48+
Y_UNUSED(keyDefaults);
49+
Y_UNUSED(itemsLimit);
50+
Y_UNUSED(bytesLimit);
51+
return {true, false};
52+
}
53+
54+
virtual TResult DoReverse(const TCells key1, const TCells key2, const TRowId row1,
55+
const TRowId row2, const TKeyCellDefaults &keyDefaults, ui64 itemsLimit,
56+
ui64 bytesLimit) const noexcept override {
57+
// TODO: implement
58+
Y_UNUSED(key1);
59+
Y_UNUSED(key2);
60+
Y_UNUSED(row1);
61+
Y_UNUSED(row2);
62+
Y_UNUSED(keyDefaults);
63+
Y_UNUSED(itemsLimit);
64+
Y_UNUSED(bytesLimit);
65+
return {true, false};
66+
}
67+
};
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "flat_part_charge_create.h"
2+
#include "flat_part_charge.h"
3+
#include "flat_part_charge_btree_index.h"
4+
5+
namespace NKikimr::NTable {
6+
7+
THolder<ICharge> CreateCharge(IPages *env, const TPart &part, TTagsRef tags, bool includeHistory) {
8+
if (part.IndexPages.BTreeGroups) {
9+
return MakeHolder<TChargeBTreeIndex>(env, part, tags, includeHistory);
10+
} else {
11+
return MakeHolder<TCharge>(env, part, tags, includeHistory);
12+
}
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "flat_part_charge_iface.h"
4+
#include "flat_part_iface.h"
5+
6+
namespace NKikimr::NTable {
7+
8+
THolder<ICharge> CreateCharge(IPages *env, const TPart &part, TTagsRef tags, bool includeHistory = false);
9+
10+
}

0 commit comments

Comments
 (0)