summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkungurtsev <[email protected]>2024-01-22 20:21:16 +0500
committerGitHub <[email protected]>2024-01-22 16:21:16 +0100
commit55445f2c8e77f9d443309a612955ea92d1cce1f9 (patch)
treee0a1f4469e6d7423c9107f9841ac8fe7f290e72c
parent8ccdd915c56cb160284705e8daea6f6f0faf8bcd (diff)
KIKIMR-19521 BTreeIndex Keep B-TreeIndex in cache after compactions (#1165)
-rw-r--r--ydb/core/tablet_flat/flat_executor_ut.cpp47
-rw-r--r--ydb/core/tablet_flat/flat_writer_blocks.h5
2 files changed, 50 insertions, 2 deletions
diff --git a/ydb/core/tablet_flat/flat_executor_ut.cpp b/ydb/core/tablet_flat/flat_executor_ut.cpp
index 89e2a69fd9a..18d8399728b 100644
--- a/ydb/core/tablet_flat/flat_executor_ut.cpp
+++ b/ydb/core/tablet_flat/flat_executor_ut.cpp
@@ -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
diff --git a/ydb/core/tablet_flat/flat_writer_blocks.h b/ydb/core/tablet_flat/flat_writer_blocks.h
index 2b123e4f53d..76cd0f6fe8b 100644
--- a/ydb/core/tablet_flat/flat_writer_blocks.h
+++ b/ydb/core/tablet_flat/flat_writer_blocks.h
@@ -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));
}