Skip to content

Commit 73759b6

Browse files
authored
fix TTL initialization from DB on CS (#12210)
1 parent 8bff909 commit 73759b6

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10343,6 +10343,50 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
1034310343
}
1034410344
}
1034510345

10346+
Y_UNIT_TEST(InitTtlSettingsOnShardStart) {
10347+
TKikimrSettings runnerSettings;
10348+
runnerSettings.WithSampleTables = false;
10349+
TTestHelper testHelper(runnerSettings);
10350+
10351+
TVector<TTestHelper::TColumnSchema> schema = {
10352+
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false),
10353+
TTestHelper::TColumnSchema().SetName("timestamp").SetType(NScheme::NTypeIds::Timestamp).SetNullable(false)
10354+
};
10355+
10356+
TTestHelper::TColumnTable testTable;
10357+
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema);
10358+
testHelper.CreateTable(testTable);
10359+
10360+
{
10361+
auto alterQuery = TStringBuilder() << R"(
10362+
--!syntax_v1
10363+
ALTER OBJECT `)" << testTable.GetName() << R"(` (TYPE TABLE) SET (ACTION=UPSERT_INDEX,
10364+
NAME=max_pk_int, TYPE=MAX, FEATURES=`{\"column_name\": \"timestamp\"}`))";
10365+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
10366+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
10367+
}
10368+
10369+
{
10370+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`SET (TTL = Interval(\"PT1H\") ON timestamp);";
10371+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
10372+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
10373+
}
10374+
10375+
{
10376+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` RESET (TTL);";
10377+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
10378+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
10379+
}
10380+
10381+
{
10382+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` DROP COLUMN timestamp;";
10383+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
10384+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
10385+
}
10386+
10387+
testHelper.RebootTablets("/Root/ColumnTableTest");
10388+
}
10389+
1034610390
}
1034710391

1034810392
Y_UNIT_TEST_SUITE(KqpOlapTypes) {

ydb/core/tx/columnshard/tables_manager.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,18 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
126126

127127
if (!table.IsDropped()) {
128128
auto& ttlSettings = versionInfo.GetTtlSettings();
129-
if (ttlSettings.HasEnabled()) {
130-
auto vIt = lastVersion.find(pathId);
131-
if (vIt == lastVersion.end()) {
132-
vIt = lastVersion.emplace(pathId, version).first;
133-
}
134-
if (vIt->second <= version) {
129+
auto vIt = lastVersion.find(pathId);
130+
if (vIt == lastVersion.end()) {
131+
vIt = lastVersion.emplace(pathId, version).first;
132+
}
133+
if (vIt->second <= version) {
134+
if (ttlSettings.HasEnabled()) {
135135
TTtl::TDescription description(ttlSettings.GetEnabled());
136136
Ttl.SetPathTtl(pathId, std::move(description));
137-
vIt->second = version;
137+
} else {
138+
Ttl.DropPathTtl(pathId);
138139
}
140+
vIt->second = version;
139141
}
140142
}
141143
table.AddVersion(version);

0 commit comments

Comments
 (0)