Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTreeIndex Keep B-TreeIndex in cache after compactions #1165

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ydb/core/tablet_flat/flat_executor_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5569,6 +5569,53 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutorBTreeIndex) {
UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 288);
}

Y_UNIT_TEST(UseBtreeIndex_True_Generations) {
TMyEnvBase env;
TRowsModel rows;

auto &appData = env->GetAppData();
appData.FeatureFlags.SetEnableLocalDBBtreeIndex(true);
auto counters = MakeIntrusive<TSharedPageCacheCounters>(env->GetDynamicCounters());
int readRows = 0, failedAttempts = 0;

env.FireDummyTablet(ui32(NFake::TDummy::EFlg::Comp));

auto policy = MakeIntrusive<TCompactionPolicy>();
policy->MinBTreeIndexNodeSize = 128;
policy->Generations.push_back({100 * 1024, 2, 2, 200 * 1024, NLocalDb::LegacyQueueIdToTaskName(1), false});
for (auto& gen : policy->Generations) {
gen.ExtraCompactionPercent = 0;
gen.ExtraCompactionMinSize = 0;
gen.ExtraCompactionExpPercent = 0;
gen.ExtraCompactionExpMaxSize = 0;
gen.UpliftPartSize = 0;
}
env.SendSync(rows.MakeScheme(std::move(policy)));

env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(1000, 950));
env.SendSync(rows.VersionTo(TRowVersion(2, 20)).RowTo(0).MakeRows(1000, 950));

env.SendSync(new NFake::TEvCompact(TRowsModel::TableId));
env.WaitFor<NFake::TEvCompacted>();

// gen 0 data pages are always kept in shared cache
// b-tree index pages are always kept in shared cache
UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 48);

env.SendSync(new NFake::TEvExecute{ new TTxFullScan(readRows, failedAttempts) });
UNIT_ASSERT_VALUES_EQUAL(readRows, 1000);
UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 286);

// restart tablet
env.SendSync(new TEvents::TEvPoison, false, true);
env.FireDummyTablet(ui32(NFake::TDummy::EFlg::Comp));

// after restart we have no pages in private cache
env.SendSync(new NFake::TEvExecute{ new TTxFullScan(readRows, failedAttempts) }, true);
UNIT_ASSERT_VALUES_EQUAL(readRows, 1000);
UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 332);
}

}

} // namespace NTabletFlatExecutor
Expand Down
5 changes: 3 additions & 2 deletions ydb/core/tablet_flat/flat_writer_blocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ namespace NWriter {
for (auto &glob : Writer.Grab())
Cone->Put(std::move(glob));

// Note: we mark flat index pages sticky after we load them
if (NTable::TLoader::NeedIn(type) || StickyFlatIndex && type == EPage::Index) {
// Note: we mark flat index pages sticky after we load them
Sticky.emplace_back(pageId, std::move(raw));
} else if (bool(Cache) && (type == EPage::DataPage || type == EPage::BTreeIndex)) {
} else if (bool(Cache) && type == EPage::DataPage || type == EPage::BTreeIndex) {
// Note: we save b-tree index pages to shared cache regardless of a cache mode
Regular.emplace_back(pageId, std::move(raw));
}

Expand Down
Loading