Skip to content

Commit

Permalink
24-1 Prevent from using B-Tree index with incorrect configuration (#4925
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kunga authored Jun 3, 2024
1 parent 62b7bff commit c165555
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 92 deletions.
2 changes: 1 addition & 1 deletion ydb/core/tablet_flat/flat_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4321,7 +4321,7 @@ ui64 TExecutor::BeginCompaction(THolder<NTable::TCompactionParams> params)

comp->Epoch = snapshot->Subset->Epoch(); /* narrows requested to actual */
comp->Layout.Final = comp->Params->IsFinal;
comp->Layout.WriteBTreeIndex = AppData()->FeatureFlags.GetEnableLocalDBBtreeIndex();
comp->Layout.WriteBTreeIndex = false; // will be in 24-2: AppData()->FeatureFlags.GetEnableLocalDBBtreeIndex();
comp->Writer.StickyFlatIndex = !comp->Layout.WriteBTreeIndex;
comp->Layout.MaxRows = snapshot->Subset->MaxRows();
comp->Layout.ByKeyFilter = tableInfo->ByKeyFilter;
Expand Down
93 changes: 3 additions & 90 deletions ydb/core/tablet_flat/flat_executor_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5491,7 +5491,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutorBTreeIndex) {
UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 288);
}

Y_UNIT_TEST(UseBtreeIndex_True) {
Y_UNIT_TEST(UseBtreeIndex_True) { // forcibly disabled in 24-1, uses FlatIndex
TMyEnvBase env;
TRowsModel rows;

Expand All @@ -5512,8 +5512,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutorBTreeIndex) {
env.SendSync(new NFake::TEvCompact(TRowsModel::TableId));
env.WaitFor<NFake::TEvCompacted>();

// all pages are always kept in shared cache (except flat index)
UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 334);
// all pages are always kept in shared cache
UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 290);

env.SendSync(new NFake::TEvExecute{ new TTxFullScan(readRows, failedAttempts) });
UNIT_ASSERT_VALUES_EQUAL(readRows, 1000);
Expand All @@ -5526,96 +5526,9 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutorBTreeIndex) {
// 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);
}

Y_UNIT_TEST(UseBtreeIndex_True_TurnOff) {
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;
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>();

// all pages are always kept in shared cache (except flat index)
UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 334);

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

// restart tablet, turn off setting
env.SendSync(new TEvents::TEvPoison, false, true);
appData.FeatureFlags.SetEnableLocalDBBtreeIndex(false);
env.FireDummyTablet(ui32(NFake::TDummy::EFlg::Comp));

// after restart we have no pages in private cache
// but use only flat index
env.SendSync(new NFake::TEvExecute{ new TTxFullScan(readRows, failedAttempts) }, true);
UNIT_ASSERT_VALUES_EQUAL(readRows, 1000);
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
2 changes: 1 addition & 1 deletion ydb/core/tablet_flat/flat_part_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void TLoader::StageParseMeta() noexcept

BTreeGroupIndexes.clear();
BTreeHistoricIndexes.clear();
if (AppData()->FeatureFlags.GetEnableLocalDBBtreeIndex()) {
if (false) { // will be in 24-2: AppData()->FeatureFlags.GetEnableLocalDBBtreeIndex()
for (bool history : {false, true}) {
for (const auto &meta : history ? layout.GetBTreeHistoricIndexes() : layout.GetBTreeGroupIndexes()) {
NPage::TBtreeIndexMeta converted{{
Expand Down

0 comments on commit c165555

Please sign in to comment.