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

fix drop column & reset ttl in one TX on CS #12127

Merged
merged 3 commits into from
Nov 29, 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
37 changes: 37 additions & 0 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10300,6 +10300,43 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
testTable.SetName(tableName).SetPrimaryKey({ "Key" }).SetSchema(schema).SetColumnFamilies(families);
testHelper.CreateTable(testTable, EStatus::GENERIC_ERROR);
}

Y_UNIT_TEST(DropColumnAndResetTtl) {
TKikimrSettings runnerSettings;
runnerSettings.WithSampleTables = false;
TTestHelper testHelper(runnerSettings);

TVector<TTestHelper::TColumnSchema> schema = {
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false),
TTestHelper::TColumnSchema().SetName("timestamp").SetType(NScheme::NTypeIds::Timestamp).SetNullable(false)
};

TTestHelper::TColumnTable testTable;
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema);
testHelper.CreateTable(testTable);

{
auto alterQuery = TStringBuilder() << R"(
--!syntax_v1
ALTER OBJECT `)" << testTable.GetName() << R"(` (TYPE TABLE) SET (ACTION=UPSERT_INDEX,
NAME=max_pk_int, TYPE=MAX, FEATURES=`{\"column_name\": \"timestamp\"}`))";
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
}

{
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`SET (TTL = Interval(\"PT1H\") ON timestamp);";
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
}

{
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` DROP COLUMN timestamp, RESET (TTL);";
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
}
}

}

Y_UNIT_TEST_SUITE(KqpOlapTypes) {
Expand Down
16 changes: 7 additions & 9 deletions ydb/core/tx/columnshard/columnshard_ttl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class TTtl {

void SetPathTtl(ui64 pathId, TDescription&& descr) {
if (descr.Eviction) {
auto& evict = descr.Eviction;
auto it = Columns.find(evict->ColumnName);
if (it != Columns.end()) {
evict->ColumnName = *it; // replace string dups (memory efficiency)
} else {
Columns.insert(evict->ColumnName);
}
PathTtls[pathId] = descr;
} else {
PathTtls.erase(pathId);
Expand All @@ -74,11 +67,16 @@ class TTtl {
return true;
}

const THashSet<TString>& TtlColumns() const { return Columns; }
THashSet<TString> TtlColumns() const {
THashSet<TString> columns;
for (const auto& [pathId, settings] : PathTtls) {
columns.insert(settings.Eviction->ColumnName);
}
return columns;
}

private:
THashMap<ui64, TDescription> PathTtls; // pathId -> ttl
THashSet<TString> Columns;

std::shared_ptr<NOlap::TTierInfo> Convert(const TDescription& descr) const
{
Expand Down
19 changes: 12 additions & 7 deletions ydb/core/tx/columnshard/tables_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
AFL_VERIFY(it != Tables.end());
auto& table = it->second;

bool isTtlModified = false;
if (versionInfo.HasTtlSettings()) {
isTtlModified = true;
const auto& ttlSettings = versionInfo.GetTtlSettings();
if (ttlSettings.HasEnabled()) {
Ttl.SetPathTtl(pathId, TTtl::TDescription(ttlSettings.GetEnabled()));
} else {
Ttl.DropPathTtl(pathId);
}
}

if (versionInfo.HasSchemaPresetId()) {
AFL_VERIFY(!schema);
Y_ABORT_UNLESS(SchemaPresetsIds.contains(versionInfo.GetSchemaPresetId()));
Expand All @@ -330,13 +341,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
AddSchemaVersion(fakePreset.GetId(), version, *schema, db, manager);
}

if (versionInfo.HasTtlSettings()) {
const auto& ttlSettings = versionInfo.GetTtlSettings();
if (ttlSettings.HasEnabled()) {
Ttl.SetPathTtl(pathId, TTtl::TDescription(ttlSettings.GetEnabled()));
} else {
Ttl.DropPathTtl(pathId);
}
if (isTtlModified) {
if (PrimaryIndex && manager->IsReady()) {
PrimaryIndex->OnTieringModified(manager, Ttl, pathId);
}
Expand Down
Loading