diff options
author | kungasc <[email protected]> | 2023-09-29 17:11:37 +0300 |
---|---|---|
committer | kungasc <[email protected]> | 2023-09-29 17:48:48 +0300 |
commit | 16b0f8d9f0fba37ed662509e8f20577aa073ca48 (patch) | |
tree | 1d140dad93c1d6c55248feb56144f7216ace28a5 | |
parent | 47efa805f712db541a1a84d861567ef949a88afa (diff) |
KIKIMR-19139 Delete TIndex fields from TPart
-rw-r--r-- | ydb/core/tablet_flat/benchmark/b_charge.cpp | 4 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_page_index.h | 24 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_part_index_iter.h | 7 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_part_loader.cpp | 19 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_part_loader.h | 5 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_stat_part.h | 4 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_table_part.h | 46 | ||||
-rw-r--r-- | ydb/core/tablet_flat/test/libs/table/test_part.h | 47 | ||||
-rw-r--r-- | ydb/core/tablet_flat/test/libs/table/test_store.h | 11 | ||||
-rw-r--r-- | ydb/core/tablet_flat/test/libs/table/test_writer.h | 19 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_charge.cpp | 16 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_compaction_multi.cpp | 7 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_part.cpp | 42 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_slice_loader.cpp | 65 |
14 files changed, 158 insertions, 158 deletions
diff --git a/ydb/core/tablet_flat/benchmark/b_charge.cpp b/ydb/core/tablet_flat/benchmark/b_charge.cpp index 203ca0b9027..793cbae77a7 100644 --- a/ydb/core/tablet_flat/benchmark/b_charge.cpp +++ b/ydb/core/tablet_flat/benchmark/b_charge.cpp @@ -63,9 +63,7 @@ namespace { TModel() : Tool(*Mass.Model->Scheme) { - auto pages = Eggs.At(0)->Index->End() - Eggs.At(0)->Index->Begin(); - - Y_VERIFY(pages > 120); + Y_VERIFY(NTest::IndexTools::CountMainPages(*Eggs.Lone()) > 120); } static NTest::TPartEggs MakeEggs() noexcept diff --git a/ydb/core/tablet_flat/flat_page_index.h b/ydb/core/tablet_flat/flat_page_index.h index 1151120cd8f..c1dae9b6e36 100644 --- a/ydb/core/tablet_flat/flat_page_index.h +++ b/ydb/core/tablet_flat/flat_page_index.h @@ -255,40 +255,16 @@ namespace NPage { return 0; /* cannot estimate rows for one page part */ } - TPageId UpperPage() const noexcept - { - return Page.Begin() ? (Page.End() - 1)->GetPageId() + 1 : 0; - } - - const TRecord* GetFirstKeyRecord() const noexcept - { - return Page.Record(0); - } - const TRecord* GetLastKeyRecord() const noexcept { return LastKey; } - const TRecord* At(TRecIdx index) const noexcept - { - Y_VERIFY(index <= Page.Count); - auto it = Page.Begin() + index; - return it - ? it.GetRecord() - : GetLastKeyRecord(); - } - TRowId GetEndRowId() const noexcept { return EndRowId; } - size_t RawSize() const noexcept - { - return Raw.size(); - } - private: TSharedData Raw; TBlock Page; diff --git a/ydb/core/tablet_flat/flat_part_index_iter.h b/ydb/core/tablet_flat/flat_part_index_iter.h index 07e886e497b..718ac87f67b 100644 --- a/ydb/core/tablet_flat/flat_part_index_iter.h +++ b/ydb/core/tablet_flat/flat_part_index_iter.h @@ -137,6 +137,13 @@ public: return Iter.GetRecord(); } + // currently this method is needed for tests only, but it's worth to keep it for future optimizations + const TRecord * GetLastRecord() const { + Y_VERIFY(Index); + Y_VERIFY(Iter, "Should be called only after SeekLast call"); + return Index->GetLastKeyRecord(); + } + private: EReady DataOrGone() const { return Iter ? EReady::Data : EReady::Gone; diff --git a/ydb/core/tablet_flat/flat_part_loader.cpp b/ydb/core/tablet_flat/flat_part_loader.cpp index 48b6f979ef4..e6f33820d06 100644 --- a/ydb/core/tablet_flat/flat_part_loader.cpp +++ b/ydb/core/tablet_flat/flat_part_loader.cpp @@ -162,23 +162,18 @@ TAutoPtr<NPageCollection::TFetch> TLoader::StageCreatePartView() noexcept Y_Fail("TPart has small blobs, " << Packs.size() << " page collections"); } - TVector<TSharedData> groupIndexes; - groupIndexes.reserve(GroupIndexesIds.size()); + // TODO: stop load indexes for (auto pageId : GroupIndexesIds) { auto* page = GetPage(pageId); if (!page) { Y_Fail("Missing group index page " << pageId); } - groupIndexes.emplace_back(*page); } - - TVector<TSharedData> historicIndexes(Reserve(HistoricIndexesIds.size())); for (auto pageId : HistoricIndexesIds) { auto* page = GetPage(pageId); if (!page) { Y_Fail("Missing historic index page " << pageId); } - historicIndexes.emplace_back(*page); } const auto extra = BlobsLabelFor(Packs[0]->PageCollection->Label()); @@ -194,19 +189,25 @@ TAutoPtr<NPageCollection::TFetch> TLoader::StageCreatePartView() noexcept groupIndexesIds.push_back(pageId); } + // TODO: put index size to stat? + // TODO: include history indexes bytes + size_t indexesRawSize = 0; + for (auto indexPage : groupIndexesIds) { + indexesRawSize += GetPageSize(indexPage); + } + auto *partStore = new TPartStore( Packs.front()->PageCollection->Label(), { epoch, TPartScheme::Parse(*scheme, Rooted), - { groupIndexesIds, HistoricIndexesIds }, + { std::move(groupIndexesIds), HistoricIndexesIds }, *index, blobs ? new NPage::TExtBlobs(*blobs, extra) : nullptr, byKey ? new NPage::TBloom(*byKey) : nullptr, large ? new NPage::TFrames(*large) : nullptr, small ? new NPage::TFrames(*small) : nullptr, - std::move(groupIndexes), - std::move(historicIndexes), + indexesRawSize, MinRowVersion, MaxRowVersion, garbageStats ? new NPage::TGarbageStats(*garbageStats) : nullptr, diff --git a/ydb/core/tablet_flat/flat_part_loader.h b/ydb/core/tablet_flat/flat_part_loader.h index 32ee5de7f3b..1d6d2c7fa20 100644 --- a/ydb/core/tablet_flat/flat_part_loader.h +++ b/ydb/core/tablet_flat/flat_part_loader.h @@ -145,6 +145,11 @@ namespace NTable { return page == Max<TPageId>() ? nullptr : Packs[0]->Lookup(page); } + size_t GetPageSize(TPageId page) noexcept + { + return Packs[0]->PageCollection->Page(page).Size; + } + void ParseMeta(TArrayRef<const char> plain) noexcept { TMemoryInput stream(plain.data(), plain.size()); diff --git a/ydb/core/tablet_flat/flat_stat_part.h b/ydb/core/tablet_flat/flat_stat_part.h index b0e036768b6..89e518e6778 100644 --- a/ydb/core/tablet_flat/flat_stat_part.h +++ b/ydb/core/tablet_flat/flat_stat_part.h @@ -52,7 +52,7 @@ public: for (ui32 group : xrange(size_t(1), Part->GroupsCount)) { AltGroups.emplace_back(Part.Get(), env, NPage::TGroupId(group)); } - for (ui32 group : xrange(Part->HistoricIndexes.size())) { + for (ui32 group : xrange(Part->HistoricGroupsCount)) { HistoryGroups.emplace_back(Part.Get(), env, NPage::TGroupId(group, true)); } } @@ -158,7 +158,7 @@ private: if (IsValid()) { return Pos.GetRowId(); } - if (TRowId endRowId = Part->Index.GetEndRowId(); endRowId != Max<TRowId>()) { + if (TRowId endRowId = Pos.GetEndRowId(); endRowId != Max<TRowId>()) { // This would include the last page rows when known return endRowId; } diff --git a/ydb/core/tablet_flat/flat_table_part.h b/ydb/core/tablet_flat/flat_table_part.h index 6aeb6f15a55..51c1a998402 100644 --- a/ydb/core/tablet_flat/flat_table_part.h +++ b/ydb/core/tablet_flat/flat_table_part.h @@ -61,8 +61,7 @@ namespace NTable { TIntrusiveConstPtr<NPage::TBloom> ByKey; TIntrusiveConstPtr<NPage::TFrames> Large; TIntrusiveConstPtr<NPage::TFrames> Small; - TVector<TSharedData> GroupIndexes; - TVector<TSharedData> HistoricIndexes; + size_t IndexesRawSize; TRowVersion MinRowVersion; TRowVersion MaxRowVersion; TIntrusiveConstPtr<NPage::TGarbageStats> GarbageStats; @@ -87,29 +86,19 @@ namespace NTable { , Small(std::move(params.Small)) , IndexPages(std::move(params.IndexPages)) , Index(std::move(params.Index)) - , GroupIndexes( - std::make_move_iterator(params.GroupIndexes.begin()), - std::make_move_iterator(params.GroupIndexes.end())) - , HistoricIndexes( - std::make_move_iterator(params.HistoricIndexes.begin()), - std::make_move_iterator(params.HistoricIndexes.end())) , ByKey(std::move(params.ByKey)) , GarbageStats(std::move(params.GarbageStats)) , TxIdStats(std::move(params.TxIdStats)) , Stat(stat) , GroupsCount(IndexPages.Groups.size()) , HistoricGroupsCount(IndexPages.Historic.size()) - , IndexesRawSize(Index.RawSize() + SumRawSize(GroupIndexes)) + , IndexesRawSize(params.IndexesRawSize) , MinRowVersion(params.MinRowVersion) , MaxRowVersion(params.MaxRowVersion) { Y_VERIFY(Scheme->Groups.size() == GroupsCount, "Part has scheme with %" PRISZT " groups, but %" PRISZT " indexes", Scheme->Groups.size(), GroupsCount); - Y_VERIFY(HistoricIndexes.empty() || HistoricIndexes.size() == GroupsCount, - "Part has %" PRISZT " indexes, but %" PRISZT " historic indexes", - GroupsCount, HistoricIndexes.size()); - Y_VERIFY(!HistoricGroupsCount || HistoricGroupsCount == GroupsCount, "Part has %" PRISZT " indexes, but %" PRISZT " historic indexes", GroupsCount, HistoricGroupsCount); @@ -141,24 +130,6 @@ namespace NTable { virtual ui8 GetPageChannel(NPage::TPageId id, NPage::TGroupId groupId = { }) const = 0; virtual ui8 GetPageChannel(ELargeObj lob, ui64 ref) const = 0; - const NPage::TIndex& GetGroupIndex(NPage::TGroupId groupId) const noexcept { - if (!groupId.Historic) { - if (groupId.Index == 0) { - return Index; - } else { - Y_VERIFY(groupId.Index <= GroupIndexes.size(), - "Group index %" PRIu32 " is missing", - groupId.Index); - return GroupIndexes[groupId.Index - 1]; - } - } else { - Y_VERIFY(groupId.Index < HistoricIndexes.size(), - "Historic index %" PRIu32 " is missing", - groupId.Index); - return HistoricIndexes[groupId.Index]; - } - } - protected: // Helper for CloneWithEpoch TPart(const TPart& src, TEpoch epoch) @@ -170,8 +141,6 @@ namespace NTable { , Small(src.Small) , IndexPages(src.IndexPages) , Index(src.Index) - , GroupIndexes(src.GroupIndexes) - , HistoricIndexes(src.HistoricIndexes) , ByKey(src.ByKey) , GarbageStats(src.GarbageStats) , Stat(src.Stat) @@ -182,15 +151,6 @@ namespace NTable { , MaxRowVersion(src.MaxRowVersion) { } - private: - static size_t SumRawSize(const TVector<NPage::TIndex>& indexes) { - size_t ret = 0; - for (auto& index : indexes) { - ret += index.RawSize(); - } - return ret; - } - public: const TLogoBlobID Label; const TEpoch Epoch; @@ -200,8 +160,6 @@ namespace NTable { const TIntrusiveConstPtr<NPage::TFrames> Small; const TIndexPages IndexPages; const NPage::TIndex Index; - const TVector<NPage::TIndex> GroupIndexes; - const TVector<NPage::TIndex> HistoricIndexes; const TIntrusiveConstPtr<NPage::TBloom> ByKey; const TIntrusiveConstPtr<NPage::TGarbageStats> GarbageStats; const TIntrusiveConstPtr<NPage::TTxIdStatsPage> TxIdStats; diff --git a/ydb/core/tablet_flat/test/libs/table/test_part.h b/ydb/core/tablet_flat/test/libs/table/test_part.h index 1690af9a9a3..6050408aa2a 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_part.h +++ b/ydb/core/tablet_flat/test/libs/table/test_part.h @@ -48,7 +48,7 @@ namespace NTest { ui64 GetPageSize(NPage::TPageId id, NPage::TGroupId groupId) const override { - return Store->GetPage(groupId.Index, id)->size(); + return Store->GetPageSize(groupId.Index, id); } NPage::EPage GetPageType(NPage::TPageId id, NPage::TGroupId groupId) const override @@ -145,4 +145,49 @@ namespace NTest { TString DumpPart(const TPartStore&, ui32 depth = 10) noexcept; + namespace IndexTools { + inline size_t CountMainPages(const TPartStore& part) { + size_t result = 0; + + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + for (size_t i = 0; ; i++) { + auto ready = i == 0 ? index.Seek(0) : index.Next(); + if (ready != EReady::Data) { + Y_VERIFY(ready != EReady::Page, "Unexpected page fault"); + break; + } + result++; + } + + return result; + } + + inline TRowId GetEndRowId(const TPartStore& part) { + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + return index.GetEndRowId(); + } + + inline const TPartIndexIt::TRecord * GetLastRecord(const TPartStore& part) { + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + Y_VERIFY(index.SeekLast() == EReady::Data); + return index.GetLastRecord(); + } + + inline const TPartIndexIt::TRecord * GetRecord(const TPartStore& part, TPageId pageId) { + TTestEnv env; + TPartIndexIt index(&part, &env, { }); + + Y_VERIFY(index.Seek(0) == EReady::Data); + for (TPageId p = 0; p < pageId; p++) { + Y_VERIFY(index.Next() == EReady::Data); + } + + Y_VERIFY(index.GetPageId() == pageId); + return index.GetRecord(); + } + } + }}} diff --git a/ydb/core/tablet_flat/test/libs/table/test_store.h b/ydb/core/tablet_flat/test/libs/table/test_store.h index 9bcc2bd6148..0b6f6c9c555 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_store.h +++ b/ydb/core/tablet_flat/test/libs/table/test_store.h @@ -32,8 +32,6 @@ namespace NTest { TData *ByKey; TData *Large; TData *Small; - TVector<TSharedData> GroupIndexes; - TVector<TSharedData> HistoricIndexes; TData *GarbageStats; TData *TxIdStats; }; @@ -63,6 +61,13 @@ namespace NTest { return &PageCollections.at(room).at(page); } + size_t GetPageSize(ui32 room, ui32 page) const noexcept + { + Y_VERIFY(room < PageCollections.size(), "Room is out of bounds"); + + return PageCollections.at(room).at(page).size(); + } + NPage::EPage GetPageType(ui32 room, ui32 page) const noexcept { Y_VERIFY(room < PageCollections.size(), "Room is out of bounds"); @@ -129,8 +134,6 @@ namespace NTest { GetPage(MainPageCollection, ByKey), GetPage(MainPageCollection, Large), nullptr, - { }, - { }, nullptr, nullptr, }; diff --git a/ydb/core/tablet_flat/test/libs/table/test_writer.h b/ydb/core/tablet_flat/test/libs/table/test_writer.h index e5d6171fae8..e57925312a1 100644 --- a/ydb/core/tablet_flat/test/libs/table/test_writer.h +++ b/ydb/core/tablet_flat/test/libs/table/test_writer.h @@ -73,6 +73,11 @@ namespace NTest { TEpoch epoch = TEpoch(root.GetEpoch()); + size_t indexesRawSize = 0; + for (auto indexPage : eggs.IndexGroupsPages) { + indexesRawSize += Store->GetPageSize(0, indexPage); + } + return new TPartStore( std::move(Store), @@ -86,8 +91,7 @@ namespace NTest { eggs.ByKey ? new TBloom(*eggs.ByKey) : nullptr, eggs.Large ? new TFrames(*eggs.Large) : nullptr, eggs.Small ? new TFrames(*eggs.Small) : nullptr, - std::move(eggs.GroupIndexes), - std::move(eggs.HistoricIndexes), + indexesRawSize, TRowVersion(minRowVersion.GetStep(), minRowVersion.GetTxId()), TRowVersion(maxRowVersion.GetStep(), maxRowVersion.GetTxId()), eggs.GarbageStats ? new NPage::TGarbageStats(*eggs.GarbageStats) : nullptr, @@ -115,30 +119,23 @@ namespace NTest { indexGroupsPages.push_back(lay.GetIndex()); } - TVector<TSharedData> groupIndexes; for (ui32 pageId : lay.GetGroupIndexes()) { indexGroupsPages.push_back(pageId); - groupIndexes.emplace_back(*Store->GetPage(0, pageId)); } - - TVector<TSharedData> historicIndexes; for (ui32 pageId : lay.GetHistoricIndexes()) { indexHistoricPages.push_back(pageId); - historicIndexes.emplace_back(*Store->GetPage(0, pageId)); } return { true /* rooted page collection */, - indexGroupsPages, - indexHistoricPages, + std::move(indexGroupsPages), + std::move(indexHistoricPages), Store->GetPage(0, lay.HasIndex() ? lay.GetIndex() : undef), Store->GetPage(0, lay.HasScheme() ? lay.GetScheme() : undef), Store->GetPage(0, lay.HasGlobs() ? lay.GetGlobs() : undef), Store->GetPage(0, lay.HasByKey() ? lay.GetByKey() : undef), Store->GetPage(0, lay.HasLarge() ? lay.GetLarge() : undef), Store->GetPage(0, lay.HasSmall() ? lay.GetSmall() : undef), - std::move(groupIndexes), - std::move(historicIndexes), Store->GetPage(0, lay.HasGarbageStats() ? lay.GetGarbageStats() : undef), Store->GetPage(0, lay.HasTxIdStats() ? lay.GetTxIdStats() : undef), }; diff --git a/ydb/core/tablet_flat/ut/ut_charge.cpp b/ydb/core/tablet_flat/ut/ut_charge.cpp index fceb7152b09..af2f98755a0 100644 --- a/ydb/core/tablet_flat/ut/ut_charge.cpp +++ b/ydb/core/tablet_flat/ut/ut_charge.cpp @@ -104,9 +104,7 @@ namespace { , Eggs(MakeEggs(groups, history)) , Tool(*Mass.Model->Scheme) { - auto pages = Eggs.Lone()->Index->End() - Eggs.Lone()->Index->Begin(); - - UNIT_ASSERT(pages == 9); + UNIT_ASSERT(NTest::IndexTools::CountMainPages(*Eggs.Lone()) == 9); } NTest::TPartEggs MakeEggs(bool groups, bool history) noexcept @@ -335,9 +333,15 @@ namespace { } TMap<ui64, ui64> absoluteId; - auto groupIndex = Eggs.Lone()->GetGroupIndex(groupId); - for (auto it = groupIndex->Begin(); it != groupIndex->End(); it++) { - absoluteId[absoluteId.size()] = it->GetPageId(); + NTest::TTestEnv env; + TPartIndexIt groupIndex(Eggs.Lone().Get(), &env, groupId); + for (size_t i = 0; ; i++) { + auto ready = i == 0 ? groupIndex.Seek(0) : groupIndex.Next(); + if (ready != EReady::Data) { + Y_VERIFY(ready != EReady::Page); + break; + } + absoluteId[absoluteId.size()] = groupIndex.GetPageId(); } TSet<TPageId> actualValue; diff --git a/ydb/core/tablet_flat/ut/ut_compaction_multi.cpp b/ydb/core/tablet_flat/ut/ut_compaction_multi.cpp index beb115c5c02..27617afa4b8 100644 --- a/ydb/core/tablet_flat/ut/ut_compaction_multi.cpp +++ b/ydb/core/tablet_flat/ut/ut_compaction_multi.cpp @@ -55,9 +55,10 @@ Y_UNIT_TEST_SUITE(TCompactionMulti) { UNIT_ASSERT_VALUES_EQUAL(fullPageSize, initialConf.Groups[0].PageSize); // Verify the last page contains a single row - auto lastPage = initialPart->Index->End(); - UNIT_ASSERT_C(--lastPage, "Unexpected failure to find the last index page"); - auto count = initialPart->Index.GetEndRowId() - lastPage->GetRowId(); + TTestEnv env; + TPartIndexIt iter(initialPart, &env, { }); + Y_VERIFY(iter.SeekLast() == EReady::Data, "Unexpected failure to find the last index page"); + auto count = iter.GetEndRowId() - iter.GetRowId(); UNIT_ASSERT_C(count == 1, "Unexpected " << count << " rows on the last page"); } diff --git a/ydb/core/tablet_flat/ut/ut_part.cpp b/ydb/core/tablet_flat/ut/ut_part.cpp index 7eaac59bf97..2e45cd1f420 100644 --- a/ydb/core/tablet_flat/ut/ut_part.cpp +++ b/ydb/core/tablet_flat/ut/ut_part.cpp @@ -182,10 +182,10 @@ Y_UNIT_TEST_SUITE(TPart) { /* Verify part has correct first and last key in the index */ const auto part = (*wrap).Eggs.Lone(); - UNIT_ASSERT_VALUES_EQUAL(part->Index.Rows(), 2u); + UNIT_ASSERT_VALUES_EQUAL(IndexTools::GetEndRowId(*part), 2u); const NPage::TCompare<NPage::TIndex::TRecord> cmp(part->Scheme->Groups[0].ColsKeyIdx, *(*lay).Keys); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*part->Index.GetFirstKeyRecord(), TRowTool(*lay).KeyCells(foo)), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*part->Index.GetLastKeyRecord(), TRowTool(*lay).KeyCells(bar)), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*part, 0), TRowTool(*lay).KeyCells(foo)), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetLastRecord(*part), TRowTool(*lay).KeyCells(bar)), 0); DumpPart(*(*wrap).Eggs.Lone(), 10); } @@ -380,7 +380,7 @@ Y_UNIT_TEST_SUITE(TPart) { UNIT_ASSERT_C(Eggs0().Parts.size() == 1, "Eggs0 has " << Eggs0().Parts.size() << "p"); auto &part = *Eggs0().Lone(); - auto pages = part.Index->End() - part.Index->Begin(); + auto pages = IndexTools::CountMainPages(part); auto minIndex = PageConf().Groups.at(0).IndexMin * 8; auto cWidth = [](const NPage::TFrames *frames, ui32 span) -> ui32 { @@ -401,7 +401,7 @@ Y_UNIT_TEST_SUITE(TPart) { /*_ Ensure that produced part has enough pages for code coverage and index grow algorithm in data pages writer has been triggered. */ - UNIT_ASSERT(pages > 100 && part.Index.RawSize() >= minIndex); + UNIT_ASSERT(pages > 100 && part.GetPageSize(part.IndexPages.Groups[0], { }) >= minIndex); { /*_ Ensure that part has some external blobs written to room 1 */ auto one = Eggs0().Lone()->Blobs->Total(); @@ -426,10 +426,10 @@ Y_UNIT_TEST_SUITE(TPart) { } { /*_ Check that the last key matches in the index */ - UNIT_ASSERT_VALUES_EQUAL(part.Index.Rows(), Mass0().Saved.Size()); + UNIT_ASSERT_VALUES_EQUAL(IndexTools::GetEndRowId(part), Mass0().Saved.Size()); const NPage::TCompare<NPage::TIndex::TRecord> cmp(part.Scheme->Groups[0].ColsKeyIdx, *Eggs0().Scheme->Keys); auto lastKey = TRowTool(*Eggs0().Scheme).KeyCells(Mass0().Saved[Mass0().Saved.Size()-1]); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*part.Index.GetLastKeyRecord(), lastKey), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetLastRecord(part), lastKey), 0); } { /*_ Check that part has correct number of slices */ @@ -701,11 +701,11 @@ Y_UNIT_TEST_SUITE(TPart) { const auto part = (*wrap).Eggs.Lone(); const NPage::TCompare<NPage::TIndex::TRecord> cmp(part->Scheme->Groups[0].ColsKeyIdx, *(*lay).Keys); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*part->Index->Begin(), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, prefix + "aaa"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(part->Index->Begin() + 1), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, prefix + "b"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(part->Index->Begin() + 2), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, nullptr))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(part->Index->Begin() + 3), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, prefix + "ccx"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*part->Index.GetLastKeyRecord(), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, prefix + "cxz"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*part, 0), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, prefix + "aaa"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*part, 1), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, prefix + "b"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*part, 2), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, nullptr))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*part, 3), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, prefix + "ccx"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetLastRecord(*part), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, prefix + "cxz"))), 0); } Y_UNIT_TEST(CutKeys_Seek) @@ -762,11 +762,11 @@ Y_UNIT_TEST_SUITE(TPart) { UNIT_ASSERT_GT(fullPart->IndexesRawSize, cutPart->IndexesRawSize); const NPage::TCompare<NPage::TIndex::TRecord> cmp(cutPart->Scheme->Groups[0].ColsKeyIdx, *(*lay).Keys); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*cutPart->Index->Begin(), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, "aaa"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(cutPart->Index->Begin() + 1), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, "b"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(cutPart->Index->Begin() + 2), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, nullptr))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*(cutPart->Index->Begin() + 3), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, "ccx"))), 0); - UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*cutPart->Index.GetLastKeyRecord(), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, "cxz"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*cutPart, 0), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, "aaa"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*cutPart, 1), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(1u, "b"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*cutPart, 2), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, nullptr))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetRecord(*cutPart, 3), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, "ccx"))), 0); + UNIT_ASSERT_VALUES_EQUAL(cmp.Compare(*IndexTools::GetLastRecord(*cutPart), TRowTool(*lay).KeyCells(*TSchemedCookRow(*lay).Col(2u, "cxz"))), 0); for (auto r : fullRows) { cutWrap.Has(*TSchemedCookRow(*lay).Col(r.first, r.second)); @@ -951,11 +951,11 @@ Y_UNIT_TEST_SUITE(TPart) { slice.FirstInclusive = true; slice.FirstRowId = rowId; if (rowId > 0) - slice.FirstKey = getKey(cutPartTmp->Index.At(slice.FirstRowId)); + slice.FirstKey = getKey(IndexTools::GetRecord(*cutPartTmp, slice.FirstRowId)); slice.LastInclusive = false; slice.LastRowId = rowId + RandomNumber<ui32>(2) + 1; if (slice.LastRowId < fullRows.size()) - slice.LastKey = getKey(cutPartTmp->Index.At(slice.LastRowId)); + slice.LastKey = getKey(IndexTools::GetRecord(*cutPartTmp, slice.LastRowId)); slices->push_back(slice); rowId = slice.LastRowId; } @@ -1043,7 +1043,7 @@ Y_UNIT_TEST_SUITE(TPart) { Cerr << DumpPart(*part, 2) << Endl; - TString actual((part->Index->Begin() + 1).GetRecord()->Cell(part->Scheme->Groups[0].ColsKeyIdx[0]).AsBuf()); + TString actual(IndexTools::GetRecord(*part, 1)->Cell(part->Scheme->Groups[0].ColsKeyIdx[0]).AsBuf()); UNIT_ASSERT_VALUES_EQUAL_C(actual, expected, testId << ": '" << a << "', '" << b << "'"); }; @@ -1150,7 +1150,7 @@ Y_UNIT_TEST_SUITE(TPart) { Cerr << DumpPart(*part, 2) << Endl; - TString actual((part->Index->Begin() + 1).GetRecord()->Cell(part->Scheme->Groups[0].ColsKeyIdx[0]).AsBuf()); + TString actual(IndexTools::GetRecord(*part, 1)->Cell(part->Scheme->Groups[0].ColsKeyIdx[0]).AsBuf()); UNIT_ASSERT_VALUES_EQUAL_C(actual, expected, testId << ": '" << a << "', '" << b << "'"); }; diff --git a/ydb/core/tablet_flat/ut/ut_slice_loader.cpp b/ydb/core/tablet_flat/ut/ut_slice_loader.cpp index 0ba12913ed9..9122a0b0337 100644 --- a/ydb/core/tablet_flat/ut/ut_slice_loader.cpp +++ b/ydb/core/tablet_flat/ut/ut_slice_loader.cpp @@ -16,6 +16,7 @@ namespace NKikimr { namespace NTable { +using namespace NTest; using TPageCollectionProtoHelper = NTabletFlatExecutor::TPageCollectionProtoHelper; using TCache = NTabletFlatExecutor::TPrivatePageCache::TInfo; @@ -194,12 +195,12 @@ Y_UNIT_TEST_SUITE(TPartSliceLoader) { for (int startOff = 0; startOff < 5; startOff++) { for (int endOff = -5; endOff < 5; endOff++) { TVector<TScreen::THole> holes; - holes.emplace_back(Part0()->Index->Begin()->GetRowId() + startOff, Part0()->Index.GetEndRowId() + endOff); + holes.emplace_back(IndexTools::GetRecord(*Part0(), 0)->GetRowId() + startOff, IndexTools::GetEndRowId(*Part0()) + endOff); TIntrusiveConstPtr<TScreen> screen = new TScreen(std::move(holes)); auto result = RunLoaderTest(Part0(), screen); UNIT_ASSERT_VALUES_EQUAL_C(result.Pages, 3, // index + first + last - "Restoring slice [" << startOff << ", " << Part0()->Index.GetEndRowId() + endOff << "] bounds needed " + "Restoring slice [" << startOff << ", " << IndexTools::GetEndRowId(*Part0()) + endOff << "] bounds needed " << result.Pages << " extra pages"); } } @@ -210,22 +211,23 @@ Y_UNIT_TEST_SUITE(TPartSliceLoader) { { // Construct screen from every index page TVector<TScreen::THole> holes; - auto index = Part0()->Index->Begin(); - while (index) { - if (auto next = index + 1) { - holes.emplace_back(index->GetRowId(), next->GetRowId()); - index = next; - } else { - holes.emplace_back(index->GetRowId(), Max<TRowId>()); - break; + TTestEnv env; + TPartIndexIt index(&*Part0(), &env, { }); + Y_VERIFY(index.Seek(0) == EReady::Data); + while (index.IsValid()) { + auto from = index.GetRowId(); + auto to = Max<TRowId>(); + if (index.Next() == EReady::Data) { + to = index.GetRowId(); } + holes.emplace_back(from, to); } - UNIT_ASSERT_C(holes.size() == Part0()->Index->Count, + UNIT_ASSERT_C(holes.size() == IndexTools::CountMainPages(*Part0()), "Generated screen has " << holes.size() << " intervals"); screen = new TScreen(std::move(holes)); } auto result = RunLoaderTest(Part0(), screen); - UNIT_ASSERT_VALUES_EQUAL_C(result.Pages, 1 + Part0()->Index->End().End(), // index + all data pages + UNIT_ASSERT_VALUES_EQUAL_C(result.Pages, 1 + IndexTools::CountMainPages(*Part0()), // index + all data pages "Restoring slice bounds needed " << result.Pages << " extra pages"); } @@ -234,23 +236,25 @@ Y_UNIT_TEST_SUITE(TPartSliceLoader) { { // Construct screen from every even index page TVector<TScreen::THole> holes; - auto index = Part0()->Index->Begin(); - while (index) { - if (auto next = index + 1) { - holes.emplace_back(index->GetRowId(), next->GetRowId()); - index = next + 1; - } else { - holes.emplace_back(index->GetRowId(), Max<TRowId>()); - break; + TTestEnv env; + TPartIndexIt index(&*Part0(), &env, { }); + Y_VERIFY(index.Seek(0) == EReady::Data); + while (index.IsValid()) { + auto from = index.GetRowId(); + auto to = Max<TRowId>(); + if (index.Next() == EReady::Data) { + to = index.GetRowId(); + index.Next(); } + holes.emplace_back(from, to); } - UNIT_ASSERT_C(holes.size() > 2, "Generated screen has only " << holes.size() << " intervals"); + UNIT_ASSERT_C(holes.size() == (IndexTools::CountMainPages(*Part0()) + 1) / 2, "Generated screen has only " << holes.size() << " intervals"); // Make sure the last page is always included holes.back().End = Max<TRowId>(); screen = new TScreen(std::move(holes)); } auto result = RunLoaderTest(Part0(), screen); - UNIT_ASSERT_VALUES_EQUAL_C(result.Pages, 1 + Part0()->Index->End().End(), // index + all data pages + UNIT_ASSERT_VALUES_EQUAL_C(result.Pages, 1 + IndexTools::CountMainPages(*Part0()), // index + all data pages "Restoring slice bounds needed " << result.Pages << " extra pages"); } @@ -259,16 +263,17 @@ Y_UNIT_TEST_SUITE(TPartSliceLoader) { { // Use every even index page, without first and last key TVector<TScreen::THole> holes; - auto index = Part0()->Index->Begin(); - while (index) { - TRowId begin = index->GetRowId() + 1; + TTestEnv env; + TPartIndexIt index(&*Part0(), &env, { }); + Y_VERIFY(index.Seek(0) == EReady::Data); + while (index.IsValid()) { + TRowId begin = index.GetRowId() + 1; TRowId end; - if (auto next = index + 1) { - end = next->GetRowId() - 1; - index = next + 1; + if (index.Next() == EReady::Data) { + end = index.GetRowId() - 1; + index.Next(); } else { - end = Part0()->Index.GetLastKeyRecord()->GetRowId(); - ++index; + end = IndexTools::GetEndRowId(*Part0()) - 1; } if (begin < end) { holes.emplace_back(begin, end); |