Skip to content

Commit d96aaa3

Browse files
authored
Check B-Tree index format in loader (#4969)
1 parent 8e7ec08 commit d96aaa3

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

ydb/core/tablet_flat/flat_page_btree_index.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,15 @@ namespace NKikimr::NTable::NPage {
248248
};
249249

250250
public:
251+
// Version = 0 didn't have GroupDataSize field
252+
static const ui16 FormatVersion = 1;
253+
251254
TBtreeIndexNode(TSharedData raw)
252255
: Raw(std::move(raw))
253256
{
254257
const auto data = NPage::TLabelWrapper().Read(Raw, EPage::BTreeIndex);
255258

256-
// Version = 0 didn't have GroupDataSize field
257-
Y_ABORT_UNLESS(data == ECodec::Plain && data.Version == 1);
259+
Y_ABORT_UNLESS(data == ECodec::Plain && data.Version == FormatVersion);
258260

259261
Header = TDeref<const THeader>::At(data.Page.data());
260262
size_t offset = sizeof(THeader);

ydb/core/tablet_flat/flat_page_btree_index_writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace NKikimr::NTable::NPage {
9797
Ptr = buf.mutable_begin();
9898
End = buf.end();
9999

100-
WriteUnaligned<TLabel>(Advance(sizeof(TLabel)), TLabel::Encode(EPage::BTreeIndex, 1, pageSize));
100+
WriteUnaligned<TLabel>(Advance(sizeof(TLabel)), TLabel::Encode(EPage::BTreeIndex, TBtreeIndexNode::FormatVersion, pageSize));
101101

102102
auto &header = Place<THeader>();
103103
header.KeysCount = Keys.size();

ydb/core/tablet_flat/flat_part_loader.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ void TLoader::StageParseMeta() noexcept
7979

8080
BTreeGroupIndexes.clear();
8181
BTreeHistoricIndexes.clear();
82-
for (bool history : {false, true}) {
83-
for (const auto &meta : history ? layout.GetBTreeHistoricIndexes() : layout.GetBTreeGroupIndexes()) {
84-
NPage::TBtreeIndexMeta converted{{
85-
meta.GetRootPageId(),
86-
meta.GetRowCount(),
87-
meta.GetDataSize(),
88-
meta.GetGroupDataSize(),
89-
meta.GetErasedRowCount()},
90-
meta.GetLevelCount(),
91-
meta.GetIndexSize()};
92-
(history ? BTreeHistoricIndexes : BTreeGroupIndexes).push_back(converted);
82+
if (layout.HasBTreeIndexesFormatVersion() && layout.GetBTreeIndexesFormatVersion() == NPage::TBtreeIndexNode::FormatVersion) {
83+
for (bool history : {false, true}) {
84+
for (const auto &meta : history ? layout.GetBTreeHistoricIndexes() : layout.GetBTreeGroupIndexes()) {
85+
NPage::TBtreeIndexMeta converted{{
86+
meta.GetRootPageId(),
87+
meta.GetRowCount(),
88+
meta.GetDataSize(),
89+
meta.GetGroupDataSize(),
90+
meta.GetErasedRowCount()},
91+
meta.GetLevelCount(),
92+
meta.GetIndexSize()};
93+
(history ? BTreeHistoricIndexes : BTreeGroupIndexes).push_back(converted);
94+
}
9395
}
9496
}
9597

ydb/core/tablet_flat/flat_part_writer.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,16 +667,19 @@ namespace NTable {
667667
lay->AddHistoricIndexes(page);
668668
}
669669

670-
for (bool history : {false, true}) {
671-
for (auto meta : history ? Current.BTreeHistoricIndexes : Current.BTreeGroupIndexes) {
672-
auto m = history ? lay->AddBTreeHistoricIndexes() : lay->AddBTreeGroupIndexes();
673-
m->SetRootPageId(meta.PageId);
674-
m->SetLevelCount(meta.LevelCount);
675-
m->SetIndexSize(meta.IndexSize);
676-
m->SetDataSize(meta.DataSize);
677-
m->SetGroupDataSize(meta.GroupDataSize);
678-
m->SetRowCount(meta.RowCount);
679-
m->SetErasedRowCount(meta.ErasedRowCount);
670+
if (WriteBTreeIndex) {
671+
lay->SetBTreeIndexesFormatVersion(NPage::TBtreeIndexNode::FormatVersion);
672+
for (bool history : {false, true}) {
673+
for (auto meta : history ? Current.BTreeHistoricIndexes : Current.BTreeGroupIndexes) {
674+
auto m = history ? lay->AddBTreeHistoricIndexes() : lay->AddBTreeGroupIndexes();
675+
m->SetRootPageId(meta.PageId);
676+
m->SetLevelCount(meta.LevelCount);
677+
m->SetIndexSize(meta.IndexSize);
678+
m->SetDataSize(meta.DataSize);
679+
m->SetGroupDataSize(meta.GroupDataSize);
680+
m->SetRowCount(meta.RowCount);
681+
m->SetErasedRowCount(meta.ErasedRowCount);
682+
}
680683
}
681684
}
682685

ydb/core/tablet_flat/protos/flat_table_part.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ message TLayout {
4646
optional uint32 TxIdStats = 10; // EPage::TxIdStats for uncommitted deltas
4747
repeated TBTreeIndexMeta BTreeGroupIndexes = 11;
4848
repeated TBTreeIndexMeta BTreeHistoricIndexes = 12;
49+
optional uint32 BTreeIndexesFormatVersion = 13;
4950
}
5051

5152
message TStat {

0 commit comments

Comments
 (0)