Skip to content

Commit 16b0f8d

Browse files
committed
KIKIMR-19139 Delete TIndex fields from TPart
1 parent 47efa80 commit 16b0f8d

14 files changed

+158
-158
lines changed

ydb/core/tablet_flat/benchmark/b_charge.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ namespace {
6363
TModel()
6464
: Tool(*Mass.Model->Scheme)
6565
{
66-
auto pages = Eggs.At(0)->Index->End() - Eggs.At(0)->Index->Begin();
67-
68-
Y_VERIFY(pages > 120);
66+
Y_VERIFY(NTest::IndexTools::CountMainPages(*Eggs.Lone()) > 120);
6967
}
7068

7169
static NTest::TPartEggs MakeEggs() noexcept

ydb/core/tablet_flat/flat_page_index.h

-24
Original file line numberDiff line numberDiff line change
@@ -255,40 +255,16 @@ namespace NPage {
255255
return 0; /* cannot estimate rows for one page part */
256256
}
257257

258-
TPageId UpperPage() const noexcept
259-
{
260-
return Page.Begin() ? (Page.End() - 1)->GetPageId() + 1 : 0;
261-
}
262-
263-
const TRecord* GetFirstKeyRecord() const noexcept
264-
{
265-
return Page.Record(0);
266-
}
267-
268258
const TRecord* GetLastKeyRecord() const noexcept
269259
{
270260
return LastKey;
271261
}
272262

273-
const TRecord* At(TRecIdx index) const noexcept
274-
{
275-
Y_VERIFY(index <= Page.Count);
276-
auto it = Page.Begin() + index;
277-
return it
278-
? it.GetRecord()
279-
: GetLastKeyRecord();
280-
}
281-
282263
TRowId GetEndRowId() const noexcept
283264
{
284265
return EndRowId;
285266
}
286267

287-
size_t RawSize() const noexcept
288-
{
289-
return Raw.size();
290-
}
291-
292268
private:
293269
TSharedData Raw;
294270
TBlock Page;

ydb/core/tablet_flat/flat_part_index_iter.h

+7
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ class TPartIndexIt {
137137
return Iter.GetRecord();
138138
}
139139

140+
// currently this method is needed for tests only, but it's worth to keep it for future optimizations
141+
const TRecord * GetLastRecord() const {
142+
Y_VERIFY(Index);
143+
Y_VERIFY(Iter, "Should be called only after SeekLast call");
144+
return Index->GetLastKeyRecord();
145+
}
146+
140147
private:
141148
EReady DataOrGone() const {
142149
return Iter ? EReady::Data : EReady::Gone;

ydb/core/tablet_flat/flat_part_loader.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,18 @@ TAutoPtr<NPageCollection::TFetch> TLoader::StageCreatePartView() noexcept
162162
Y_Fail("TPart has small blobs, " << Packs.size() << " page collections");
163163
}
164164

165-
TVector<TSharedData> groupIndexes;
166-
groupIndexes.reserve(GroupIndexesIds.size());
165+
// TODO: stop load indexes
167166
for (auto pageId : GroupIndexesIds) {
168167
auto* page = GetPage(pageId);
169168
if (!page) {
170169
Y_Fail("Missing group index page " << pageId);
171170
}
172-
groupIndexes.emplace_back(*page);
173171
}
174-
175-
TVector<TSharedData> historicIndexes(Reserve(HistoricIndexesIds.size()));
176172
for (auto pageId : HistoricIndexesIds) {
177173
auto* page = GetPage(pageId);
178174
if (!page) {
179175
Y_Fail("Missing historic index page " << pageId);
180176
}
181-
historicIndexes.emplace_back(*page);
182177
}
183178

184179
const auto extra = BlobsLabelFor(Packs[0]->PageCollection->Label());
@@ -194,19 +189,25 @@ TAutoPtr<NPageCollection::TFetch> TLoader::StageCreatePartView() noexcept
194189
groupIndexesIds.push_back(pageId);
195190
}
196191

192+
// TODO: put index size to stat?
193+
// TODO: include history indexes bytes
194+
size_t indexesRawSize = 0;
195+
for (auto indexPage : groupIndexesIds) {
196+
indexesRawSize += GetPageSize(indexPage);
197+
}
198+
197199
auto *partStore = new TPartStore(
198200
Packs.front()->PageCollection->Label(),
199201
{
200202
epoch,
201203
TPartScheme::Parse(*scheme, Rooted),
202-
{ groupIndexesIds, HistoricIndexesIds },
204+
{ std::move(groupIndexesIds), HistoricIndexesIds },
203205
*index,
204206
blobs ? new NPage::TExtBlobs(*blobs, extra) : nullptr,
205207
byKey ? new NPage::TBloom(*byKey) : nullptr,
206208
large ? new NPage::TFrames(*large) : nullptr,
207209
small ? new NPage::TFrames(*small) : nullptr,
208-
std::move(groupIndexes),
209-
std::move(historicIndexes),
210+
indexesRawSize,
210211
MinRowVersion,
211212
MaxRowVersion,
212213
garbageStats ? new NPage::TGarbageStats(*garbageStats) : nullptr,

ydb/core/tablet_flat/flat_part_loader.h

+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ namespace NTable {
145145
return page == Max<TPageId>() ? nullptr : Packs[0]->Lookup(page);
146146
}
147147

148+
size_t GetPageSize(TPageId page) noexcept
149+
{
150+
return Packs[0]->PageCollection->Page(page).Size;
151+
}
152+
148153
void ParseMeta(TArrayRef<const char> plain) noexcept
149154
{
150155
TMemoryInput stream(plain.data(), plain.size());

ydb/core/tablet_flat/flat_stat_part.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TScreenedPartIndexIterator {
5252
for (ui32 group : xrange(size_t(1), Part->GroupsCount)) {
5353
AltGroups.emplace_back(Part.Get(), env, NPage::TGroupId(group));
5454
}
55-
for (ui32 group : xrange(Part->HistoricIndexes.size())) {
55+
for (ui32 group : xrange(Part->HistoricGroupsCount)) {
5656
HistoryGroups.emplace_back(Part.Get(), env, NPage::TGroupId(group, true));
5757
}
5858
}
@@ -158,7 +158,7 @@ class TScreenedPartIndexIterator {
158158
if (IsValid()) {
159159
return Pos.GetRowId();
160160
}
161-
if (TRowId endRowId = Part->Index.GetEndRowId(); endRowId != Max<TRowId>()) {
161+
if (TRowId endRowId = Pos.GetEndRowId(); endRowId != Max<TRowId>()) {
162162
// This would include the last page rows when known
163163
return endRowId;
164164
}

ydb/core/tablet_flat/flat_table_part.h

+2-44
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ namespace NTable {
6161
TIntrusiveConstPtr<NPage::TBloom> ByKey;
6262
TIntrusiveConstPtr<NPage::TFrames> Large;
6363
TIntrusiveConstPtr<NPage::TFrames> Small;
64-
TVector<TSharedData> GroupIndexes;
65-
TVector<TSharedData> HistoricIndexes;
64+
size_t IndexesRawSize;
6665
TRowVersion MinRowVersion;
6766
TRowVersion MaxRowVersion;
6867
TIntrusiveConstPtr<NPage::TGarbageStats> GarbageStats;
@@ -87,29 +86,19 @@ namespace NTable {
8786
, Small(std::move(params.Small))
8887
, IndexPages(std::move(params.IndexPages))
8988
, Index(std::move(params.Index))
90-
, GroupIndexes(
91-
std::make_move_iterator(params.GroupIndexes.begin()),
92-
std::make_move_iterator(params.GroupIndexes.end()))
93-
, HistoricIndexes(
94-
std::make_move_iterator(params.HistoricIndexes.begin()),
95-
std::make_move_iterator(params.HistoricIndexes.end()))
9689
, ByKey(std::move(params.ByKey))
9790
, GarbageStats(std::move(params.GarbageStats))
9891
, TxIdStats(std::move(params.TxIdStats))
9992
, Stat(stat)
10093
, GroupsCount(IndexPages.Groups.size())
10194
, HistoricGroupsCount(IndexPages.Historic.size())
102-
, IndexesRawSize(Index.RawSize() + SumRawSize(GroupIndexes))
95+
, IndexesRawSize(params.IndexesRawSize)
10396
, MinRowVersion(params.MinRowVersion)
10497
, MaxRowVersion(params.MaxRowVersion)
10598
{
10699
Y_VERIFY(Scheme->Groups.size() == GroupsCount,
107100
"Part has scheme with %" PRISZT " groups, but %" PRISZT " indexes",
108101
Scheme->Groups.size(), GroupsCount);
109-
Y_VERIFY(HistoricIndexes.empty() || HistoricIndexes.size() == GroupsCount,
110-
"Part has %" PRISZT " indexes, but %" PRISZT " historic indexes",
111-
GroupsCount, HistoricIndexes.size());
112-
113102
Y_VERIFY(!HistoricGroupsCount || HistoricGroupsCount == GroupsCount,
114103
"Part has %" PRISZT " indexes, but %" PRISZT " historic indexes",
115104
GroupsCount, HistoricGroupsCount);
@@ -141,24 +130,6 @@ namespace NTable {
141130
virtual ui8 GetPageChannel(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0;
142131
virtual ui8 GetPageChannel(ELargeObj lob, ui64 ref) const = 0;
143132

144-
const NPage::TIndex& GetGroupIndex(NPage::TGroupId groupId) const noexcept {
145-
if (!groupId.Historic) {
146-
if (groupId.Index == 0) {
147-
return Index;
148-
} else {
149-
Y_VERIFY(groupId.Index <= GroupIndexes.size(),
150-
"Group index %" PRIu32 " is missing",
151-
groupId.Index);
152-
return GroupIndexes[groupId.Index - 1];
153-
}
154-
} else {
155-
Y_VERIFY(groupId.Index < HistoricIndexes.size(),
156-
"Historic index %" PRIu32 " is missing",
157-
groupId.Index);
158-
return HistoricIndexes[groupId.Index];
159-
}
160-
}
161-
162133
protected:
163134
// Helper for CloneWithEpoch
164135
TPart(const TPart& src, TEpoch epoch)
@@ -170,8 +141,6 @@ namespace NTable {
170141
, Small(src.Small)
171142
, IndexPages(src.IndexPages)
172143
, Index(src.Index)
173-
, GroupIndexes(src.GroupIndexes)
174-
, HistoricIndexes(src.HistoricIndexes)
175144
, ByKey(src.ByKey)
176145
, GarbageStats(src.GarbageStats)
177146
, Stat(src.Stat)
@@ -182,15 +151,6 @@ namespace NTable {
182151
, MaxRowVersion(src.MaxRowVersion)
183152
{ }
184153

185-
private:
186-
static size_t SumRawSize(const TVector<NPage::TIndex>& indexes) {
187-
size_t ret = 0;
188-
for (auto& index : indexes) {
189-
ret += index.RawSize();
190-
}
191-
return ret;
192-
}
193-
194154
public:
195155
const TLogoBlobID Label;
196156
const TEpoch Epoch;
@@ -200,8 +160,6 @@ namespace NTable {
200160
const TIntrusiveConstPtr<NPage::TFrames> Small;
201161
const TIndexPages IndexPages;
202162
const NPage::TIndex Index;
203-
const TVector<NPage::TIndex> GroupIndexes;
204-
const TVector<NPage::TIndex> HistoricIndexes;
205163
const TIntrusiveConstPtr<NPage::TBloom> ByKey;
206164
const TIntrusiveConstPtr<NPage::TGarbageStats> GarbageStats;
207165
const TIntrusiveConstPtr<NPage::TTxIdStatsPage> TxIdStats;

ydb/core/tablet_flat/test/libs/table/test_part.h

+46-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace NTest {
4848

4949
ui64 GetPageSize(NPage::TPageId id, NPage::TGroupId groupId) const override
5050
{
51-
return Store->GetPage(groupId.Index, id)->size();
51+
return Store->GetPageSize(groupId.Index, id);
5252
}
5353

5454
NPage::EPage GetPageType(NPage::TPageId id, NPage::TGroupId groupId) const override
@@ -145,4 +145,49 @@ namespace NTest {
145145

146146
TString DumpPart(const TPartStore&, ui32 depth = 10) noexcept;
147147

148+
namespace IndexTools {
149+
inline size_t CountMainPages(const TPartStore& part) {
150+
size_t result = 0;
151+
152+
TTestEnv env;
153+
TPartIndexIt index(&part, &env, { });
154+
for (size_t i = 0; ; i++) {
155+
auto ready = i == 0 ? index.Seek(0) : index.Next();
156+
if (ready != EReady::Data) {
157+
Y_VERIFY(ready != EReady::Page, "Unexpected page fault");
158+
break;
159+
}
160+
result++;
161+
}
162+
163+
return result;
164+
}
165+
166+
inline TRowId GetEndRowId(const TPartStore& part) {
167+
TTestEnv env;
168+
TPartIndexIt index(&part, &env, { });
169+
return index.GetEndRowId();
170+
}
171+
172+
inline const TPartIndexIt::TRecord * GetLastRecord(const TPartStore& part) {
173+
TTestEnv env;
174+
TPartIndexIt index(&part, &env, { });
175+
Y_VERIFY(index.SeekLast() == EReady::Data);
176+
return index.GetLastRecord();
177+
}
178+
179+
inline const TPartIndexIt::TRecord * GetRecord(const TPartStore& part, TPageId pageId) {
180+
TTestEnv env;
181+
TPartIndexIt index(&part, &env, { });
182+
183+
Y_VERIFY(index.Seek(0) == EReady::Data);
184+
for (TPageId p = 0; p < pageId; p++) {
185+
Y_VERIFY(index.Next() == EReady::Data);
186+
}
187+
188+
Y_VERIFY(index.GetPageId() == pageId);
189+
return index.GetRecord();
190+
}
191+
}
192+
148193
}}}

ydb/core/tablet_flat/test/libs/table/test_store.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace NTest {
3232
TData *ByKey;
3333
TData *Large;
3434
TData *Small;
35-
TVector<TSharedData> GroupIndexes;
36-
TVector<TSharedData> HistoricIndexes;
3735
TData *GarbageStats;
3836
TData *TxIdStats;
3937
};
@@ -63,6 +61,13 @@ namespace NTest {
6361
return &PageCollections.at(room).at(page);
6462
}
6563

64+
size_t GetPageSize(ui32 room, ui32 page) const noexcept
65+
{
66+
Y_VERIFY(room < PageCollections.size(), "Room is out of bounds");
67+
68+
return PageCollections.at(room).at(page).size();
69+
}
70+
6671
NPage::EPage GetPageType(ui32 room, ui32 page) const noexcept
6772
{
6873
Y_VERIFY(room < PageCollections.size(), "Room is out of bounds");
@@ -129,8 +134,6 @@ namespace NTest {
129134
GetPage(MainPageCollection, ByKey),
130135
GetPage(MainPageCollection, Large),
131136
nullptr,
132-
{ },
133-
{ },
134137
nullptr,
135138
nullptr,
136139
};

ydb/core/tablet_flat/test/libs/table/test_writer.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ namespace NTest {
7373

7474
TEpoch epoch = TEpoch(root.GetEpoch());
7575

76+
size_t indexesRawSize = 0;
77+
for (auto indexPage : eggs.IndexGroupsPages) {
78+
indexesRawSize += Store->GetPageSize(0, indexPage);
79+
}
80+
7681
return
7782
new TPartStore(
7883
std::move(Store),
@@ -86,8 +91,7 @@ namespace NTest {
8691
eggs.ByKey ? new TBloom(*eggs.ByKey) : nullptr,
8792
eggs.Large ? new TFrames(*eggs.Large) : nullptr,
8893
eggs.Small ? new TFrames(*eggs.Small) : nullptr,
89-
std::move(eggs.GroupIndexes),
90-
std::move(eggs.HistoricIndexes),
94+
indexesRawSize,
9195
TRowVersion(minRowVersion.GetStep(), minRowVersion.GetTxId()),
9296
TRowVersion(maxRowVersion.GetStep(), maxRowVersion.GetTxId()),
9397
eggs.GarbageStats ? new NPage::TGarbageStats(*eggs.GarbageStats) : nullptr,
@@ -115,30 +119,23 @@ namespace NTest {
115119
indexGroupsPages.push_back(lay.GetIndex());
116120
}
117121

118-
TVector<TSharedData> groupIndexes;
119122
for (ui32 pageId : lay.GetGroupIndexes()) {
120123
indexGroupsPages.push_back(pageId);
121-
groupIndexes.emplace_back(*Store->GetPage(0, pageId));
122124
}
123-
124-
TVector<TSharedData> historicIndexes;
125125
for (ui32 pageId : lay.GetHistoricIndexes()) {
126126
indexHistoricPages.push_back(pageId);
127-
historicIndexes.emplace_back(*Store->GetPage(0, pageId));
128127
}
129128

130129
return {
131130
true /* rooted page collection */,
132-
indexGroupsPages,
133-
indexHistoricPages,
131+
std::move(indexGroupsPages),
132+
std::move(indexHistoricPages),
134133
Store->GetPage(0, lay.HasIndex() ? lay.GetIndex() : undef),
135134
Store->GetPage(0, lay.HasScheme() ? lay.GetScheme() : undef),
136135
Store->GetPage(0, lay.HasGlobs() ? lay.GetGlobs() : undef),
137136
Store->GetPage(0, lay.HasByKey() ? lay.GetByKey() : undef),
138137
Store->GetPage(0, lay.HasLarge() ? lay.GetLarge() : undef),
139138
Store->GetPage(0, lay.HasSmall() ? lay.GetSmall() : undef),
140-
std::move(groupIndexes),
141-
std::move(historicIndexes),
142139
Store->GetPage(0, lay.HasGarbageStats() ? lay.GetGarbageStats() : undef),
143140
Store->GetPage(0, lay.HasTxIdStats() ? lay.GetTxIdStats() : undef),
144141
};

0 commit comments

Comments
 (0)