From dafbf951f19fa727fee754adcda63ec9d34812bc Mon Sep 17 00:00:00 2001 From: Semyon Yentsov Date: Sun, 10 Nov 2024 19:13:26 +0000 Subject: [PATCH 1/3] configure tiering on CS via ttl --- ydb/core/grpc_services/rpc_create_table.cpp | 1 - ydb/core/grpc_services/rpc_log_store.cpp | 8 -- ydb/core/kqp/host/kqp_gateway_proxy.cpp | 20 ++- ydb/core/kqp/provider/yql_kikimr_exec.cpp | 7 - ydb/core/kqp/provider/yql_kikimr_gateway.cpp | 32 ++--- ydb/core/kqp/provider/yql_kikimr_gateway.h | 8 +- ydb/core/kqp/provider/yql_kikimr_type_ann.cpp | 8 -- ydb/core/kqp/ut/common/columnshard.cpp | 21 +-- ydb/core/kqp/ut/common/columnshard.h | 3 +- ydb/core/kqp/ut/olap/tiering_ut.cpp | 114 +++++++++-------- ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 78 ++++++------ ydb/core/protos/flat_scheme_op.proto | 4 +- ydb/core/tx/columnshard/columnshard.cpp | 8 +- ydb/core/tx/columnshard/columnshard__init.cpp | 1 - .../columnshard__propose_transaction.cpp | 2 +- ydb/core/tx/columnshard/columnshard_impl.cpp | 52 +++++--- ydb/core/tx/columnshard/columnshard_impl.h | 3 +- ydb/core/tx/columnshard/columnshard_schema.h | 6 +- ydb/core/tx/columnshard/columnshard_ttl.h | 93 -------------- .../tx/columnshard/engines/column_engine.h | 5 +- .../engines/column_engine_logs.cpp | 44 ++----- .../columnshard/engines/column_engine_logs.h | 5 +- .../engines/scheme/tiering/tier_info.h | 71 +++++++++++ .../tx/columnshard/hooks/abstract/abstract.h | 4 +- ydb/core/tx/columnshard/loading/stages.cpp | 2 +- ydb/core/tx/columnshard/tables_manager.cpp | 25 ++-- ydb/core/tx/columnshard/tables_manager.h | 21 +-- .../test_helper/columnshard_ut_common.cpp | 10 +- .../test_helper/columnshard_ut_common.h | 25 ++-- ydb/core/tx/schemeshard/common/validation.cpp | 6 +- ydb/core/tx/schemeshard/common/validation.h | 4 +- .../tx/schemeshard/olap/manager/manager.cpp | 55 +++++--- .../tx/schemeshard/olap/manager/manager.h | 6 +- .../operations/alter/abstract/converter.h | 7 +- .../olap/operations/alter_table.cpp | 3 +- ydb/core/tx/schemeshard/olap/ttl/schema.cpp | 3 - .../tx/schemeshard/olap/ttl/validator.cpp | 6 +- .../tx/schemeshard/ut_helpers/ls_checks.cpp | 14 +- .../tx/schemeshard/ut_helpers/ls_checks.h | 2 +- ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp | 29 ++++- ydb/core/tx/tiering/external_data.cpp | 7 +- ydb/core/tx/tiering/external_data.h | 2 +- ydb/core/tx/tiering/manager.cpp | 32 +---- ydb/core/tx/tiering/manager.h | 9 +- ydb/core/tx/tiering/rule/behaviour.cpp | 26 ---- ydb/core/tx/tiering/rule/behaviour.h | 20 --- ydb/core/tx/tiering/rule/checker.cpp | 97 -------------- ydb/core/tx/tiering/rule/checker.h | 44 ------- ydb/core/tx/tiering/rule/initializer.cpp | 41 ------ ydb/core/tx/tiering/rule/initializer.h | 15 --- ydb/core/tx/tiering/rule/manager.cpp | 43 ------- ydb/core/tx/tiering/rule/manager.h | 18 --- ydb/core/tx/tiering/rule/object.cpp | 104 --------------- ydb/core/tx/tiering/rule/object.h | 94 -------------- ydb/core/tx/tiering/rule/ya.make | 24 ---- ydb/core/tx/tiering/snapshot.cpp | 35 +---- ydb/core/tx/tiering/snapshot.h | 8 +- ydb/core/tx/tiering/tier/checker.cpp | 64 +--------- ydb/core/tx/tiering/tier/checker.h | 6 - .../tx/tiering/{rule => tier}/ss_checker.cpp | 0 .../tx/tiering/{rule => tier}/ss_checker.h | 0 .../tx/tiering/{rule => tier}/ss_fetcher.cpp | 0 .../tx/tiering/{rule => tier}/ss_fetcher.h | 0 ydb/core/tx/tiering/tier/ya.make | 2 + ydb/core/tx/tiering/ut/ut_tiers.cpp | 120 +++++++----------- ydb/core/tx/tiering/ya.make | 1 - ydb/core/ydb_convert/table_description.cpp | 16 --- ydb/core/ydb_convert/table_settings.cpp | 10 -- .../api/protos/draft/ydb_logstore.proto | 10 +- ydb/public/api/protos/ydb_table.proto | 9 +- ydb/public/lib/experimental/ydb_logstore.cpp | 2 - ydb/public/lib/experimental/ydb_logstore.h | 20 --- ydb/public/sdk/cpp/client/ydb_table/table.cpp | 20 +-- ydb/public/sdk/cpp/client/ydb_table/table.h | 1 + 74 files changed, 467 insertions(+), 1249 deletions(-) delete mode 100644 ydb/core/tx/columnshard/columnshard_ttl.h delete mode 100644 ydb/core/tx/tiering/rule/behaviour.cpp delete mode 100644 ydb/core/tx/tiering/rule/behaviour.h delete mode 100644 ydb/core/tx/tiering/rule/checker.cpp delete mode 100644 ydb/core/tx/tiering/rule/checker.h delete mode 100644 ydb/core/tx/tiering/rule/initializer.cpp delete mode 100644 ydb/core/tx/tiering/rule/initializer.h delete mode 100644 ydb/core/tx/tiering/rule/manager.cpp delete mode 100644 ydb/core/tx/tiering/rule/manager.h delete mode 100644 ydb/core/tx/tiering/rule/object.cpp delete mode 100644 ydb/core/tx/tiering/rule/object.h delete mode 100644 ydb/core/tx/tiering/rule/ya.make rename ydb/core/tx/tiering/{rule => tier}/ss_checker.cpp (100%) rename ydb/core/tx/tiering/{rule => tier}/ss_checker.h (100%) rename ydb/core/tx/tiering/{rule => tier}/ss_fetcher.cpp (100%) rename ydb/core/tx/tiering/{rule => tier}/ss_fetcher.h (100%) diff --git a/ydb/core/grpc_services/rpc_create_table.cpp b/ydb/core/grpc_services/rpc_create_table.cpp index 971cca82ce05..acad425ae98b 100644 --- a/ydb/core/grpc_services/rpc_create_table.cpp +++ b/ydb/core/grpc_services/rpc_create_table.cpp @@ -136,7 +136,6 @@ class TCreateTableRPC : public TRpcSchemeRequestActorMutableTtlSettings()->SetUseTiering(req.tiering()); return true; } diff --git a/ydb/core/grpc_services/rpc_log_store.cpp b/ydb/core/grpc_services/rpc_log_store.cpp index 08cd8667c99c..2e8e26dc5c90 100644 --- a/ydb/core/grpc_services/rpc_log_store.cpp +++ b/ydb/core/grpc_services/rpc_log_store.cpp @@ -435,8 +435,6 @@ class TCreateLogTableRPC : public TRpcSchemeRequestActorMutableTtlSettings()->MutableEnabled(), req->ttl_settings(), status, error)) { return Reply(status, error, NKikimrIssues::TIssuesIds::DEFAULT_ERROR, ctx); } - } else if (req->has_tiering_settings()) { - create->MutableTtlSettings()->SetUseTiering(req->tiering_settings().tiering_id()); } create->SetColumnShardCount(req->shards_count()); @@ -600,12 +598,6 @@ class TAlterLogTableRPC : public TRpcSchemeRequestActorMutableAlterTtlSettings()->MutableDisabled(); } - if (req->has_set_tiering_settings()) { - alter->MutableAlterTtlSettings()->SetUseTiering(req->set_tiering_settings().tiering_id()); - } else if (req->has_drop_tiering_settings()) { - alter->MutableAlterTtlSettings()->SetUseTiering(""); - } - ctx.Send(MakeTxProxyID(), proposeRequest.release()); } }; diff --git a/ydb/core/kqp/host/kqp_gateway_proxy.cpp b/ydb/core/kqp/host/kqp_gateway_proxy.cpp index 1f47b88897dc..e3a4a61366cd 100644 --- a/ydb/core/kqp/host/kqp_gateway_proxy.cpp +++ b/ydb/core/kqp/host/kqp_gateway_proxy.cpp @@ -276,16 +276,6 @@ bool ConvertCreateTableSettingsToProto(NYql::TKikimrTableMetadataPtr metadata, Y } } - if (const auto& tiering = metadata->TableSettings.Tiering) { - if (tiering.IsSet()) { - proto.set_tiering(tiering.GetValueSet()); - } else { - code = Ydb::StatusIds::BAD_REQUEST; - error = "Can't reset TIERING"; - return false; - } - } - if (metadata->TableSettings.StoreExternalBlobs) { auto& storageSettings = *proto.mutable_storage_settings(); TString value = to_lower(metadata->TableSettings.StoreExternalBlobs.GetRef()); @@ -520,7 +510,15 @@ bool FillCreateColumnTableDesc(NYql::TKikimrTableMetadataPtr metadata, const auto& inputSettings = metadata->TableSettings.TtlSettings.GetValueSet(); auto& resultSettings = *tableDesc.MutableTtlSettings(); resultSettings.MutableEnabled()->SetColumnName(inputSettings.ColumnName); - resultSettings.MutableEnabled()->SetExpireAfterSeconds(inputSettings.ExpireAfter.Seconds()); + for (const auto& tier : inputSettings.Tiers) { + auto* tierProto = resultSettings.MutableEnabled()->AddTiers(); + tierProto->SetApplyAfterSeconds(tier.ApplyAfter.Seconds()); + if (tier.StorageName) { + tierProto->MutableEvictToExternalStorage()->SetStorageName(*tier.StorageName); + } else { + tierProto->MutableDelete(); + } + } if (inputSettings.ColumnUnit) { resultSettings.MutableEnabled()->SetColumnUnit(static_cast(*inputSettings.ColumnUnit)); } diff --git a/ydb/core/kqp/provider/yql_kikimr_exec.cpp b/ydb/core/kqp/provider/yql_kikimr_exec.cpp index b2b205be6e3a..5a11ab401434 100644 --- a/ydb/core/kqp/provider/yql_kikimr_exec.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_exec.cpp @@ -1657,13 +1657,6 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer().Literal().Cast().Value() - ); - alterTableRequest.set_set_tiering(tieringName); - } else if (name == "resetTiering") { - alterTableRequest.mutable_drop_tiering(); } else { ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), TStringBuilder() << "Unknown table profile setting: " << name)); diff --git a/ydb/core/kqp/provider/yql_kikimr_gateway.cpp b/ydb/core/kqp/provider/yql_kikimr_gateway.cpp index 233058ee4a01..717b393478a3 100644 --- a/ydb/core/kqp/provider/yql_kikimr_gateway.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_gateway.cpp @@ -101,16 +101,6 @@ bool TTtlSettings::TryParse(const NNodes::TCoNameValueTupleList& node, TTtlSetti if (name == "columnName") { YQL_ENSURE(field.Value().Maybe()); settings.ColumnName = field.Value().Cast().StringValue(); - } else if (name == "expireAfter") { - // TODO (yentsovsemyon): remove this clause after extending TTL syntax in YQL - YQL_ENSURE(field.Value().Maybe()); - auto value = FromString(field.Value().Cast().Literal().Value()); - if (value < 0) { - error = "Interval value cannot be negative"; - return false; - } - - settings.ExpireAfter = TDuration::FromValue(value); } else if (name == "tiers") { YQL_ENSURE(field.Value().Maybe()); auto listNode = field.Value().Cast(); @@ -118,12 +108,14 @@ bool TTtlSettings::TryParse(const NNodes::TCoNameValueTupleList& node, TTtlSetti for (size_t i = 0; i < listNode.Size(); ++i) { auto tierNode = listNode.Item(i); + std::optional storageName; + TDuration evictionDelay; YQL_ENSURE(tierNode.Maybe()); for (const auto& tierField : tierNode.Cast()) { auto tierFieldName = tierField.Name().Value(); if (tierFieldName == "storageName") { - error = "TTL cannot contain tiered storage: tiering in TTL syntax is not supported"; - return false; + YQL_ENSURE(tierField.Value().Maybe()); + storageName = tierField.Value().Cast().StringValue(); } else if (tierFieldName == "evictionDelay") { YQL_ENSURE(tierField.Value().Maybe()); auto value = FromString(tierField.Value().Cast().Literal().Value()); @@ -131,12 +123,14 @@ bool TTtlSettings::TryParse(const NNodes::TCoNameValueTupleList& node, TTtlSetti error = "Interval value cannot be negative"; return false; } - settings.ExpireAfter = TDuration::FromValue(value); + evictionDelay = TDuration::FromValue(value); } else { error = TStringBuilder() << "Unknown field: " << tierFieldName; return false; } } + + settings.Tiers.emplace_back(evictionDelay, storageName); } } else if (name == "columnUnit") { YQL_ENSURE(field.Value().Maybe()); @@ -318,9 +312,15 @@ void ConvertTtlSettingsToProto(const NYql::TTtlSettings& settings, Ydb::Table::T opts.set_column_name(settings.ColumnName); opts.set_column_unit(static_cast(*settings.ColumnUnit)); } - auto* deleteTier = proto.add_tiers(); - deleteTier->set_apply_after_seconds(settings.ExpireAfter.Seconds()); - deleteTier->mutable_delete_(); + for (const auto& tier : settings.Tiers) { + auto* tierProto = proto.add_tiers(); + tierProto->set_apply_after_seconds(tier.ApplyAfter.Seconds()); + if (tier.StorageName) { + tierProto->mutable_evict_to_external_storage()->set_storage_name(tier.StorageName); + } else { + tierProto->mutable_delete_(); + } + } } Ydb::FeatureFlag::Status GetFlagValue(const TMaybe& value) { diff --git a/ydb/core/kqp/provider/yql_kikimr_gateway.h b/ydb/core/kqp/provider/yql_kikimr_gateway.h index 86e304fb040c..b3c71974011d 100644 --- a/ydb/core/kqp/provider/yql_kikimr_gateway.h +++ b/ydb/core/kqp/provider/yql_kikimr_gateway.h @@ -221,9 +221,14 @@ struct TTtlSettings { Nanoseconds = 4, }; + struct TTier { + TDuration ApplyAfter; + std::optional StorageName; + }; + TString ColumnName; - TDuration ExpireAfter; TMaybe ColumnUnit; + std::vector Tiers; static bool TryParse(const NNodes::TCoNameValueTupleList& node, TTtlSettings& settings, TString& error); }; @@ -241,7 +246,6 @@ struct TTableSettings { TMaybe KeyBloomFilter; TMaybe ReadReplicasSettings; TResetableSetting TtlSettings; - TResetableSetting Tiering; TMaybe PartitionByHashFunction; TMaybe StoreExternalBlobs; diff --git a/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp b/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp index 613149823956..d732bfa7064b 100644 --- a/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_type_ann.cpp @@ -1251,14 +1251,6 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), "Can't reset TTL settings")); return TStatus::Error; - } else if (name == "setTiering") { - meta->TableSettings.Tiering.Set(TString( - setting.Value().Cast().Literal().Cast().Value() - )); - } else if (name == "resetTiering") { - ctx.AddError(TIssue(ctx.GetPosition(setting.Name().Pos()), - "Can't reset TIERING")); - return TStatus::Error; } else if (name == "storeType") { TMaybe storeType = TString(setting.Value().Cast().Value()); if (storeType && to_lower(storeType.GetRef()) == "column") { diff --git a/ydb/core/kqp/ut/common/columnshard.cpp b/ydb/core/kqp/ut/common/columnshard.cpp index e5e442d7cfe7..28ffe5f3e7dd 100644 --- a/ydb/core/kqp/ut/common/columnshard.cpp +++ b/ydb/core/kqp/ut/common/columnshard.cpp @@ -68,29 +68,14 @@ namespace NKqp { UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); } - TString TTestHelper::CreateTieringRule(const TString& tierName, const TString& columnName) { - const TString ruleName = tierName + "_" + columnName; - const TString configTieringStr = TStringBuilder() << R"({ - "rules" : [ - { - "tierName" : ")" << tierName << R"(", - "durationForEvict" : "10d" - } - ] - })"; - auto result = GetSession().ExecuteSchemeQuery("CREATE OBJECT IF NOT EXISTS " + ruleName + " (TYPE TIERING_RULE) WITH (defaultColumn = " + columnName + ", description = `" + configTieringStr + "`)").GetValueSync(); - UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); - return ruleName; - } - - void TTestHelper::SetTiering(const TString& tableName, const TString& ruleName) { - auto alterQuery = TStringBuilder() << "ALTER TABLE `" << tableName << "` SET (TIERING = '" << ruleName << "')"; + void TTestHelper::SetTiering(const TString& tableName, const TString& tierName, const TString& columnName) { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << tableName << "` SET TTL Interval(\"P10D\") TO EXTERNAL DATA SOURCE `" << tierName << "` ON `" << columnName << "`;"; auto result = GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); } void TTestHelper::ResetTiering(const TString& tableName) { - auto alterQuery = TStringBuilder() << "ALTER TABLE `" << tableName << "` RESET (TIERING)"; + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << tableName << "` RESET (TTL)"; auto result = GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); } diff --git a/ydb/core/kqp/ut/common/columnshard.h b/ydb/core/kqp/ut/common/columnshard.h index e7d00ee6a1f7..ba85f6686162 100644 --- a/ydb/core/kqp/ut/common/columnshard.h +++ b/ydb/core/kqp/ut/common/columnshard.h @@ -109,9 +109,10 @@ class TTestHelper { NYdb::NTable::TSession& GetSession(); void CreateTable(const TColumnTableBase& table, const NYdb::EStatus expectedStatus = NYdb::EStatus::SUCCESS); void DropTable(const TString& tableName); + void EnsureSecret(const TString& name, const TString& value); void CreateTier(const TString& tierName); TString CreateTieringRule(const TString& tierName, const TString& columnName); - void SetTiering(const TString& tableName, const TString& ruleName); + void SetTiering(const TString& tableName, const TString& tierName, const TString& columnName); void ResetTiering(const TString& tableName); void BulkUpsert( const TColumnTable& table, TTestHelper::TUpdatesBuilder& updates, const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS); diff --git a/ydb/core/kqp/ut/olap/tiering_ut.cpp b/ydb/core/kqp/ut/olap/tiering_ut.cpp index 410adeddb67f..f14fa26a325b 100644 --- a/ydb/core/kqp/ut/olap/tiering_ut.cpp +++ b/ydb/core/kqp/ut/olap/tiering_ut.cpp @@ -12,26 +12,39 @@ namespace NKikimr::NKqp { -Y_UNIT_TEST_SUITE(KqpOlapTiering) { - Y_UNIT_TEST(Eviction) { +class TTestEvictionBase { +protected: + std::optional TestHelper; + TString TieringRule; + +protected: + virtual void UnevictAll() = 0; + +public: + void RunTest() { auto csController = NYDBTest::TControllers::RegisterCSControllerGuard(); csController->SetSkipSpecialCheckForEvict(true); TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; - TTestHelper testHelper(runnerSettings); - TLocalHelper localHelper(testHelper.GetKikimr()); - NYdb::NTable::TTableClient tableClient = testHelper.GetKikimr().GetTableClient(); - Tests::NCommon::TLoggerInit(testHelper.GetKikimr()).Initialize(); + TestHelper.emplace(runnerSettings); + TLocalHelper localHelper(TestHelper->GetKikimr()); + // TestHelper->GetRuntime().SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NActors::NLog::PRI_DEBUG); + // TestHelper->GetRuntime().SetLogPriority(NKikimrServices::TX_COLUMNSHARD, NActors::NLog::PRI_DEBUG); + TestHelper->GetRuntime().SetLogPriority(NKikimrServices::TX_TIERING, NActors::NLog::PRI_DEBUG); + // TestHelper->GetRuntime().SetLogPriority(NKikimrServices::KQP_GATEWAY, NActors::NLog::PRI_DEBUG); + // TestHelper->GetRuntime().SetLogPriority(NKikimrServices::TX_PROXY_SCHEME_CACHE, NActors::NLog::PRI_DEBUG); + // TestHelper->GetRuntime().SetLogPriority(NKikimrServices::TX_PROXY, NActors::NLog::PRI_DEBUG); + NYdb::NTable::TTableClient tableClient = TestHelper->GetKikimr().GetTableClient(); + Tests::NCommon::TLoggerInit(TestHelper->GetKikimr()).Initialize(); Singleton()->SetSecretKey("fakeSecret"); localHelper.CreateTestOlapTable(); - testHelper.CreateTier("tier1"); - const TString tieringRule = testHelper.CreateTieringRule("tier1", "timestamp"); + TestHelper->CreateTier("tier1"); for (ui64 i = 0; i < 100; ++i) { - WriteTestData(testHelper.GetKikimr(), "/Root/olapStore/olapTable", 0, i * 10000, 1000); - WriteTestData(testHelper.GetKikimr(), "/Root/olapStore/olapTable", 0, i * 10000, 1000); + WriteTestData(TestHelper->GetKikimr(), "/Root/olapStore/olapTable", 0, 3600000000 + i * 10000, 1000); + WriteTestData(TestHelper->GetKikimr(), "/Root/olapStore/olapTable", 0, 3600000000 + i * 10000, 1000); } csController->WaitCompactions(TDuration::Seconds(5)); @@ -55,7 +68,7 @@ Y_UNIT_TEST_SUITE(KqpOlapTiering) { UNIT_ASSERT_GT(columnRawBytes, 0); } - testHelper.SetTiering("/Root/olapStore/olapTable", tieringRule); + TestHelper->SetTiering("/Root/olapStore/olapTable", "tier1", "timestamp"); csController->WaitActualization(TDuration::Seconds(5)); { @@ -72,10 +85,10 @@ Y_UNIT_TEST_SUITE(KqpOlapTiering) { UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("TierName")), "tier1"); UNIT_ASSERT_VALUES_EQUAL_C(GetUint64(rows[0].at("RawBytes")), columnRawBytes, TStringBuilder() << "RawBytes changed after eviction: before=" << columnRawBytes - << " after=" << GetUint64(rows[0].at("RawBytes"))); + << " after=" << GetUint64(rows[0].at("RawBytes"))); } - testHelper.ResetTiering("/Root/olapStore/olapTable"); + UnevictAll(); csController->WaitCompactions(TDuration::Seconds(5)); { @@ -92,72 +105,65 @@ Y_UNIT_TEST_SUITE(KqpOlapTiering) { UNIT_ASSERT_VALUES_EQUAL(GetUtf8(rows[0].at("TierName")), "__DEFAULT"); UNIT_ASSERT_VALUES_EQUAL_C(GetUint64(rows[0].at("RawBytes")), columnRawBytes, TStringBuilder() << "RawBytes changed after resetting tiering: before=" << columnRawBytes - << " after=" << GetUint64(rows[0].at("RawBytes"))); + << " after=" << GetUint64(rows[0].at("RawBytes"))); } + + } +}; + +class TTestEvictionResetTiering : public TTestEvictionBase { + private: + void UnevictAll() { + TestHelper->ResetTiering("/Root/olapStore/olapTable"); } +}; + +class TTestEvictionIncreaseDuration : public TTestEvictionBase { + private: + void UnevictAll() { + const TString query = R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P30000D") TO EXTERNAL DATA SOURCE tier1 ON timestamp)"; + auto result = TestHelper->GetSession().ExecuteSchemeQuery(query).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString()); + } +}; + +Y_UNIT_TEST_SUITE(KqpOlapTiering) { - Y_UNIT_TEST(TieringRuleValidation) { + Y_UNIT_TEST(EvictionResetTiering) { + TTestEvictionResetTiering().RunTest(); + } + + Y_UNIT_TEST(EvictionIncreaseDuration) { + TTestEvictionIncreaseDuration().RunTest(); + } + + Y_UNIT_TEST(TieringValidation) { auto csController = NYDBTest::TControllers::RegisterCSControllerGuard(); TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; TTestHelper testHelper(runnerSettings); TLocalHelper localHelper(testHelper.GetKikimr()); + testHelper.GetRuntime().SetLogPriority(NKikimrServices::TX_TIERING, NActors::NLog::PRI_DEBUG); NYdb::NTable::TTableClient tableClient = testHelper.GetKikimr().GetTableClient(); Tests::NCommon::TLoggerInit(testHelper.GetKikimr()).Initialize(); - Singleton()->SetSecretKey("fakeSecret"); localHelper.CreateTestOlapTable(); testHelper.CreateTier("tier1"); { - const TString query = R"( - CREATE OBJECT IF NOT EXISTS empty_tiering_rule (TYPE TIERING_RULE) - WITH (defaultColumn = timestamp, description = `{"rules": []}`))"; + const TString query = R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10D") TO EXTERNAL DATA SOURCE tier1 ON unknown_column;)"; auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); } { - const TString query = R"( - CREATE OBJECT IF NOT EXISTS empty_default_column (TYPE TIERING_RULE) - WITH (defaultColumn = ``, description = `{"rules": [{ "tierName" : "tier1", "durationForEvict" : "10d" }]}`))"; + const TString query = R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10D") TO EXTERNAL DATA SOURCE tier1 ON uid;)"; auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); } - { - const TString query = R"( - CREATE OBJECT IF NOT EXISTS no_default_column (TYPE TIERING_RULE) - WITH (description = `{"rules": [{ "tierName" : "tier1", "durationForEvict" : "10d" }]}`))"; - auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); - UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); - } - - const TString correctTieringRule = testHelper.CreateTieringRule("tier1", "timestamp"); - { - const TString query = "ALTER OBJECT " + correctTieringRule + R"( (TYPE TIERING_RULE) SET description `{"rules": []}`)"; - auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); - UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); - } - - { - const TString query = "ALTER OBJECT " + correctTieringRule + R"( (TYPE TIERING_RULE) SET description `{"rules": []}`)"; - auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); - UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); - } - - { - const TString query = "ALTER OBJECT " + correctTieringRule + R"( (TYPE TIERING_RULE) SET defaultColumn ``)"; - auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); - UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); - } - - { - const TString query = "ALTER OBJECT " + correctTieringRule + R"( (TYPE TIERING_RULE) RESET defaultColumn)"; - auto result = testHelper.GetSession().ExecuteSchemeQuery(query).GetValueSync(); - UNIT_ASSERT_VALUES_UNEQUAL(result.GetStatus(), NYdb::EStatus::SUCCESS); - } + testHelper.SetTiering("/Root/olapStore/olapTable", "tier1", "timestamp"); } } diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index 490d1a1c5d17..6ea265d820a5 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -5415,15 +5415,18 @@ Y_UNIT_TEST_SUITE(KqpScheme) { TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; runnerSettings.SetEnableTieringInColumnShard(true); - TKikimrRunner kikimr(runnerSettings); - auto db = kikimr.GetTableClient(); + TTestHelper testHelper(runnerSettings); + auto db = testHelper.GetKikimr().GetTableClient(); auto session = db.CreateSession().GetValueSync().GetSession(); TString tableName = "/Root/ColumnTableTest"; + testHelper.CreateTier("tier1"); + testHelper.CreateTier("tier2"); + auto query = TStringBuilder() << R"( --!syntax_v1 CREATE TABLE `)" << tableName << R"(` ( - Key Uint64 NOT NULL, + Key Timestamp NOT NULL, Value1 String, Value2 Int64 NOT NULL, PRIMARY KEY (Key) @@ -5432,23 +5435,23 @@ Y_UNIT_TEST_SUITE(KqpScheme) { WITH ( STORE = COLUMN, AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10, - TIERING = 'tiering1' + TTL = Interval("PT10S") TO EXTERNAL DATA SOURCE tier1 ON Key );)"; auto result = session.ExecuteSchemeQuery(query).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); -#if 0 // TODO { // describe table auto desc = session.DescribeTable(tableName).ExtractValueSync(); UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); - auto tiering = desc.GetTableDescription().GetTiering(); - UNIT_ASSERT(tiering); - UNIT_ASSERT_VALUES_EQUAL(*tiering, "tiering1"); + UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); + auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); } -#endif auto query2 = TStringBuilder() << R"( --!syntax_v1 - ALTER TABLE `)" << tableName << R"(` SET(TIERING = 'tiering2');)"; + ALTER TABLE `)" << tableName << R"(` SET (TTL = Interval("PT10S") TO EXTERNAL DATA SOURCE tier2 ON Key);)"; result = session.ExecuteSchemeQuery(query2).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); @@ -5456,14 +5459,16 @@ Y_UNIT_TEST_SUITE(KqpScheme) { auto desc = session.DescribeTable(tableName).ExtractValueSync(); UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); - auto tiering = desc.GetTableDescription().GetTiering(); - UNIT_ASSERT(tiering); - UNIT_ASSERT_VALUES_EQUAL(*tiering, "tiering2"); + UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); + auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier2"); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); } auto query3 = TStringBuilder() << R"( --!syntax_v1 - ALTER TABLE `)" << tableName << R"(` RESET (TIERING);)"; + ALTER TABLE `)" << tableName << R"(` RESET (TTL);)"; result = session.ExecuteSchemeQuery(query3).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); @@ -5471,13 +5476,13 @@ Y_UNIT_TEST_SUITE(KqpScheme) { auto desc = session.DescribeTable(tableName).ExtractValueSync(); UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); - auto tiering = desc.GetTableDescription().GetTiering(); - UNIT_ASSERT(!tiering); + auto ttl = desc.GetTableDescription().GetTtlSettings(); + UNIT_ASSERT(!ttl); } auto query4 = TStringBuilder() << R"( --!syntax_v1 - ALTER TABLE `)" << tableName << R"(` SET (TIERING = 'tiering1');)"; + ALTER TABLE `)" << tableName << R"(` SET (TTL = Interval("PT10S") TO EXTERNAL DATA SOURCE tier1 ON Key);)"; result = session.ExecuteSchemeQuery(query4).GetValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); @@ -5485,9 +5490,11 @@ Y_UNIT_TEST_SUITE(KqpScheme) { auto desc = session.DescribeTable(tableName).ExtractValueSync(); UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); - auto tiering = desc.GetTableDescription().GetTiering(); - UNIT_ASSERT(tiering); - UNIT_ASSERT_VALUES_EQUAL(*tiering, "tiering1"); + UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); + auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); } auto query5 = TStringBuilder() << R"( @@ -8105,9 +8112,7 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { testHelper.BulkUpsert(testTable, tableInserter); } - // const auto ruleName = testHelper.CreateTieringRule("tier1", "created_att"); - const auto ruleName = testHelper.CreateTieringRule("tier1", "created_at"); - testHelper.SetTiering(tableName, ruleName); + testHelper.SetTiering(tableName, "tier1", "created_at"); while (csController->GetTieringUpdates().Val() == 0) { Cout << "Wait tiering..." << Endl; @@ -8132,6 +8137,7 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { TTestHelper::TColumnTable testTable; testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id", "id_second"}).SetSharding({"id"}).SetSchema(schema); testHelper.CreateTable(testTable); + testHelper.CreateTier("tier1"); { auto alterQuery = TStringBuilder() << R"( @@ -8173,16 +8179,22 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { UNIT_ASSERT_VALUES_EQUAL(columns.size(), 5); UNIT_ASSERT_VALUES_EQUAL(description.GetTtlSettings()->GetDateTypeColumn().GetExpireAfter(), TDuration::Hours(1)); } - testHelper.SetTiering("/Root/ColumnTableTest", "tiering1"); + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`SET (TTL = Interval(\"PT10S\") TO EXTERNAL DATA SOURCE tier1, Interval(\"PT1H\") DELETE ON created_at);"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } { auto settings = TDescribeTableSettings().WithTableStatistics(true); auto describeResult = testHelper.GetSession().DescribeTable("/Root/ColumnTableTest", settings).GetValueSync(); UNIT_ASSERT_C(describeResult.IsSuccess(), describeResult.GetIssues().ToString()); const auto& description = describeResult.GetTableDescription(); - UNIT_ASSERT(description.GetTiering()); - UNIT_ASSERT_VALUES_EQUAL(*description.GetTiering(), "tiering1"); - UNIT_ASSERT_VALUES_EQUAL(description.GetTtlSettings()->GetDateTypeColumn().GetExpireAfter(), TDuration::Hours(1)); + UNIT_ASSERT(describeResult.GetTableDescription().GetTtlSettings()); + auto ttl = describeResult.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetExpireAfter(), TDuration::Hours(1)); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); } { auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << R"(` RESET (TTL);)"; @@ -8195,18 +8207,6 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { UNIT_ASSERT_C(describeResult.IsSuccess(), describeResult.GetIssues().ToString()); const auto& description = describeResult.GetTableDescription(); - UNIT_ASSERT(description.GetTiering()); - UNIT_ASSERT_VALUES_EQUAL(*description.GetTiering(), "tiering1"); - UNIT_ASSERT(!description.GetTtlSettings()); - } - testHelper.ResetTiering("/Root/ColumnTableTest"); - { - auto settings = TDescribeTableSettings().WithTableStatistics(true); - auto describeResult = testHelper.GetSession().DescribeTable("/Root/ColumnTableTest", settings).GetValueSync(); - UNIT_ASSERT_C(describeResult.IsSuccess(), describeResult.GetIssues().ToString()); - - const auto& description = describeResult.GetTableDescription(); - UNIT_ASSERT(!description.GetTiering()); UNIT_ASSERT(!description.GetTtlSettings()); } } diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index 50505ae2f27c..797a0de060ec 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -250,7 +250,7 @@ message TTTLSettings { TDisabled Disabled = 2; } - optional string UseTiering = 3; + reserved 3; } message TTableReplicationConfig { @@ -612,7 +612,7 @@ message TColumnDataLifeCycle { // Incremented on each settings change optional uint64 Version = 3 [default = 1]; - optional string UseTiering = 5; + reserved 5; } message TColumnTableTtlSettingsPreset { diff --git a/ydb/core/tx/columnshard/columnshard.cpp b/ydb/core/tx/columnshard/columnshard.cpp index 125335c86bd0..0d5c5766c270 100644 --- a/ydb/core/tx/columnshard/columnshard.cpp +++ b/ydb/core/tx/columnshard/columnshard.cpp @@ -60,8 +60,12 @@ void TColumnShard::SwitchToWork(const TActorContext& ctx) { NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("tablet_id", TabletID())("self_id", SelfId())("process", "SwitchToWork"); AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "initialize_shard")("step", "SwitchToWork"); - for (auto&& i : TablesManager.GetTables()) { - ActivateTiering(i.first, i.second.GetTieringUsage()); + for (const auto& [pathId, tiering] : TablesManager.GetTtl()) { + THashSet tiers; + for (const auto& [name, config] : tiering.GetTierByName()) { + tiers.emplace(name); + } + ActivateTiering(pathId, tiers); } Become(&TThis::StateWork); diff --git a/ydb/core/tx/columnshard/columnshard__init.cpp b/ydb/core/tx/columnshard/columnshard__init.cpp index ace229ac6ff1..852c05444105 100644 --- a/ydb/core/tx/columnshard/columnshard__init.cpp +++ b/ydb/core/tx/columnshard/columnshard__init.cpp @@ -1,7 +1,6 @@ #include "columnshard_impl.h" #include "columnshard_private_events.h" #include "columnshard_schema.h" -#include "columnshard_ttl.h" #include "bg_tasks/adapter/adapter.h" #include "bg_tasks/manager/manager.h" diff --git a/ydb/core/tx/columnshard/columnshard__propose_transaction.cpp b/ydb/core/tx/columnshard/columnshard__propose_transaction.cpp index d4ded82be3d8..f3bc2aa80e58 100644 --- a/ydb/core/tx/columnshard/columnshard__propose_transaction.cpp +++ b/ydb/core/tx/columnshard/columnshard__propose_transaction.cpp @@ -164,7 +164,7 @@ class TTxProposeTransaction: public NTabletFlatExecutor::TTransactionBaseSetupTtl(pathTtls)) { return TTxController::TProposeResult(NKikimrTxColumnShard::EResultStatus::SCHEMA_ERROR, "TTL not started"); } - Self->TablesManager.MutablePrimaryIndex().OnTieringModified(Self->Tiers, Self->TablesManager.GetTtl(), {}); + Self->TablesManager.MutablePrimaryIndex().OnTieringModified(Self->TablesManager.GetTtl()); return TTxController::TProposeResult(); } diff --git a/ydb/core/tx/columnshard/columnshard_impl.cpp b/ydb/core/tx/columnshard/columnshard_impl.cpp index f38dad89222e..3070a3bb41d1 100644 --- a/ydb/core/tx/columnshard/columnshard_impl.cpp +++ b/ydb/core/tx/columnshard/columnshard_impl.cpp @@ -406,20 +406,18 @@ void TColumnShard::RunEnsureTable(const NKikimrTxColumnShard::TCreateTable& tabl } { - bool needTieringActivation = false; + THashSet usedTiers; TTableInfo table(pathId); if (tableProto.HasTtlSettings()) { const auto& ttlSettings = tableProto.GetTtlSettings(); *tableVerProto.MutableTtlSettings() = ttlSettings; - if (ttlSettings.HasUseTiering()) { - table.SetTieringUsage(ttlSettings.GetUseTiering()); - needTieringActivation = true; + if (ttlSettings.HasEnabled()) { + usedTiers = NOlap::TTiering::GetUsedTiers(ttlSettings.GetEnabled()); } } - const TString tieringName = table.GetTieringUsage(); TablesManager.RegisterTable(std::move(table), db); - if (needTieringActivation) { - ActivateTiering(pathId, tieringName); + if (!usedTiers.empty()) { + ActivateTiering(pathId, usedTiers); } } @@ -430,7 +428,7 @@ void TColumnShard::RunEnsureTable(const NKikimrTxColumnShard::TCreateTable& tabl Counters.GetTabletCounters()->SetCounter(COUNTER_TABLES, TablesManager.GetTables().size()); Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_PRESETS, TablesManager.GetSchemaPresets().size()); - Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_TTLS, TablesManager.GetTtl().PathsCount()); + Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_TTLS, TablesManager.GetTtl().size()); } void TColumnShard::RunAlterTable(const NKikimrTxColumnShard::TAlterTable& alterProto, const NOlap::TSnapshot& version, @@ -454,14 +452,16 @@ void TColumnShard::RunAlterTable(const NKikimrTxColumnShard::TAlterTable& alterP schema = alterProto.GetSchema(); } - const auto& ttlSettings = alterProto.GetTtlSettings(); // Note: Not valid behaviour for full alter implementation - const TString& tieringUsage = ttlSettings.GetUseTiering(); + THashSet usedTiers; if (alterProto.HasTtlSettings()) { const auto& ttlSettings = alterProto.GetTtlSettings(); *tableVerProto.MutableTtlSettings() = ttlSettings; + + if (ttlSettings.HasEnabled()) { + usedTiers = NOlap::TTiering::GetUsedTiers(ttlSettings.GetEnabled()); + } } - ActivateTiering(pathId, tieringUsage); - Schema::SaveTableInfo(db, pathId, tieringUsage); + ActivateTiering(pathId, usedTiers); tableVerProto.SetSchemaPresetVersionAdj(alterProto.GetSchemaPresetVersionAdj()); TablesManager.AddTableVersion(pathId, version, tableVerProto, schema, db, Tiers); @@ -1552,13 +1552,13 @@ void TColumnShard::Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& Tiers->TakeConfigs(ev->Get()->GetSnapshot(), nullptr); } -void TColumnShard::ActivateTiering(const ui64 pathId, const TString& useTiering) { +void TColumnShard::ActivateTiering(const ui64 pathId, const THashSet& usedTiers) { AFL_VERIFY(Tiers); - if (useTiering) { - AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "activate_tiering")("path_id", pathId)("tiering", useTiering); + if (!usedTiers.empty()) { + AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "activate_tiering")("path_id", pathId)("tiers", JoinStrings(usedTiers.begin(), usedTiers.end(), ",")); } - if (useTiering) { - Tiers->EnablePathId(pathId, useTiering); + if (!usedTiers.empty()) { + Tiers->EnablePathId(pathId, usedTiers); } else { Tiers->DisablePathId(pathId); } @@ -1580,10 +1580,20 @@ void TColumnShard::Enqueue(STFUNC_SIG) { void TColumnShard::OnTieringModified(const std::optional pathId) { AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "OnTieringModified")("path_id", pathId); - if (Tiers->IsReady()) { - StoragesManager->OnTieringModified(Tiers); - if (TablesManager.HasPrimaryIndex()) { - TablesManager.MutablePrimaryIndex().OnTieringModified(Tiers, TablesManager.GetTtl(), pathId); + if (!Tiers->IsReady()) { + AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "skip_reload_tiering")("reason", "manager_not_ready")("path_id", pathId); + return; + } + StoragesManager->OnTieringModified(Tiers); + if (TablesManager.HasPrimaryIndex()) { + if (pathId) { + std::optional tableTtl; + if (auto* findTtl = TablesManager.GetTtl().FindPtr(*pathId)) { + tableTtl = *findTtl; + } + TablesManager.MutablePrimaryIndex().OnTieringModified(tableTtl, *pathId); + } else { + TablesManager.MutablePrimaryIndex().OnTieringModified(TablesManager.GetTtl()); } } } diff --git a/ydb/core/tx/columnshard/columnshard_impl.h b/ydb/core/tx/columnshard/columnshard_impl.h index ffa9a9c7cc23..844a3e20b80c 100644 --- a/ydb/core/tx/columnshard/columnshard_impl.h +++ b/ydb/core/tx/columnshard/columnshard_impl.h @@ -2,7 +2,6 @@ #include "background_controller.h" #include "columnshard.h" #include "columnshard_private_events.h" -#include "columnshard_ttl.h" #include "counters.h" #include "defs.h" #include "inflight_request_tracker.h" @@ -323,7 +322,7 @@ class TColumnShard: public TActor, public NTabletFlatExecutor::TTa putStatus.OnYellowChannels(Executor()); } - void ActivateTiering(const ui64 pathId, const TString& useTiering); + void ActivateTiering(const ui64 pathId, const THashSet& usedTiers); void OnTieringModified(const std::optional pathId = {}); public: diff --git a/ydb/core/tx/columnshard/columnshard_schema.h b/ydb/core/tx/columnshard/columnshard_schema.h index 0bea4bcfd18f..2a507e45c6fc 100644 --- a/ydb/core/tx/columnshard/columnshard_schema.h +++ b/ydb/core/tx/columnshard/columnshard_schema.h @@ -781,10 +781,8 @@ struct Schema : NIceDb::Schema { db.Table().Key(id).Delete(); } - static void SaveTableInfo(NIceDb::TNiceDb& db, const ui64 pathId, const TString tieringUsage) { - db.Table().Key(pathId).Update( - NIceDb::TUpdate(tieringUsage) - ); + static void SaveTableInfo(NIceDb::TNiceDb& db, const ui64 pathId) { + db.Table().Key(pathId).Update(); } diff --git a/ydb/core/tx/columnshard/columnshard_ttl.h b/ydb/core/tx/columnshard/columnshard_ttl.h deleted file mode 100644 index de2378737e95..000000000000 --- a/ydb/core/tx/columnshard/columnshard_ttl.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once -#include "defs.h" - -namespace NKikimr::NColumnShard { - -class TTtl { -public: - struct TEviction { - TDuration EvictAfter; - TString ColumnName; - ui32 UnitsInSecond = 0; // 0 means auto (data type specific) - }; - - struct TDescription { - std::optional Eviction; - - TDescription() = default; - - TDescription(const NKikimrSchemeOp::TColumnDataLifeCycle::TTtl& ttl) { - auto expireSec = TDuration::Seconds(ttl.GetExpireAfterSeconds()); - - Eviction = TEviction{expireSec, ttl.GetColumnName()}; - Y_ABORT_UNLESS(!Eviction->ColumnName.empty()); - - switch (ttl.GetColumnUnit()) { - case NKikimrSchemeOp::TTTLSettings::UNIT_SECONDS: - Eviction->UnitsInSecond = 1; - break; - case NKikimrSchemeOp::TTTLSettings::UNIT_MILLISECONDS: - Eviction->UnitsInSecond = 1000; - break; - case NKikimrSchemeOp::TTTLSettings::UNIT_MICROSECONDS: - Eviction->UnitsInSecond = 1000 * 1000; - break; - case NKikimrSchemeOp::TTTLSettings::UNIT_NANOSECONDS: - Eviction->UnitsInSecond = 1000 * 1000 * 1000; - break; - case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: - default: - break; - } - } - }; - - ui64 PathsCount() const { - return PathTtls.size(); - } - - 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); - } - } - - void DropPathTtl(ui64 pathId) { - PathTtls.erase(pathId); - } - - bool AddTtls(THashMap& eviction) const { - for (auto& [pathId, descr] : PathTtls) { - if (!eviction[pathId].Add(Convert(descr))) { - return false; - } - } - return true; - } - - const THashSet& TtlColumns() const { return Columns; } - -private: - THashMap PathTtls; // pathId -> ttl - THashSet Columns; - - std::shared_ptr Convert(const TDescription& descr) const - { - if (descr.Eviction) { - auto& evict = descr.Eviction; - return NOlap::TTierInfo::MakeTtl(evict->EvictAfter, evict->ColumnName, evict->UnitsInSecond); - } - return {}; - } -}; - -} diff --git a/ydb/core/tx/columnshard/engines/column_engine.h b/ydb/core/tx/columnshard/engines/column_engine.h index 58581bab51e2..06db832429df 100644 --- a/ydb/core/tx/columnshard/engines/column_engine.h +++ b/ydb/core/tx/columnshard/engines/column_engine.h @@ -13,7 +13,6 @@ namespace NKikimr::NColumnShard { class TTiersManager; -class TTtl; } // namespace NKikimr::NColumnShard namespace NKikimr::NOlap { @@ -365,8 +364,8 @@ class IColumnEngine { virtual TSnapshot LastUpdate() const { return TSnapshot::Zero(); } - virtual void OnTieringModified( - const std::shared_ptr& manager, const NColumnShard::TTtl& ttl, const std::optional pathId) = 0; + virtual void OnTieringModified(const std::optional& ttl, const ui64 pathId) = 0; + virtual void OnTieringModified(const THashMap& ttl) = 0; }; } // namespace NKikimr::NOlap diff --git a/ydb/core/tx/columnshard/engines/column_engine_logs.cpp b/ydb/core/tx/columnshard/engines/column_engine_logs.cpp index 7a1511a3acf1..6ae4ba1cad19 100644 --- a/ydb/core/tx/columnshard/engines/column_engine_logs.cpp +++ b/ydb/core/tx/columnshard/engines/column_engine_logs.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -153,12 +152,7 @@ void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, TInd const bool isCriticalScheme = indexInfo.GetSchemeNeedActualization(); auto* indexInfoActual = VersionedIndex.AddIndex(snapshot, std::move(indexInfo)); if (isCriticalScheme) { - if (!ActualizationStarted) { - ActualizationStarted = true; - for (auto&& i : GranulesStorage->GetTables()) { - i.second->StartActualizationIndex(); - } - } + StartActualization({}); for (auto&& i : GranulesStorage->GetTables()) { i.second->RefreshScheme(); } @@ -548,35 +542,25 @@ bool TColumnEngineForLogs::StartActualization(const THashMap& sp ActualizationStarted = true; return true; } +void TColumnEngineForLogs::OnTieringModified(const std::optional& ttl, const ui64 pathId) { + AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "OnTieringModified")("path_id", pathId); + StartActualization({}); + + auto g = GetGranulePtrVerified(pathId); + g->RefreshTiering(ttl); +} -void TColumnEngineForLogs::OnTieringModified( - const std::shared_ptr& manager, const NColumnShard::TTtl& ttl, const std::optional pathId) { +void TColumnEngineForLogs::OnTieringModified(const THashMap& ttl) { + AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "OnTieringModified")("new_count_tierings", ttl.size()); StartActualization({}); - AFL_VERIFY(manager); - THashMap tierings = manager->GetTiering(); - ttl.AddTtls(tierings); - - AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "OnTieringModified")("new_count_tierings", tierings.size())( - "new_count_ttls", ttl.PathsCount()); - // some string - - if (pathId) { - auto g = GetGranulePtrVerified(*pathId); - auto it = tierings.find(*pathId); - if (it == tierings.end()) { + + for (auto&& [gPathId, g] : GranulesStorage->GetTables()) { + auto it = ttl.find(gPathId); + if (it == ttl.end()) { g->RefreshTiering({}); } else { g->RefreshTiering(it->second); } - } else { - for (auto&& [gPathId, g] : GranulesStorage->GetTables()) { - auto it = tierings.find(gPathId); - if (it == tierings.end()) { - g->RefreshTiering({}); - } else { - g->RefreshTiering(it->second); - } - } } } diff --git a/ydb/core/tx/columnshard/engines/column_engine_logs.h b/ydb/core/tx/columnshard/engines/column_engine_logs.h index 92f1a4ed5e8a..3db0681a93e7 100644 --- a/ydb/core/tx/columnshard/engines/column_engine_logs.h +++ b/ydb/core/tx/columnshard/engines/column_engine_logs.h @@ -8,7 +8,6 @@ #include "storage/granule/granule.h" #include "storage/granule/storage.h" -#include #include #include #include @@ -95,8 +94,8 @@ class TColumnEngineForLogs: public IColumnEngine { TColumnEngineForLogs(const ui64 tabletId, const std::shared_ptr& dataAccessorsManager, const std::shared_ptr& storagesManager, const TSnapshot& snapshot, TIndexInfo&& schema); - virtual void OnTieringModified( - const std::shared_ptr& manager, const NColumnShard::TTtl& ttl, const std::optional pathId) override; + void OnTieringModified(const std::optional& ttl, const ui64 pathId) override; + void OnTieringModified(const THashMap& ttl) override; virtual std::shared_ptr CopyVersionedIndexPtr() const override { return std::make_shared(VersionedIndex); diff --git a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h index 77f090e3b993..8e1cb9169495 100644 --- a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h +++ b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h @@ -53,6 +53,21 @@ class TTierInfo { return std::make_shared(NTiering::NCommon::DeleteTierName, evictDuration, ttlColumn, unitsInSecond); } + static ui32 GetUnitsInSecond(const NKikimrSchemeOp::TTTLSettings::EUnit timeUnit) { + switch (timeUnit) { + case NKikimrSchemeOp::TTTLSettings::UNIT_SECONDS: + return 1; + case NKikimrSchemeOp::TTTLSettings::UNIT_MILLISECONDS: + return 1000; + case NKikimrSchemeOp::TTTLSettings::UNIT_MICROSECONDS: + return 1000 * 1000; + case NKikimrSchemeOp::TTTLSettings::UNIT_NANOSECONDS: + return 1000 * 1000 * 1000; + case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: + return 0; + } + } + TString GetDebugString() const { TStringBuilder sb; sb << "name=" << Name << ";duration=" << EvictDuration << ";column=" << EvictColumnName << ";serializer="; @@ -106,6 +121,7 @@ class TTierRef { }; class TTiering { + using TProto = NKikimrSchemeOp::TColumnDataLifeCycle::TTtl; using TTiersMap = THashMap>; TTiersMap TierByName; TSet OrderedTiers; @@ -199,6 +215,46 @@ class TTiering { return {}; } + TConclusionStatus DeserializeFromProto(const TProto& serialized) { + if (serialized.HasExpireAfterBytes()) { + return TConclusionStatus::Fail("TTL by size is not supported."); + } + if (!serialized.HasColumnName()) { + return TConclusionStatus::Fail("Missing column name in TTL settings"); + } + + const TString ttlColumnName = serialized.GetColumnName(); + const ui32 unitsInSecond = TTierInfo::GetUnitsInSecond(serialized.GetColumnUnit()); + + if (!serialized.TiersSize()) { + // legacy schema + if (!Add(TTierInfo::MakeTtl(TDuration::Seconds(serialized.GetExpireAfterSeconds()), ttlColumnName, unitsInSecond))) { + return TConclusionStatus::Fail("Invalid ttl settings"); + } + } + for (const auto& tier : serialized.GetTiers()) { + if (!tier.HasApplyAfterSeconds()) { + return TConclusionStatus::Fail("Missing eviction delay in tier description"); + } + std::shared_ptr tierInfo; + switch (tier.GetActionCase()) { + case NKikimrSchemeOp::TTTLSettings_TTier::kDelete: + tierInfo = TTierInfo::MakeTtl(TDuration::Seconds(tier.GetApplyAfterSeconds()), ttlColumnName, unitsInSecond); + break; + case NKikimrSchemeOp::TTTLSettings_TTier::kEvictToExternalStorage: + tierInfo = std::make_shared(tier.GetEvictToExternalStorage().GetStorageName(), + TDuration::Seconds(tier.GetApplyAfterSeconds()), ttlColumnName, unitsInSecond); + break; + case NKikimrSchemeOp::TTTLSettings_TTier::ACTION_NOT_SET: + return TConclusionStatus::Fail("No action in tier"); + } + if (!Add(tierInfo)) { + return TConclusionStatus::Fail("Invalid tier settings"); + } + } + return TConclusionStatus::Success(); + } + const TString& GetEvictColumnName() const { AFL_VERIFY(TTLColumnName); return *TTLColumnName; @@ -211,6 +267,21 @@ class TTiering { } return sb; } + + static THashSet GetUsedTiers(const TProto& ttlSettings) { + THashSet usedTiers; + for (const auto& tier : ttlSettings.GetTiers()) { + switch (tier.GetActionCase()) { + case NKikimrSchemeOp::TTTLSettings_TTier::kEvictToExternalStorage: + usedTiers.emplace(tier.GetEvictToExternalStorage().GetStorageName()); + break; + case NKikimrSchemeOp::TTTLSettings_TTier::kDelete: + case NKikimrSchemeOp::TTTLSettings_TTier::ACTION_NOT_SET: + break; + } + } + return usedTiers; + } }; } diff --git a/ydb/core/tx/columnshard/hooks/abstract/abstract.h b/ydb/core/tx/columnshard/hooks/abstract/abstract.h index 506020186346..28470aca8bda 100644 --- a/ydb/core/tx/columnshard/hooks/abstract/abstract.h +++ b/ydb/core/tx/columnshard/hooks/abstract/abstract.h @@ -285,8 +285,8 @@ class ICSController { } virtual NMetadata::NFetcher::ISnapshot::TPtr GetFallbackTiersSnapshot() const { - static std::shared_ptr result = - std::make_shared(TInstant::Now()); + static std::shared_ptr result = + std::make_shared(TInstant::Now()); return result; } diff --git a/ydb/core/tx/columnshard/loading/stages.cpp b/ydb/core/tx/columnshard/loading/stages.cpp index ed9a5fd6f87c..ac4ab092d4db 100644 --- a/ydb/core/tx/columnshard/loading/stages.cpp +++ b/ydb/core/tx/columnshard/loading/stages.cpp @@ -203,7 +203,7 @@ bool TTablesManagerInitializer::DoExecute(NTabletFlatExecutor::TTransactionConte } Self->Counters.GetTabletCounters()->SetCounter(COUNTER_TABLES, tablesManagerLocal.GetTables().size()); Self->Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_PRESETS, tablesManagerLocal.GetSchemaPresets().size()); - Self->Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_TTLS, tablesManagerLocal.GetTtl().PathsCount()); + Self->Counters.GetTabletCounters()->SetCounter(COUNTER_TABLE_TTLS, tablesManagerLocal.GetTtl().size()); Self->TablesManager = std::move(tablesManagerLocal); return true; diff --git a/ydb/core/tx/columnshard/tables_manager.cpp b/ydb/core/tx/columnshard/tables_manager.cpp index 1047b10372fd..d07b960f4b2c 100644 --- a/ydb/core/tx/columnshard/tables_manager.cpp +++ b/ydb/core/tx/columnshard/tables_manager.cpp @@ -132,8 +132,9 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) { vIt = lastVersion.emplace(pathId, version).first; } if (vIt->second <= version) { - TTtl::TDescription description(ttlSettings.GetEnabled()); - Ttl.SetPathTtl(pathId, std::move(description)); + NOlap::TTiering deserializedTtl; + AFL_VERIFY(deserializedTtl.DeserializeFromProto(ttlSettings.GetEnabled()).IsSuccess()); + Ttl[pathId] = std::move(deserializedTtl); vIt->second = version; } } @@ -228,7 +229,7 @@ const TTableInfo& TTablesManager::GetTable(const ui64 pathId) const { } ui64 TTablesManager::GetMemoryUsage() const { - ui64 memory = Tables.size() * sizeof(TTableInfo) + PathsToDrop.size() * sizeof(ui64) + Ttl.PathsCount() * sizeof(TTtl::TDescription); + ui64 memory = Tables.size() * sizeof(TTableInfo) + PathsToDrop.size() * sizeof(ui64) + Ttl.size() * sizeof(NOlap::TTiering); if (PrimaryIndex) { memory += PrimaryIndex->MemoryUsage(); } @@ -240,7 +241,7 @@ void TTablesManager::DropTable(const ui64 pathId, const NOlap::TSnapshot& versio auto& table = Tables[pathId]; table.SetDropVersion(version); PathsToDrop.insert(pathId); - Ttl.DropPathTtl(pathId); + Ttl.erase(pathId); Schema::SaveTableDropVersion(db, pathId, version.GetPlanStep(), version.GetTxId()); } @@ -254,7 +255,7 @@ void TTablesManager::RegisterTable(TTableInfo&& table, NIceDb::TNiceDb& db) { Y_ABORT_UNLESS(!HasTable(table.GetPathId())); Y_ABORT_UNLESS(table.IsEmpty()); - Schema::SaveTableInfo(db, table.GetPathId(), table.GetTieringUsage()); + Schema::SaveTableInfo(db, table.GetPathId()); const ui64 pathId = table.GetPathId(); AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("method", "RegisterTable")("path_id", pathId); AFL_VERIFY(Tables.emplace(pathId, std::move(table)).second)("path_id", pathId)("size", Tables.size()); @@ -298,7 +299,7 @@ void TTablesManager::AddSchemaVersion(const ui32 presetId, const NOlap::TSnapsho PrimaryIndex->RegisterTable(i.first); } if (manager->IsReady()) { - PrimaryIndex->OnTieringModified(manager, Ttl, {}); + PrimaryIndex->OnTieringModified(Ttl); } } else { PrimaryIndex->RegisterSchemaVersion(version, NOlap::IColumnEngine::TSchemaInitializationData(versionInfo)); @@ -333,12 +334,18 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot& if (versionInfo.HasTtlSettings()) { const auto& ttlSettings = versionInfo.GetTtlSettings(); if (ttlSettings.HasEnabled()) { - Ttl.SetPathTtl(pathId, TTtl::TDescription(ttlSettings.GetEnabled())); + NOlap::TTiering deserializedTtl; + AFL_VERIFY(deserializedTtl.DeserializeFromProto(ttlSettings.GetEnabled()).IsSuccess()); + Ttl[pathId] = std::move(deserializedTtl); } else { - Ttl.DropPathTtl(pathId); + Ttl.erase(pathId); } if (PrimaryIndex && manager->IsReady()) { - PrimaryIndex->OnTieringModified(manager, Ttl, pathId); + if (auto findTtl = Ttl.FindPtr(pathId)) { + PrimaryIndex->OnTieringModified(*findTtl, pathId); + } else { + PrimaryIndex->OnTieringModified({}, pathId); + } } } Schema::SaveTableVersionInfo(db, pathId, version, versionInfo); diff --git a/ydb/core/tx/columnshard/tables_manager.h b/ydb/core/tx/columnshard/tables_manager.h index 5f6928f7cce6..f44ca4c872ce 100644 --- a/ydb/core/tx/columnshard/tables_manager.h +++ b/ydb/core/tx/columnshard/tables_manager.h @@ -1,7 +1,6 @@ #pragma once #include "columnshard_schema.h" -#include "columnshard_ttl.h" #include "blobs_action/abstract/storages_manager.h" #include "data_accessor/manager.h" @@ -10,6 +9,7 @@ #include #include #include +#include #include @@ -93,20 +93,10 @@ class TSchemaPreset: public TVersionedSchema DropVersion; YDB_READONLY_DEF(TSet, Versions); public: - const TString& GetTieringUsage() const { - return TieringUsage; - } - - TTableInfo& SetTieringUsage(const TString& data) { - TieringUsage = data; - return *this; - } - bool IsEmpty() const { return Versions.empty(); } @@ -136,7 +126,6 @@ class TTableInfo { template bool InitFromDB(const TRow& rowset) { PathId = rowset.template GetValue(); - TieringUsage = rowset.template GetValue(); if (rowset.template HaveValue() && rowset.template HaveValue()) { DropVersion.emplace( rowset.template GetValue(), rowset.template GetValue()); @@ -151,7 +140,7 @@ class TTablesManager { THashSet SchemaPresetsIds; THashMap ActualSchemaForPreset; THashSet PathsToDrop; - TTtl Ttl; + THashMap Ttl; std::unique_ptr PrimaryIndex; std::shared_ptr StoragesManager; std::shared_ptr DataAccessorsManager; @@ -171,14 +160,10 @@ class TTablesManager { bool TryFinalizeDropPathOnExecute(NTable::TDatabase& dbTable, const ui64 pathId) const; bool TryFinalizeDropPathOnComplete(const ui64 pathId); - const TTtl& GetTtl() const { + const THashMap& GetTtl() const { return Ttl; } - bool AddTtls(THashMap& eviction) { - return Ttl.AddTtls(eviction); - } - const THashSet& GetPathsToDrop() const { return PathsToDrop; } diff --git a/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.cpp b/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.cpp index 8e08a0fd331f..e8d016f45d17 100644 --- a/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.cpp +++ b/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.cpp @@ -372,17 +372,11 @@ TSerializedTableRange MakeTestRange(std::pair range, bool inclusiveF } NMetadata::NFetcher::ISnapshot::TPtr TTestSchema::BuildSnapshot(const TTableSpecials& specials) { - std::unique_ptr cs(new NColumnShard::NTiers::TConfigsSnapshot(Now())); + std::unique_ptr cs(new NColumnShard::NTiers::TTiersSnapshot(Now())); if (specials.Tiers.empty()) { return cs; } - NColumnShard::NTiers::TTieringRule tRule; - tRule.SetTieringRuleId("Tiering1"); for (auto&& tier : specials.Tiers) { - if (!tRule.GetDefaultColumn()) { - tRule.SetDefaultColumn(tier.TtlColumn); - } - UNIT_ASSERT(tRule.GetDefaultColumn() == tier.TtlColumn); { NKikimrSchemeOp::TStorageTierConfig cProto; cProto.SetName(tier.Name); @@ -396,9 +390,7 @@ NMetadata::NFetcher::ISnapshot::TPtr TTestSchema::BuildSnapshot(const TTableSpec NColumnShard::NTiers::TTierConfig tConfig(tier.Name, cProto); cs->MutableTierConfigs().emplace(tConfig.GetTierName(), tConfig); } - tRule.AddInterval(tier.Name, TDuration::Seconds((*tier.EvictAfter).Seconds())); } - cs->MutableTableTierings().emplace(tRule.GetTieringRuleId(), tRule); return cs; } diff --git a/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.h b/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.h index 3dd60dcb8bb0..20418f574cf9 100644 --- a/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.h +++ b/ydb/core/tx/columnshard/test_helper/columnshard_ut_common.h @@ -246,22 +246,25 @@ struct TTestSchema { const TTableSpecials& specials, NKikimrSchemeOp::TColumnTableSchema* schema); - static void InitTtl(const TTableSpecials& specials, NKikimrSchemeOp::TColumnDataLifeCycle::TTtl* ttl) { - Y_ABORT_UNLESS(specials.HasTtl()); - Y_ABORT_UNLESS(!specials.TtlColumn.empty()); - ttl->SetColumnName(specials.TtlColumn); - ttl->SetExpireAfterSeconds((*specials.EvictAfter).Seconds()); - } - static bool InitTiersAndTtl(const TTableSpecials& specials, NKikimrSchemeOp::TColumnDataLifeCycle* ttlSettings) { ttlSettings->SetVersion(1); - if (specials.HasTiers()) { - ttlSettings->SetUseTiering("Tiering1"); + if (!specials.HasTiers() && !specials.HasTtl()) { + return false; + } + ttlSettings->MutableEnabled()->SetColumnName(specials.TtlColumn); + for (const auto& tier : specials.Tiers) { + UNIT_ASSERT(tier.EvictAfter); + UNIT_ASSERT_EQUAL(specials.TtlColumn, tier.TtlColumn); + auto* tierSettings = ttlSettings->MutableEnabled()->AddTiers(); + tierSettings->MutableEvictToExternalStorage()->SetStorageName(tier.Name); + tierSettings->SetApplyAfterSeconds(tier.EvictAfter->Seconds()); } if (specials.HasTtl()) { - InitTtl(specials, ttlSettings->MutableEnabled()); + auto* tier = ttlSettings->MutableEnabled()->AddTiers(); + tier->MutableDelete(); + tier->SetApplyAfterSeconds((*specials.EvictAfter).Seconds()); } - return specials.HasTiers() || specials.HasTtl(); + return true; } static TString CreateTableTxBody(ui64 pathId, const std::vector& columns, diff --git a/ydb/core/tx/schemeshard/common/validation.cpp b/ydb/core/tx/schemeshard/common/validation.cpp index 2ef0e4f89a37..0dcb2cfa331c 100644 --- a/ydb/core/tx/schemeshard/common/validation.cpp +++ b/ydb/core/tx/schemeshard/common/validation.cpp @@ -57,9 +57,9 @@ bool TTTLValidator::ValidateUnit(const NScheme::TTypeInfo columnType, NKikimrSch return true; } -bool TTTLValidator::ValidateTiers(const NKikimrSchemeOp::TTTLSettings::TEnabled ttlSettings, TString& errStr) { - for (ui64 i = 0; i < ttlSettings.TiersSize(); ++i) { - if (ttlSettings.GetTiers(i).HasDelete() && i + 1 != ttlSettings.TiersSize()) { +bool TTTLValidator::ValidateTiers(const google::protobuf::RepeatedPtrField& tiers, TString& errStr) { + for (i64 i = 0; i < tiers.size(); ++i) { + if (tiers[i].HasDelete() && i + 1 != tiers.size()) { errStr = "Only the last tier in TTL settings can have Delete action"; return false; } diff --git a/ydb/core/tx/schemeshard/common/validation.h b/ydb/core/tx/schemeshard/common/validation.h index 0ee739982ea7..e110a72e85fd 100644 --- a/ydb/core/tx/schemeshard/common/validation.h +++ b/ydb/core/tx/schemeshard/common/validation.h @@ -9,6 +9,8 @@ namespace NKikimr::NSchemeShard::NValidation { class TTTLValidator { public: static bool ValidateUnit(const NScheme::TTypeInfo columnType, NKikimrSchemeOp::TTTLSettings::EUnit unit, TString& errStr); - static bool ValidateTiers(const NKikimrSchemeOp::TTTLSettings::TEnabled ttlSettings, TString& errStr); + static bool ValidateTiers(const google::protobuf::RepeatedPtrField& tiers, TString& errStr); + +private: }; } diff --git a/ydb/core/tx/schemeshard/olap/manager/manager.cpp b/ydb/core/tx/schemeshard/olap/manager/manager.cpp index 4d91e3c07f8e..0df8e96f0e6b 100644 --- a/ydb/core/tx/schemeshard/olap/manager/manager.cpp +++ b/ydb/core/tx/schemeshard/olap/manager/manager.cpp @@ -3,25 +3,43 @@ namespace NKikimr::NSchemeShard { void TTablesStorage::OnAddObject(const TPathId& pathId, TColumnTableInfo::TPtr object) { - const TString& tieringId = object->Description.GetTtlSettings().GetUseTiering(); - if (!!tieringId) { - PathsByTieringId[tieringId].emplace(pathId); + for (const auto& tier : object->Description.GetTtlSettings().GetEnabled().GetTiers()) { + std::optional usedExternalStorage; + switch (tier.GetActionCase()) { + case NKikimrSchemeOp::TTTLSettings_TTier::kEvictToExternalStorage: + usedExternalStorage = tier.GetEvictToExternalStorage().GetStorageName(); + break; + case NKikimrSchemeOp::TTTLSettings_TTier::kDelete: + case NKikimrSchemeOp::TTTLSettings_TTier::ACTION_NOT_SET: + break; + } + if (usedExternalStorage) { + AFL_VERIFY(PathsByTier[*usedExternalStorage].emplace(pathId).second); + } } for (auto&& s : object->GetColumnShards()) { - TablesByShard[s].AddId(pathId); + AFL_VERIFY(TablesByShard[s].AddId(pathId)); } } void TTablesStorage::OnRemoveObject(const TPathId& pathId, TColumnTableInfo::TPtr object) { - const TString& tieringId = object->Description.GetTtlSettings().GetUseTiering(); - if (!!tieringId) { - auto it = PathsByTieringId.find(tieringId); - if (PathsByTieringId.end() == it) { - return; + for (const auto& tier : object->Description.GetTtlSettings().GetEnabled().GetTiers()) { + std::optional usedExternalStorage; + switch (tier.GetActionCase()) { + case NKikimrSchemeOp::TTTLSettings_TTier::kEvictToExternalStorage: + usedExternalStorage = tier.GetEvictToExternalStorage().GetStorageName(); + break; + case NKikimrSchemeOp::TTTLSettings_TTier::kDelete: + case NKikimrSchemeOp::TTTLSettings_TTier::ACTION_NOT_SET: + break; } - it->second.erase(pathId); - if (it->second.empty()) { - PathsByTieringId.erase(it); + if (usedExternalStorage) { + auto findTier = PathsByTier.find(*usedExternalStorage); + AFL_VERIFY(findTier); + AFL_VERIFY(findTier->second.erase(pathId)); + if (findTier->second.empty()) { + PathsByTier.erase(findTier); + } } } for (auto&& s : object->GetColumnShards()) { @@ -29,9 +47,9 @@ void TTablesStorage::OnRemoveObject(const TPathId& pathId, TColumnTableInfo::TPt } } -const THashSet& TTablesStorage::GetTablesWithTiering(const TString& tieringId) const { - auto it = PathsByTieringId.find(tieringId); - if (it != PathsByTieringId.end()) { +const THashSet& TTablesStorage::GetTablesWithTier(const TString& storageId) const { + auto it = PathsByTier.find(storageId); + if (it != PathsByTier.end()) { return it->second; } else { return Default>(); @@ -78,13 +96,14 @@ TTablesStorage::TTableCreatedGuard TTablesStorage::BuildNew(const TPathId& id) { return TTableCreatedGuard(*this, id); } -size_t TTablesStorage::Drop(const TPathId& id) { +bool TTablesStorage::Drop(const TPathId& id) { auto it = Tables.find(id); if (it == Tables.end()) { - return 0; + return false; } else { OnRemoveObject(id, it->second); - return Tables.erase(id); + Tables.erase(it); + return true; } } diff --git a/ydb/core/tx/schemeshard/olap/manager/manager.h b/ydb/core/tx/schemeshard/olap/manager/manager.h index 0873a12da22d..8c025690e97a 100644 --- a/ydb/core/tx/schemeshard/olap/manager/manager.h +++ b/ydb/core/tx/schemeshard/olap/manager/manager.h @@ -9,7 +9,7 @@ namespace NKikimr::NSchemeShard { class TTablesStorage { private: THashMap Tables; - THashMap> PathsByTieringId; + THashMap> PathsByTier; THashMap TablesByShard; void OnAddObject(const TPathId& pathId, TColumnTableInfo::TPtr object); @@ -20,7 +20,7 @@ class TTablesStorage { TColumnTablesLayout GetTablesLayout(const std::vector& tabletIds) const; - const THashSet& GetTablesWithTiering(const TString& tieringId) const; + const THashSet& GetTablesWithTier(const TString& storageId) const; class TTableReadGuard { protected: @@ -115,7 +115,7 @@ class TTablesStorage { TTableReadGuard at(const TPathId& id) const { return TTableReadGuard(Tables.at(id)); } - size_t Drop(const TPathId& id); + bool Drop(const TPathId& id); }; } diff --git a/ydb/core/tx/schemeshard/olap/operations/alter/abstract/converter.h b/ydb/core/tx/schemeshard/olap/operations/alter/abstract/converter.h index 6a36133245e9..da5db2ad1117 100644 --- a/ydb/core/tx/schemeshard/olap/operations/alter/abstract/converter.h +++ b/ydb/core/tx/schemeshard/olap/operations/alter/abstract/converter.h @@ -26,15 +26,10 @@ class TConverterModifyToAlter { if (enabled.HasColumnUnit()) { alterEnabled->SetColumnUnit(enabled.GetColumnUnit()); } - for (const auto& tier : enabled.GetTiers()) { - alterEnabled->AddTiers()->CopyFrom(tier); - } + *alterEnabled->MutableTiers() = enabled.GetTiers(); } else if (tableTtl.HasDisabled()) { alterTtl->MutableDisabled(); } - if (tableTtl.HasUseTiering()) { - alterTtl->SetUseTiering(tableTtl.GetUseTiering()); - } } for (auto&& dsColumn : dsDescription.GetColumns()) { diff --git a/ydb/core/tx/schemeshard/olap/operations/alter_table.cpp b/ydb/core/tx/schemeshard/olap/operations/alter_table.cpp index 4fb76b4a75a0..850151c51dd3 100644 --- a/ydb/core/tx/schemeshard/olap/operations/alter_table.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/alter_table.cpp @@ -271,8 +271,7 @@ class TAlterColumnTable: public TSubOperation { return result; } - const bool hasTiering = Transaction.HasAlterColumnTable() && Transaction.GetAlterColumnTable().HasAlterTtlSettings() && - Transaction.GetAlterColumnTable().GetAlterTtlSettings().HasUseTiering(); + const bool hasTiering = Transaction.GetAlterColumnTable().GetAlterTtlSettings().GetEnabled().TiersSize(); if (hasTiering && HasAppData() && !AppDataVerified().FeatureFlags.GetEnableTieringInColumnShard()) { result->SetError(NKikimrScheme::StatusPreconditionFailed, "Tiering functionality is disabled for OLAP tables"); return result; diff --git a/ydb/core/tx/schemeshard/olap/ttl/schema.cpp b/ydb/core/tx/schemeshard/olap/ttl/schema.cpp index 379f35012d24..f1b6e73c93ff 100644 --- a/ydb/core/tx/schemeshard/olap/ttl/schema.cpp +++ b/ydb/core/tx/schemeshard/olap/ttl/schema.cpp @@ -5,9 +5,6 @@ namespace NKikimr::NSchemeShard::NOlap::NAlter { TConclusionStatus TOlapTTL::Update(const TOlapTTLUpdate& update) { const ui64 currentTtlVersion = Proto.GetVersion(); const auto& ttlUpdate = update.GetPatch(); - if (ttlUpdate.HasUseTiering()) { - Proto.SetUseTiering(ttlUpdate.GetUseTiering()); - } if (ttlUpdate.HasEnabled()) { *Proto.MutableEnabled() = ttlUpdate.GetEnabled(); } diff --git a/ydb/core/tx/schemeshard/olap/ttl/validator.cpp b/ydb/core/tx/schemeshard/olap/ttl/validator.cpp index 8cae2a0b4fdb..e4a3e2b5d389 100644 --- a/ydb/core/tx/schemeshard/olap/ttl/validator.cpp +++ b/ydb/core/tx/schemeshard/olap/ttl/validator.cpp @@ -44,7 +44,7 @@ bool TTTLValidator::ValidateColumnTableTtl(const NKikimrSchemeOp::TColumnDataLif return false; } - if (!ttl.HasExpireAfterSeconds()) { + if (!ttl.HasExpireAfterSeconds() && ttl.GetTiers().empty()) { errors.AddError("TTL without eviction time"); return false; } @@ -66,6 +66,10 @@ bool TTTLValidator::ValidateColumnTableTtl(const NKikimrSchemeOp::TColumnDataLif errors.AddError(errStr); return false; } + if (!NValidation::TTTLValidator::ValidateTiers(ttl.GetTiers(), errStr)) { + errors.AddError(errStr); + return false; + } { bool correct = false; if (column->GetKeyOrder() && *column->GetKeyOrder() == 0) { diff --git a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp index 7d86703aab85..edf4e8a5506e 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp +++ b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp @@ -1218,12 +1218,22 @@ TCheckFunc HasColumnTableTtlSettingsDisabled() { }; } -TCheckFunc HasColumnTableTtlSettingsTiering(const TString& tieringName) { +TCheckFunc HasColumnTableTtlSettingsTier(const TString& columnName, const TDuration& evictAfter, const std::optional& storageName) { return [=] (const NKikimrScheme::TEvDescribeSchemeResult& record) { const auto& table = record.GetPathDescription().GetColumnTableDescription(); UNIT_ASSERT(table.HasTtlSettings()); const auto& ttl = table.GetTtlSettings(); - UNIT_ASSERT_EQUAL(ttl.GetUseTiering(), tieringName); + UNIT_ASSERT(ttl.HasEnabled()); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().GetColumnName(), columnName); + UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().TiersSize(), 1); + const auto& tier = ttl.GetEnabled().GetTiers(0); + UNIT_ASSERT_VALUES_EQUAL(tier.GetApplyAfterSeconds(), evictAfter.Seconds()); + if (storageName) { + UNIT_ASSERT(tier.HasEvictToExternalStorage()); + UNIT_ASSERT_VALUES_EQUAL(tier.GetEvictToExternalStorage().GetStorageName(), storageName); + } else { + UNIT_ASSERT(tier.HasDelete()); + } }; } diff --git a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h index bcd1e2c0e163..c46f6bc5c610 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h +++ b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h @@ -134,7 +134,7 @@ namespace NLs { TCheckFunc HasColumnTableTtlSettingsVersion(ui64 ttlSettingsVersion); TCheckFunc HasColumnTableTtlSettingsEnabled(const TString& columnName, const TDuration& expireAfter); TCheckFunc HasColumnTableTtlSettingsDisabled(); - TCheckFunc HasColumnTableTtlSettingsTiering(const TString& tierName); + TCheckFunc HasColumnTableTtlSettingsTier(const TString& columnName, const TDuration& evictAfter, const std::optional& storageName); TCheckFunc CheckPartCount(const TString& name, ui32 partCount, ui32 maxParts, ui32 tabletCount, ui32 groupCount, NKikimrSchemeOp::EPathState pathState = NKikimrSchemeOp::EPathState::EPathStateNoChanges); diff --git a/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp b/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp index f0f5fb0832ee..5545ce39eda3 100644 --- a/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp +++ b/ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp @@ -470,7 +470,14 @@ Y_UNIT_TEST_SUITE(TOlap) { Name: "Table3" ColumnShardCount: 1 TtlSettings { - UseTiering : "Tiering1" + Enabled: { + ColumnName: "timestamp" + ColumnUnit: UNIT_AUTO + Tiers: { + EvictAfterSeconds: 360 + StorageName: "Tier1" + } + } } )"; @@ -481,13 +488,20 @@ Y_UNIT_TEST_SUITE(TOlap) { NLs::HasColumnTableSchemaPreset("default"), NLs::HasColumnTableSchemaVersion(1), NLs::HasColumnTableTtlSettingsVersion(1), - NLs::HasColumnTableTtlSettingsTiering("Tiering1"))); + NLs::HasColumnTableTtlSettingsTier("timestamp", TDuration::Seconds(360), "Tier1"))); TString tableSchema4 = R"( Name: "Table4" ColumnShardCount: 1 TtlSettings { - UseTiering : "Tiering1" + Enabled: { + ColumnName: "timestamp" + ColumnUnit: UNIT_AUTO + Tiers: { + EvictAfterSeconds: 3600000000 + StorageName: "Tier1" + } + } } )"; @@ -631,7 +645,14 @@ Y_UNIT_TEST_SUITE(TOlap) { TestAlterColumnTable(runtime, ++txId, "/MyRoot/OlapStore", R"( Name: "ColumnTable" AlterTtlSettings { - UseTiering : "Tiering1" + Enabled: { + ColumnName: "timestamp" + ColumnUnit: UNIT_AUTO + Tiers: { + EvictAfterSeconds: 3600000000 + StorageName: "Tier1" + } + } } )"); env.TestWaitNotification(runtime, txId); diff --git a/ydb/core/tx/tiering/external_data.cpp b/ydb/core/tx/tiering/external_data.cpp index b6616bc760aa..812215b01ff3 100644 --- a/ydb/core/tx/tiering/external_data.cpp +++ b/ydb/core/tx/tiering/external_data.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -19,11 +18,7 @@ TSnapshotConstructor::TSnapshotConstructor() { } std::vector TSnapshotConstructor::DoGetManagers() const { - std::vector result = { - TTierConfig::GetBehaviour(), - TTieringRule::GetBehaviour() - }; - return result; + return { TTierConfig::GetBehaviour() }; } } diff --git a/ydb/core/tx/tiering/external_data.h b/ydb/core/tx/tiering/external_data.h index 02b963ab6d4b..456ad1ff59e3 100644 --- a/ydb/core/tx/tiering/external_data.h +++ b/ydb/core/tx/tiering/external_data.h @@ -9,7 +9,7 @@ namespace NKikimr::NColumnShard::NTiers { -class TSnapshotConstructor: public NMetadata::NFetcher::TSnapshotsFetcher { +class TSnapshotConstructor: public NMetadata::NFetcher::TSnapshotsFetcher { private: using TNavigate = NSchemeCache::TSchemeCacheNavigate; using TBaseActor = TActor; diff --git a/ydb/core/tx/tiering/manager.cpp b/ydb/core/tx/tiering/manager.cpp index 57462d745d3a..dbe06df7e0d4 100644 --- a/ydb/core/tx/tiering/manager.cpp +++ b/ydb/core/tx/tiering/manager.cpp @@ -12,7 +12,7 @@ class TTiersManager::TActor: public TActorBootstrapped { std::shared_ptr Owner; NMetadata::NFetcher::ISnapshotsFetcher::TPtr SecretsFetcher; std::shared_ptr SecretsSnapshot; - std::shared_ptr ConfigsSnapshot; + std::shared_ptr ConfigsSnapshot; TActorId GetExternalDataActorId() const { return NMetadata::NProvider::MakeServiceId(SelfId().NodeId()); } @@ -45,7 +45,7 @@ class TTiersManager::TActor: public TActorBootstrapped { void Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& ev) { auto snapshot = ev->Get()->GetSnapshot(); - if (auto configs = std::dynamic_pointer_cast(snapshot)) { + if (auto configs = std::dynamic_pointer_cast(snapshot)) { AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "TEvRefreshSubscriberData")("snapshot", "configs"); ConfigsSnapshot = configs; if (SecretsSnapshot) { @@ -123,7 +123,7 @@ void TTiersManager::TakeConfigs(NMetadata::NFetcher::ISnapshot::TPtr snapshotExt ALS_INFO(NKikimrServices::TX_TIERING) << "Take configs:" << (snapshotExt ? " snapshots" : "") << (secrets ? " secrets" : "") << " at tablet " << TabletId; - auto snapshotPtr = std::dynamic_pointer_cast(snapshotExt); + auto snapshotPtr = std::dynamic_pointer_cast(snapshotExt); Y_ABORT_UNLESS(snapshotPtr); Snapshot = snapshotExt; Secrets = secrets; @@ -192,32 +192,6 @@ NMetadata::NFetcher::ISnapshotsFetcher::TPtr TTiersManager::GetExternalDataManip return ExternalDataManipulation; } -THashMap TTiersManager::GetTiering() const { - THashMap result; - AFL_VERIFY(IsReady()); - auto snapshotPtr = std::dynamic_pointer_cast(Snapshot); - Y_ABORT_UNLESS(snapshotPtr); - auto& tierConfigs = snapshotPtr->GetTierConfigs(); - for (auto&& i : PathIdTiering) { - auto* tieringRule = snapshotPtr->GetTieringById(i.second); - if (tieringRule) { - AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("path_id", i.first)("tiering_name", i.second)("event", "activation"); - NOlap::TTiering tiering = tieringRule->BuildOlapTiers(); - for (auto& [name, tier] : tiering.GetTierByName()) { - AFL_VERIFY(name != NOlap::NTiering::NCommon::DeleteTierName); - auto it = tierConfigs.find(name); - if (it != tierConfigs.end()) { - tier->SetSerializer(NTiers::ConvertCompression(it->second.GetCompression())); - } - } - result.emplace(i.first, std::move(tiering)); - } else { - AFL_ERROR(NKikimrServices::TX_COLUMNSHARD)("path_id", i.first)("tiering_name", i.second)("event", "not_found"); - } - } - return result; -} - TActorId TTiersManager::GetActorId() const { if (Actor) { return Actor->SelfId(); diff --git a/ydb/core/tx/tiering/manager.h b/ydb/core/tx/tiering/manager.h index 147ee27f54f8..d0a464e40e61 100644 --- a/ydb/core/tx/tiering/manager.h +++ b/ydb/core/tx/tiering/manager.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -53,7 +54,6 @@ class TTiersManager: public ITiersManager { const TActorId TabletActorId; std::function ShardCallback; TActor* Actor = nullptr; - std::unordered_map PathIdTiering; TManagers Managers; std::shared_ptr Secrets; @@ -69,13 +69,10 @@ class TTiersManager: public ITiersManager { { } TActorId GetActorId() const; - THashMap GetTiering() const; void TakeConfigs(NMetadata::NFetcher::ISnapshot::TPtr snapshot, std::shared_ptr secrets); - void EnablePathId(const ui64 pathId, const TString& tieringId) { - PathIdTiering.emplace(pathId, tieringId); + void EnablePathId(const ui64 /*pathId*/, const THashSet& /*usedTiers*/) { } - void DisablePathId(const ui64 pathId) { - PathIdTiering.erase(pathId); + void DisablePathId(const ui64 /*pathId*/) { } bool IsReady() const { diff --git a/ydb/core/tx/tiering/rule/behaviour.cpp b/ydb/core/tx/tiering/rule/behaviour.cpp deleted file mode 100644 index df7ad1973101..000000000000 --- a/ydb/core/tx/tiering/rule/behaviour.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "behaviour.h" -#include "initializer.h" -#include "checker.h" -#include "manager.h" - -namespace NKikimr::NColumnShard::NTiers { - -TTieringRuleBehaviour::TFactory::TRegistrator TTieringRuleBehaviour::Registrator(TTieringRule::GetTypeId()); - -TString TTieringRuleBehaviour::GetInternalStorageTablePath() const { - return "tiering/rules"; -} - -NMetadata::NInitializer::IInitializationBehaviour::TPtr TTieringRuleBehaviour::ConstructInitializer() const { - return std::make_shared(); -} - -NMetadata::NModifications::IOperationsManager::TPtr TTieringRuleBehaviour::ConstructOperationsManager() const { - return std::make_shared(); -} - -TString TTieringRuleBehaviour::GetTypeId() const { - return TTieringRule::GetTypeId(); -} - -} diff --git a/ydb/core/tx/tiering/rule/behaviour.h b/ydb/core/tx/tiering/rule/behaviour.h deleted file mode 100644 index c10f2f24d73f..000000000000 --- a/ydb/core/tx/tiering/rule/behaviour.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "object.h" -#include - -namespace NKikimr::NColumnShard::NTiers { - -class TTieringRuleBehaviour: public NMetadata::TClassBehaviour { -private: - static TFactory::TRegistrator Registrator; -protected: - virtual std::shared_ptr ConstructInitializer() const override; - virtual std::shared_ptr ConstructOperationsManager() const override; - - virtual TString GetInternalStorageTablePath() const override; - virtual TString GetTypeId() const override; - -}; - -} diff --git a/ydb/core/tx/tiering/rule/checker.cpp b/ydb/core/tx/tiering/rule/checker.cpp deleted file mode 100644 index 1210b66ed0b4..000000000000 --- a/ydb/core/tx/tiering/rule/checker.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "checker.h" -#include "ss_checker.h" - -#include -#include -#include -#include -#include -#include - -namespace NKikimr::NColumnShard::NTiers { - -void TRulePreparationActor::StartChecker() { - if (!Tierings || !Secrets || !SSCheckResult) { - return; - } - auto g = PassAwayGuard(); - if (!SSCheckResult->GetContent().GetOperationAllow()) { - Controller->OnPreparationProblem(SSCheckResult->GetContent().GetDenyReason()); - return; - } - - for (auto&& tiering : Objects) { - for (auto&& interval : tiering.GetIntervals()) { - auto tier = Tierings->GetTierById(interval.GetTierName()); - if (!tier) { - Controller->OnPreparationProblem("unknown tier usage: " + interval.GetTierName()); - return; - } else if (!Secrets->CheckSecretAccess(tier->GetAccessKey(), Context.GetExternalData().GetUserToken())) { - Controller->OnPreparationProblem("no access for secret: " + tier->GetAccessKey().DebugString()); - return; - } else if (!Secrets->CheckSecretAccess(tier->GetSecretKey(), Context.GetExternalData().GetUserToken())) { - Controller->OnPreparationProblem("no access for secret: " + tier->GetSecretKey().DebugString()); - return; - } - } - } - Controller->OnPreparationFinished(std::move(Objects)); -} - -void TRulePreparationActor::Handle(NSchemeShard::TEvSchemeShard::TEvProcessingResponse::TPtr& ev) { - auto& proto = ev->Get()->Record; - if (proto.HasError()) { - Controller->OnPreparationProblem(proto.GetError().GetErrorMessage()); - PassAway(); - } else if (proto.HasContent()) { - SSCheckResult = SSFetcher->UnpackResult(ev->Get()->Record.GetContent().GetData()); - if (!SSCheckResult) { - Controller->OnPreparationProblem("cannot unpack ss-fetcher result for class " + SSFetcher->GetClassName()); - PassAway(); - } else { - StartChecker(); - } - } else { - Y_ABORT_UNLESS(false); - } -} - -void TRulePreparationActor::Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& ev) { - if (auto snapshot = ev->Get()->GetSnapshotPtrAs()) { - Tierings = snapshot; - } else if (auto snapshot = ev->Get()->GetSnapshotPtrAs()) { - Secrets = snapshot; - } else { - Y_ABORT_UNLESS(false); - } - StartChecker(); -} - -void TRulePreparationActor::Bootstrap() { - Become(&TThis::StateMain); - Send(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()), - new NMetadata::NProvider::TEvAskSnapshot(std::make_shared())); - Send(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()), - new NMetadata::NProvider::TEvAskSnapshot(std::make_shared())); - { - SSFetcher = std::make_shared(); - SSFetcher->SetUserToken(Context.GetExternalData().GetUserToken()); - SSFetcher->SetActivityType(Context.GetActivityType()); - for (auto&& i : Objects) { - SSFetcher->MutableTieringRuleIds().emplace(i.GetTieringRuleId()); - } - Register(new TSSFetchingActor(SSFetcher, std::make_shared(SelfId()), TDuration::Seconds(10))); - } -} - -TRulePreparationActor::TRulePreparationActor(std::vector&& objects, - NMetadata::NModifications::IAlterPreparationController::TPtr controller, - const NMetadata::NModifications::IOperationsManager::TInternalModificationContext& context) - : Objects(std::move(objects)) - , Controller(controller) - , Context(context) -{ - -} - -} diff --git a/ydb/core/tx/tiering/rule/checker.h b/ydb/core/tx/tiering/rule/checker.h deleted file mode 100644 index ec6e0f3d66e7..000000000000 --- a/ydb/core/tx/tiering/rule/checker.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "object.h" -#include "ss_fetcher.h" - -#include -#include - -#include -#include -#include -#include - -namespace NKikimr::NColumnShard::NTiers { - -class TRulePreparationActor: public NActors::TActorBootstrapped { -private: - std::vector Objects; - NMetadata::NModifications::IAlterPreparationController::TPtr Controller; - NMetadata::NModifications::IOperationsManager::TInternalModificationContext Context; - std::shared_ptr Tierings; - std::shared_ptr Secrets; - std::shared_ptr SSFetcher; - std::optional SSCheckResult; - void StartChecker(); -protected: - void Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& ev); - void Handle(NSchemeShard::TEvSchemeShard::TEvProcessingResponse::TPtr& ev); -public: - STATEFN(StateMain) { - switch (ev->GetTypeRewrite()) { - hFunc(NMetadata::NProvider::TEvRefreshSubscriberData, Handle); - hFunc(NSchemeShard::TEvSchemeShard::TEvProcessingResponse, Handle); - default: - break; - } - } - void Bootstrap(); - - TRulePreparationActor(std::vector&& objects, - NMetadata::NModifications::IAlterPreparationController::TPtr controller, - const NMetadata::NModifications::IOperationsManager::TInternalModificationContext& context); -}; - -} diff --git a/ydb/core/tx/tiering/rule/initializer.cpp b/ydb/core/tx/tiering/rule/initializer.cpp deleted file mode 100644 index 96c1c3cff550..000000000000 --- a/ydb/core/tx/tiering/rule/initializer.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "initializer.h" -#include "object.h" - -namespace NKikimr::NColumnShard::NTiers { - -TVector TTierRulesInitializer::BuildModifiers() const { - TVector result; - { - Ydb::Table::CreateTableRequest request; - request.set_session_id(""); - request.set_path(TTieringRule::GetBehaviour()->GetStorageTablePath()); - request.add_primary_key("tieringRuleId"); - { - auto& column = *request.add_columns(); - column.set_name("tieringRuleId"); - column.mutable_type()->mutable_optional_type()->mutable_item()->set_type_id(Ydb::Type::UTF8); - } - { - auto& column = *request.add_columns(); - column.set_name("defaultColumn"); - column.mutable_type()->mutable_optional_type()->mutable_item()->set_type_id(Ydb::Type::UTF8); - } - { - auto& column = *request.add_columns(); - column.set_name("description"); - column.mutable_type()->mutable_optional_type()->mutable_item()->set_type_id(Ydb::Type::UTF8); - } - result.emplace_back(new NMetadata::NInitializer::TGenericTableModifier(request, "create")); - auto hRequest = TTieringRule::AddHistoryTableScheme(request); - result.emplace_back(new NMetadata::NInitializer::TGenericTableModifier(hRequest, "create_history")); - } - result.emplace_back(NMetadata::NInitializer::TACLModifierConstructor::GetReadOnlyModifier(TTieringRule::GetBehaviour()->GetStorageTablePath(), "acl")); - result.emplace_back(NMetadata::NInitializer::TACLModifierConstructor::GetReadOnlyModifier(TTieringRule::GetBehaviour()->GetStorageHistoryTablePath(), "acl_history")); - return result; -} - -void TTierRulesInitializer::DoPrepare(NMetadata::NInitializer::IInitializerInput::TPtr controller) const { - controller->OnPreparationFinished(BuildModifiers()); -} - -} diff --git a/ydb/core/tx/tiering/rule/initializer.h b/ydb/core/tx/tiering/rule/initializer.h deleted file mode 100644 index 93f15e78f9c4..000000000000 --- a/ydb/core/tx/tiering/rule/initializer.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include -#include - -namespace NKikimr::NColumnShard::NTiers { - -class TTierRulesInitializer: public NMetadata::NInitializer::IInitializationBehaviour { -protected: - TVector BuildModifiers() const; - virtual void DoPrepare(NMetadata::NInitializer::IInitializerInput::TPtr controller) const override; -public: -}; - -} diff --git a/ydb/core/tx/tiering/rule/manager.cpp b/ydb/core/tx/tiering/rule/manager.cpp deleted file mode 100644 index 88ff0533c444..000000000000 --- a/ydb/core/tx/tiering/rule/manager.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "manager.h" -#include "initializer.h" -#include "checker.h" - -namespace NKikimr::NColumnShard::NTiers { - -void TTieringRulesManager::DoPrepareObjectsBeforeModification(std::vector&& objects, - NMetadata::NModifications::IAlterPreparationController::TPtr controller, - const TInternalModificationContext& context, const NMetadata::NModifications::TAlterOperationContext& /*alterContext*/) const { - TActivationContext::Register(new TRulePreparationActor(std::move(objects), controller, context)); -} - -NMetadata::NModifications::TOperationParsingResult TTieringRulesManager::DoBuildPatchFromSettings( - const NYql::TObjectSettingsImpl& settings, - TInternalModificationContext& /*context*/) const { - if (HasAppData() && !AppDataVerified().FeatureFlags.GetEnableTieringInColumnShard()) { - return TConclusionStatus::Fail("Tiering functionality is disabled for OLAP tables."); - } - - NMetadata::NInternal::TTableRecord result; - result.SetColumn(TTieringRule::TDecoder::TieringRuleId, NMetadata::NInternal::TYDBValue::Utf8(settings.GetObjectId())); - if (settings.GetObjectId().StartsWith("$") || settings.GetObjectId().StartsWith("_")) { - return TConclusionStatus::Fail("tiering rule cannot start with '$', '_' characters"); - } - { - auto fValue = settings.GetFeaturesExtractor().Extract(TTieringRule::TDecoder::DefaultColumn); - if (fValue) { - if (fValue->empty()) { - return TConclusionStatus::Fail("defaultColumn cannot be empty"); - } - result.SetColumn(TTieringRule::TDecoder::DefaultColumn, NMetadata::NInternal::TYDBValue::Utf8(*fValue)); - } - } - { - auto fValue = settings.GetFeaturesExtractor().Extract(TTieringRule::TDecoder::Description); - if (fValue) { - result.SetColumn(TTieringRule::TDecoder::Description, NMetadata::NInternal::TYDBValue::Utf8(*fValue)); - } - } - return result; -} - -} diff --git a/ydb/core/tx/tiering/rule/manager.h b/ydb/core/tx/tiering/rule/manager.h deleted file mode 100644 index d5646dbf3002..000000000000 --- a/ydb/core/tx/tiering/rule/manager.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "object.h" - -#include - -namespace NKikimr::NColumnShard::NTiers { - -class TTieringRulesManager: public NMetadata::NModifications::TGenericOperationsManager { -protected: - virtual void DoPrepareObjectsBeforeModification(std::vector&& objects, - NMetadata::NModifications::IAlterPreparationController::TPtr controller, - const TInternalModificationContext& context, const NMetadata::NModifications::TAlterOperationContext& alterContext) const override; - - virtual NMetadata::NModifications::TOperationParsingResult DoBuildPatchFromSettings(const NYql::TObjectSettingsImpl& settings, - TInternalModificationContext& context) const override; -}; - -} diff --git a/ydb/core/tx/tiering/rule/object.cpp b/ydb/core/tx/tiering/rule/object.cpp deleted file mode 100644 index 18dfc9288bc1..000000000000 --- a/ydb/core/tx/tiering/rule/object.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "object.h" -#include "behaviour.h" - -#include -#include - -#include - -namespace NKikimr::NColumnShard::NTiers { - -NJson::TJsonValue TTieringRule::GetDebugJson() const { - NJson::TJsonValue result = NJson::JSON_MAP; - result.InsertValue(TDecoder::TieringRuleId, TieringRuleId); - result.InsertValue(TDecoder::DefaultColumn, DefaultColumn); - result.InsertValue(TDecoder::Description, SerializeDescriptionToJson()); - return result; -} - -NJson::TJsonValue TTieringRule::SerializeDescriptionToJson() const { - NJson::TJsonValue result = NJson::JSON_MAP; - auto& jsonRules = result.InsertValue("rules", NJson::JSON_ARRAY); - for (auto&& i : Intervals) { - jsonRules.AppendValue(i.SerializeToJson()); - } - return result; -} - -bool TTieringRule::DeserializeDescriptionFromJson(const NJson::TJsonValue& jsonInfo) { - const NJson::TJsonValue::TArray* rules; - if (!jsonInfo["rules"].GetArrayPointer(&rules)) { - return false; - } - if (rules->empty()) { - AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "tiering_rule_deserialization_failed")("reason", "empty_rules"); - return false; - } - for (auto&& i : *rules) { - TTieringInterval interval; - if (!interval.DeserializeFromJson(i)) { - return false; - } - Intervals.emplace_back(std::move(interval)); - } - std::sort(Intervals.begin(), Intervals.end()); - return true; -} - -NMetadata::NInternal::TTableRecord TTieringRule::SerializeToRecord() const { - NMetadata::NInternal::TTableRecord result; - result.SetColumn(TDecoder::TieringRuleId, NMetadata::NInternal::TYDBValue::Utf8(TieringRuleId)); - result.SetColumn(TDecoder::DefaultColumn, NMetadata::NInternal::TYDBValue::Utf8(DefaultColumn)); - { - auto jsonDescription = SerializeDescriptionToJson(); - NJsonWriter::TBuf sout; - sout.WriteJsonValue(&jsonDescription, true); - result.SetColumn(TDecoder::Description, NMetadata::NInternal::TYDBValue::Utf8(sout.Str())); - } - return result; -} - -bool TTieringRule::DeserializeFromRecord(const TDecoder& decoder, const Ydb::Value& r) { - if (!decoder.Read(decoder.GetTieringRuleIdIdx(), TieringRuleId, r)) { - return false; - } - if (!decoder.Read(decoder.GetDefaultColumnIdx(), DefaultColumn, r)) { - return false; - } - if (DefaultColumn.empty()) { - return false; - } - NJson::TJsonValue jsonDescription; - if (!decoder.ReadJson(decoder.GetDescriptionIdx(), jsonDescription, r)) { - return false; - } - if (!DeserializeDescriptionFromJson(jsonDescription)) { - return false; - } - return true; -} - -NKikimr::NOlap::TTiering TTieringRule::BuildOlapTiers() const { - AFL_VERIFY(!Intervals.empty()); - NOlap::TTiering result; - for (auto&& r : Intervals) { - AFL_VERIFY(result.Add(std::make_shared(r.GetTierName(), r.GetDurationForEvict(), GetDefaultColumn()))); - } - return result; -} - -bool TTieringRule::ContainsTier(const TString& tierName) const { - for (auto&& i : Intervals) { - if (i.GetTierName() == tierName) { - return true; - } - } - return false; -} - -NMetadata::IClassBehaviour::TPtr TTieringRule::GetBehaviour() { - static std::shared_ptr result = std::make_shared(); - return result; -} - -} diff --git a/ydb/core/tx/tiering/rule/object.h b/ydb/core/tx/tiering/rule/object.h deleted file mode 100644 index 566f10e5efc8..000000000000 --- a/ydb/core/tx/tiering/rule/object.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once -#include -#include - -#include -#include -#include -#include - -#include - -namespace NKikimr::NColumnShard::NTiers { - -class TTieringInterval { -private: - YDB_ACCESSOR_DEF(TString, TierName); - YDB_ACCESSOR_DEF(TDuration, DurationForEvict); -public: - TTieringInterval() = default; - TTieringInterval(const TString& name, const TDuration d) - : TierName(name) - , DurationForEvict(d) - { - - } - - bool operator<(const TTieringInterval& item) const { - return DurationForEvict < item.DurationForEvict; - } - - NJson::TJsonValue SerializeToJson() const { - NJson::TJsonValue result; - result.InsertValue("tierName", TierName); - result.InsertValue("durationForEvict", DurationForEvict.ToString()); - return result; - } - - bool DeserializeFromJson(const NJson::TJsonValue& jsonInfo) { - if (!jsonInfo["tierName"].GetString(&TierName)) { - return false; - } - const TString dStr = jsonInfo["durationForEvict"].GetStringRobust(); - if (!TDuration::TryParse(dStr, DurationForEvict)) { - return false; - } - return true; - } -}; - -class TTieringRule: public NMetadata::NModifications::TObject { -private: - YDB_ACCESSOR_DEF(TString, TieringRuleId); - YDB_ACCESSOR_DEF(TString, DefaultColumn); - YDB_ACCESSOR_DEF(TVector, Intervals); -protected: - NJson::TJsonValue SerializeDescriptionToJson() const; - bool DeserializeDescriptionFromJson(const NJson::TJsonValue& jsonInfo); -public: - static NMetadata::IClassBehaviour::TPtr GetBehaviour(); - - bool ContainsTier(const TString& tierName) const; - - void AddInterval(const TString& name, const TDuration evDuration) { - Intervals.emplace_back(TTieringInterval(name, evDuration)); - } - - static TString GetTypeId() { - return "TIERING_RULE"; - } - - NJson::TJsonValue GetDebugJson() const; - - class TDecoder: public NMetadata::NInternal::TDecoderBase { - private: - YDB_READONLY(i32, TieringRuleIdIdx, -1); - YDB_READONLY(i32, DefaultColumnIdx, -1); - YDB_READONLY(i32, DescriptionIdx, -1); - public: - static inline const TString TieringRuleId = "tieringRuleId"; - static inline const TString DefaultColumn = "defaultColumn"; - static inline const TString Description = "description"; - - TDecoder(const Ydb::ResultSet& rawData) { - TieringRuleIdIdx = GetFieldIndex(rawData, TieringRuleId); - DefaultColumnIdx = GetFieldIndex(rawData, DefaultColumn); - DescriptionIdx = GetFieldIndex(rawData, Description); - } - }; - NMetadata::NInternal::TTableRecord SerializeToRecord() const; - bool DeserializeFromRecord(const TDecoder& decoder, const Ydb::Value& r); - NKikimr::NOlap::TTiering BuildOlapTiers() const; -}; - -} diff --git a/ydb/core/tx/tiering/rule/ya.make b/ydb/core/tx/tiering/rule/ya.make deleted file mode 100644 index 80b625857c1f..000000000000 --- a/ydb/core/tx/tiering/rule/ya.make +++ /dev/null @@ -1,24 +0,0 @@ -LIBRARY() - -SRCS( - manager.cpp - object.cpp - GLOBAL behaviour.cpp - initializer.cpp - checker.cpp - ss_checker.cpp - GLOBAL ss_fetcher.cpp -) - -PEERDIR( - ydb/services/metadata/abstract - ydb/services/metadata/common - ydb/services/metadata/initializer - ydb/services/metadata/manager - ydb/services/bg_tasks/abstract - ydb/core/tx/schemeshard -) - -YQL_LAST_ABI_VERSION() - -END() diff --git a/ydb/core/tx/tiering/snapshot.cpp b/ydb/core/tx/tiering/snapshot.cpp index cfc003d7ba7b..d64987b5b62e 100644 --- a/ydb/core/tx/tiering/snapshot.cpp +++ b/ydb/core/tx/tiering/snapshot.cpp @@ -9,14 +9,13 @@ namespace NKikimr::NColumnShard::NTiers { -bool TConfigsSnapshot::DoDeserializeFromResultSet(const Ydb::Table::ExecuteQueryResult& rawDataResult) { - Y_ABORT_UNLESS(rawDataResult.result_sets().size() == 2); +bool TTiersSnapshot::DoDeserializeFromResultSet(const Ydb::Table::ExecuteQueryResult& rawDataResult) { + Y_ABORT_UNLESS(rawDataResult.result_sets().size() == 1); ParseSnapshotObjects(rawDataResult.result_sets()[0], [this](TTierConfig&& s) {TierConfigs.emplace(s.GetTierName(), s); }); - ParseSnapshotObjects(rawDataResult.result_sets()[1], [this](TTieringRule&& s) {TableTierings.emplace(s.GetTieringRuleId(), s); }); return true; } -std::optional TConfigsSnapshot::GetTierById(const TString& tierName) const { +std::optional TTiersSnapshot::GetTierById(const TString& tierName) const { auto it = TierConfigs.find(tierName); if (it == TierConfigs.end()) { return {}; @@ -25,38 +24,12 @@ std::optional TConfigsSnapshot::GetTierById(const TString& tierName } } -const TTieringRule* TConfigsSnapshot::GetTieringById(const TString& tieringId) const { - auto it = TableTierings.find(tieringId); - if (it == TableTierings.end()) { - return nullptr; - } else { - return &it->second; - } -} - -std::set TConfigsSnapshot::GetTieringIdsForTier(const TString& tierName) const { - std::set result; - for (auto&& i : TableTierings) { - for (auto&& t : i.second.GetIntervals()) { - if (t.GetTierName() == tierName) { - result.emplace(i.second.GetTieringRuleId()); - break; - } - } - } - return result; -} - -TString NTiers::TConfigsSnapshot::DoSerializeToString() const { +TString NTiers::TTiersSnapshot::DoSerializeToString() const { NJson::TJsonValue result = NJson::JSON_MAP; auto& jsonTiers = result.InsertValue("tiers", NJson::JSON_MAP); for (auto&& i : TierConfigs) { jsonTiers.InsertValue(i.first, i.second.GetDebugJson()); } - auto& jsonTiering = result.InsertValue("rules", NJson::JSON_MAP); - for (auto&& i : TableTierings) { - jsonTiering.InsertValue(i.first, i.second.GetDebugJson()); - } return result.GetStringRobust(); } diff --git a/ydb/core/tx/tiering/snapshot.h b/ydb/core/tx/tiering/snapshot.h index db323d11f253..4eea9921c56a 100644 --- a/ydb/core/tx/tiering/snapshot.h +++ b/ydb/core/tx/tiering/snapshot.h @@ -2,7 +2,6 @@ #include #include #include -#include #include @@ -10,20 +9,15 @@ namespace NKikimr::NColumnShard::NTiers { -class TConfigsSnapshot: public NMetadata::NFetcher::ISnapshot { +class TTiersSnapshot: public NMetadata::NFetcher::ISnapshot { private: using TBase = NMetadata::NFetcher::ISnapshot; using TConfigsMap = TMap; YDB_ACCESSOR_DEF(TConfigsMap, TierConfigs); - using TTieringMap = TMap; - YDB_ACCESSOR_DEF(TTieringMap, TableTierings); protected: virtual bool DoDeserializeFromResultSet(const Ydb::Table::ExecuteQueryResult& rawData) override; virtual TString DoSerializeToString() const override; public: - - std::set GetTieringIdsForTier(const TString& tierName) const; - const TTieringRule* GetTieringById(const TString& tieringId) const; std::optional GetTierById(const TString& tierName) const; using TBase::TBase; }; diff --git a/ydb/core/tx/tiering/tier/checker.cpp b/ydb/core/tx/tiering/tier/checker.cpp index 1fd719069d43..32ec8da0e7b4 100644 --- a/ydb/core/tx/tiering/tier/checker.cpp +++ b/ydb/core/tx/tiering/tier/checker.cpp @@ -1,36 +1,16 @@ #include "checker.h" #include -#include #include namespace NKikimr::NColumnShard::NTiers { void TTierPreparationActor::StartChecker() { - if (!Tierings || !Secrets || !SSCheckResult) { + if (!Secrets) { return; } auto g = PassAwayGuard(); - if (!SSCheckResult->GetContent().GetOperationAllow()) { - Controller->OnPreparationProblem(SSCheckResult->GetContent().GetDenyReason()); - return; - } for (auto&& tier : Objects) { - if (Context.GetActivityType() == NMetadata::NModifications::IOperationsManager::EActivityType::Drop) { - std::set tieringsWithTiers; - for (auto&& i : Tierings->GetTableTierings()) { - if (i.second.ContainsTier(tier.GetTierName())) { - tieringsWithTiers.emplace(i.first); - if (tieringsWithTiers.size() > 10) { - break; - } - } - } - if (tieringsWithTiers.size()) { - Controller->OnPreparationProblem("tier in usage for tierings: " + JoinSeq(", ", tieringsWithTiers)); - return; - } - } if (!Secrets->CheckSecretAccess(tier.GetAccessKey(), Context.GetExternalData().GetUserToken())) { Controller->OnPreparationProblem("no access for secret: " + tier.GetAccessKey().DebugString()); return; @@ -42,49 +22,9 @@ void TTierPreparationActor::StartChecker() { Controller->OnPreparationFinished(std::move(Objects)); } -void TTierPreparationActor::Handle(NSchemeShard::TEvSchemeShard::TEvProcessingResponse::TPtr& ev) { - auto& proto = ev->Get()->Record; - if (proto.HasError()) { - Controller->OnPreparationProblem(proto.GetError().GetErrorMessage()); - PassAway(); - } else if (proto.HasContent()) { - SSCheckResult = SSFetcher->UnpackResult(ev->Get()->Record.GetContent().GetData()); - if (!SSCheckResult) { - Controller->OnPreparationProblem("cannot unpack ss-fetcher result for class " + SSFetcher->GetClassName()); - PassAway(); - } else { - StartChecker(); - } - } else { - Y_ABORT_UNLESS(false); - } -} - void TTierPreparationActor::Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& ev) { if (auto snapshot = ev->Get()->GetSnapshotPtrAs()) { Secrets = snapshot; - } else if (auto snapshot = ev->Get()->GetSnapshotPtrAs()) { - Tierings = snapshot; - std::set tieringIds; - std::set tiersChecked; - for (auto&& tier : Objects) { - if (!tiersChecked.emplace(tier.GetTierName()).second) { - continue; - } - auto tIds = Tierings->GetTieringIdsForTier(tier.GetTierName()); - if (tieringIds.empty()) { - tieringIds = std::move(tIds); - } else { - tieringIds.insert(tIds.begin(), tIds.end()); - } - } - { - SSFetcher = std::make_shared(); - SSFetcher->SetUserToken(Context.GetExternalData().GetUserToken()); - SSFetcher->SetActivityType(Context.GetActivityType()); - SSFetcher->MutableTieringRuleIds() = tieringIds; - Register(new TSSFetchingActor(SSFetcher, std::make_shared(SelfId()), TDuration::Seconds(10))); - } } else { Y_ABORT_UNLESS(false); } @@ -95,8 +35,6 @@ void TTierPreparationActor::Bootstrap() { Become(&TThis::StateMain); Send(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()), new NMetadata::NProvider::TEvAskSnapshot(std::make_shared())); - Send(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()), - new NMetadata::NProvider::TEvAskSnapshot(std::make_shared())); } TTierPreparationActor::TTierPreparationActor(std::vector&& objects, diff --git a/ydb/core/tx/tiering/tier/checker.h b/ydb/core/tx/tiering/tier/checker.h index 2b1d5ffd2e7a..109c9de208aa 100644 --- a/ydb/core/tx/tiering/tier/checker.h +++ b/ydb/core/tx/tiering/tier/checker.h @@ -2,7 +2,6 @@ #include "object.h" #include -#include #include #include @@ -18,18 +17,13 @@ class TTierPreparationActor: public NActors::TActorBootstrapped::TPtr Controller; NMetadata::NModifications::IOperationsManager::TInternalModificationContext Context; std::shared_ptr Secrets; - std::shared_ptr Tierings; - std::shared_ptr SSFetcher; - std::optional SSCheckResult; void StartChecker(); protected: void Handle(NMetadata::NProvider::TEvRefreshSubscriberData::TPtr& ev); - void Handle(NSchemeShard::TEvSchemeShard::TEvProcessingResponse::TPtr& ev); public: STATEFN(StateMain) { switch (ev->GetTypeRewrite()) { hFunc(NMetadata::NProvider::TEvRefreshSubscriberData, Handle); - hFunc(NSchemeShard::TEvSchemeShard::TEvProcessingResponse, Handle); default: break; } diff --git a/ydb/core/tx/tiering/rule/ss_checker.cpp b/ydb/core/tx/tiering/tier/ss_checker.cpp similarity index 100% rename from ydb/core/tx/tiering/rule/ss_checker.cpp rename to ydb/core/tx/tiering/tier/ss_checker.cpp diff --git a/ydb/core/tx/tiering/rule/ss_checker.h b/ydb/core/tx/tiering/tier/ss_checker.h similarity index 100% rename from ydb/core/tx/tiering/rule/ss_checker.h rename to ydb/core/tx/tiering/tier/ss_checker.h diff --git a/ydb/core/tx/tiering/rule/ss_fetcher.cpp b/ydb/core/tx/tiering/tier/ss_fetcher.cpp similarity index 100% rename from ydb/core/tx/tiering/rule/ss_fetcher.cpp rename to ydb/core/tx/tiering/tier/ss_fetcher.cpp diff --git a/ydb/core/tx/tiering/rule/ss_fetcher.h b/ydb/core/tx/tiering/tier/ss_fetcher.h similarity index 100% rename from ydb/core/tx/tiering/rule/ss_fetcher.h rename to ydb/core/tx/tiering/tier/ss_fetcher.h diff --git a/ydb/core/tx/tiering/tier/ya.make b/ydb/core/tx/tiering/tier/ya.make index f319e8e28af1..822435a2ec4c 100644 --- a/ydb/core/tx/tiering/tier/ya.make +++ b/ydb/core/tx/tiering/tier/ya.make @@ -6,9 +6,11 @@ SRCS( initializer.cpp checker.cpp GLOBAL behaviour.cpp + ss_checker.cpp ) PEERDIR( + ydb/services/bg_tasks/abstract ydb/services/metadata/initializer ydb/services/metadata/abstract ydb/services/metadata/secret diff --git a/ydb/core/tx/tiering/ut/ut_tiers.cpp b/ydb/core/tx/tiering/ut/ut_tiers.cpp index d3b707a24c0a..0afdde164162 100644 --- a/ydb/core/tx/tiering/ut/ut_tiers.cpp +++ b/ydb/core/tx/tiering/ut/ut_tiers.cpp @@ -75,9 +75,6 @@ class TLocalHelper: public Tests::NCS::THelper { TBase::CreateTestOlapTable(sender, storeName, Sprintf(R"( Name: "%s" ColumnShardCount: %d - TtlSettings: { - UseTiering: "tiering1" - } Sharding { HashSharding { Function: %s @@ -219,7 +216,6 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TActorId ProviderId; TInstant Start; YDB_READONLY_FLAG(Found, false); - YDB_ACCESSOR(ui32, ExpectedTieringsCount, 1); YDB_ACCESSOR(ui32, ExpectedTiersCount, 1); using TKeyCheckers = TMap; @@ -261,17 +257,12 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { } void CheckFound(NMetadata::NProvider::TEvRefreshSubscriberData* event) { - auto snapshot = event->GetSnapshotAs(); + auto snapshot = event->GetSnapshotAs(); if (!snapshot) { Cerr << "incorrect snapshot" << Endl; return; } Cerr << "SNAPSHOT: " << snapshot->SerializeToString() << Endl; - const auto& tierings = snapshot->GetTableTierings(); - if (tierings.size() != ExpectedTieringsCount) { - Cerr << "TieringsCount incorrect: " << snapshot->SerializeToString() << ";expectation=" << ExpectedTieringsCount << Endl; - return; - } if (ExpectedTiersCount != snapshot->GetTierConfigs().size()) { Cerr << "TiersCount incorrect: " << snapshot->SerializeToString() << ";expectation=" << ExpectedTiersCount << Endl; return; @@ -281,9 +272,6 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { if (i.first.StartsWith("TIER.")) { auto value = snapshot->GetTierById(i.first.substr(5)); jsonData = value->SerializeConfigToJson(); - } else if (i.first.StartsWith("TIERING_RULE.")) { - auto value = snapshot->GetTierById(i.first.substr(13)); - jsonData = value->SerializeConfigToJson(); } else { Y_ABORT_UNLESS(false); } @@ -344,25 +332,23 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { Tests::TClient client(serverSettings); auto& runtime = *server->GetRuntime(); + runtime.SetLogPriority(NKikimrServices::TX_TIERING, NLog::PRI_DEBUG); auto sender = runtime.AllocateEdgeActor(); server->SetupRootStoragePools(sender); TLocalHelper lHelper(*server); - lHelper.CreateTestOlapTable(); { - TTestCSEmulator* emulator = new TTestCSEmulator; + lHelper.CreateTestOlapTable(); + lHelper.StartSchemaRequest("CREATE OBJECT tier1 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc") + "`"); + lHelper.StartSchemaRequest("CREATE OBJECT tier2 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc") + "`"); + lHelper.StartSchemaRequest(R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10D") TO EXTERNAL DATA SOURCE tier1, Interval("P20D") TO EXTERNAL DATA SOURCE tier2 ON timestamp)"); + + TTestCSEmulator* emulator = new TTestCSEmulator(); emulator->MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "abc")); emulator->SetExpectedTiersCount(2); runtime.Register(emulator); runtime.SimulateSleep(TDuration::Seconds(10)); Cerr << "Initialization finished" << Endl; - - lHelper.StartSchemaRequest("CREATE OBJECT tier1 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc") + "`"); - lHelper.StartSchemaRequest("CREATE OBJECT tiering1 (" - "TYPE TIERING_RULE) WITH (defaultColumn = timestamp, description = `" + ConfigTiering1Str + "` )", false); - lHelper.StartSchemaRequest("CREATE OBJECT tier2 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc") + "`"); - lHelper.StartSchemaRequest("CREATE OBJECT tiering1 (" - "TYPE TIERING_RULE) WITH (defaultColumn = timestamp, description = `" + ConfigTiering1Str + "` )"); { const TInstant start = Now(); while (!emulator->IsFound() && Now() - start < TDuration::Seconds(2000)) { @@ -387,13 +373,11 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { } { emulator->ResetConditions(); - emulator->SetExpectedTieringsCount(0); emulator->SetExpectedTiersCount(0); - lHelper.StartSchemaRequest("DROP OBJECT tier1(TYPE TIER)", false); - lHelper.StartSchemaRequest("DROP OBJECT tiering1(TYPE TIERING_RULE)", false); + // TODO: add validation + // lHelper.StartSchemaRequest("DROP OBJECT tier1(TYPE TIER)", false); lHelper.StartSchemaRequest("DROP TABLE `/Root/olapStore/olapTable`"); - lHelper.StartSchemaRequest("DROP OBJECT tiering1(TYPE TIERING_RULE)"); lHelper.StartSchemaRequest("DROP OBJECT tier1(TYPE TIER)"); lHelper.StartSchemaRequest("DROP OBJECT tier2(TYPE TIER)"); @@ -438,56 +422,52 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TLocalHelper lHelper(*server); lHelper.SetUseQueryService(useQueryService); - lHelper.CreateTestOlapTable("olapTable"); - runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_NOTICE); runtime.SetLogPriority(NKikimrServices::TX_COLUMNSHARD, NLog::PRI_INFO); + runtime.SetLogPriority(NKikimrServices::TX_TIERING, NLog::PRI_DEBUG); // runtime.SetLogPriority(NKikimrServices::TX_PROXY_SCHEME_CACHE, NLog::PRI_DEBUG); runtime.SimulateSleep(TDuration::Seconds(10)); Cerr << "Initialization finished" << Endl; lHelper.StartSchemaRequest("CREATE OBJECT tier1 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc1") + "`", true, false); { - TTestCSEmulator emulator; - emulator.MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "abc1")); - emulator.SetExpectedTieringsCount(0); - emulator.SetExpectedTiersCount(1); - emulator.CheckRuntime(runtime); + TTestCSEmulator* emulator = new TTestCSEmulator; + runtime.Register(emulator); + emulator->MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "abc1")); + emulator->SetExpectedTiersCount(1); + emulator->CheckRuntime(runtime); } lHelper.StartSchemaRequest("CREATE OBJECT tier2 (TYPE TIER) WITH tierConfig = `" + GetConfigProtoWithName("abc2") + "`"); - lHelper.StartSchemaRequest("CREATE OBJECT IF NOT EXISTS tiering1 (TYPE TIERING_RULE) " - "WITH (defaultColumn = timestamp, description = `" + ConfigTiering1Str + "`)"); - lHelper.StartSchemaRequest("CREATE OBJECT tiering2 (TYPE TIERING_RULE) " - "WITH (defaultColumn = timestamp, description = `" + ConfigTiering2Str + "` )", true, false); { - TTestCSEmulator emulator; - emulator.MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "abc1")); - emulator.MutableCheckers().emplace("TIER.tier2", TJsonChecker("Name", "abc2")); - emulator.SetExpectedTieringsCount(2); - emulator.SetExpectedTiersCount(2); - emulator.CheckRuntime(runtime); - } - - lHelper.StartSchemaRequest("DROP OBJECT tier2 (TYPE TIER)", false); - lHelper.StartSchemaRequest("DROP OBJECT tier1 (TYPE TIER)", false); - lHelper.StartSchemaRequest("DROP OBJECT tiering2 (TYPE TIERING_RULE)"); - lHelper.StartSchemaRequest("DROP OBJECT tiering1 (TYPE TIERING_RULE)", false); + TTestCSEmulator* emulator = new TTestCSEmulator(); + runtime.Register(emulator); + emulator->MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "abc1")); + emulator->MutableCheckers().emplace("TIER.tier2", TJsonChecker("Name", "abc2")); + emulator->SetExpectedTiersCount(2); + emulator->CheckRuntime(runtime); + } + + lHelper.CreateTestOlapTable("olapTable"); + lHelper.StartSchemaRequest(R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10D") TO EXTERNAL DATA SOURCE tier1, Interval("P20D") TO EXTERNAL DATA SOURCE tier2 ON timestamp)"); + + // TODO: add validation + // lHelper.StartSchemaRequest("DROP OBJECT tier2 (TYPE TIER)", false); + // lHelper.StartSchemaRequest("DROP OBJECT tier1 (TYPE TIER)", false); lHelper.StartSchemaRequest("DROP TABLE `/Root/olapStore/olapTable`"); - lHelper.StartSchemaRequest("DROP OBJECT tiering1 (TYPE TIERING_RULE)", true, false); { - TTestCSEmulator emulator; - emulator.SetExpectedTieringsCount(0); - emulator.SetExpectedTiersCount(2); - emulator.CheckRuntime(runtime); + TTestCSEmulator* emulator = new TTestCSEmulator; + runtime.Register(emulator); + emulator->SetExpectedTiersCount(2); + emulator->CheckRuntime(runtime); } lHelper.StartSchemaRequest("DROP OBJECT tier2 (TYPE TIER)"); lHelper.StartSchemaRequest("DROP OBJECT tier1 (TYPE TIER)", true, false); { - TTestCSEmulator emulator; - emulator.SetExpectedTieringsCount(0); - emulator.SetExpectedTiersCount(0); - emulator.CheckRuntime(runtime); + TTestCSEmulator* emulator = new TTestCSEmulator; + runtime.Register(emulator); + emulator->SetExpectedTiersCount(0); + emulator->CheckRuntime(runtime); } //runtime.SetLogPriority(NKikimrServices::TX_PROXY, NLog::PRI_TRACE); @@ -573,6 +553,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { // runtime.SetLogPriority(NKikimrServices::TX_DATASHARD, NLog::PRI_NOTICE); runtime.SetLogPriority(NKikimrServices::TX_COLUMNSHARD, NLog::PRI_DEBUG); runtime.SetLogPriority(NKikimrServices::BG_TASKS, NLog::PRI_DEBUG); + // runtime.SetLogPriority(NKikimrServices::TX_TIERING, NLog::PRI_DEBUG); // runtime.SetLogPriority(NKikimrServices::TX_PROXY_SCHEME_CACHE, NLog::PRI_DEBUG); TLocalHelper lHelper(*server); @@ -587,21 +568,17 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { "TYPE TIER) WITH (tierConfig = `" + TierConfigProtoStr + "`)"); lHelper.StartSchemaRequest("CREATE OBJECT tier2 ( " "TYPE TIER) WITH (tierConfig = `" + TierConfigProtoStr + "`)"); - - lHelper.StartSchemaRequest("CREATE OBJECT tiering1 (" - "TYPE TIERING_RULE) WITH (defaultColumn = timestamp, description = `" + ConfigTiering1Str + "` )"); - lHelper.StartSchemaRequest("CREATE OBJECT tiering2 (" - "TYPE TIERING_RULE) WITH (defaultColumn = timestamp, description = `" + ConfigTiering2Str + "` )"); { - TTestCSEmulator* emulator = new TTestCSEmulator; + TTestCSEmulator* emulator = new TTestCSEmulator(); runtime.Register(emulator); emulator->MutableCheckers().emplace("TIER.tier1", TJsonChecker("Name", "fakeTier")); emulator->MutableCheckers().emplace("TIER.tier2", TJsonChecker("ObjectStorage.Endpoint", TierEndpoint)); - emulator->SetExpectedTieringsCount(2); emulator->SetExpectedTiersCount(2); emulator->CheckRuntime(runtime); } + lHelper.CreateTestOlapTable("olapTable", 2); + lHelper.StartSchemaRequest(R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10D") TO EXTERNAL DATA SOURCE tier1, Interval("P20D") TO EXTERNAL DATA SOURCE tier2 ON timestamp)"); Cerr << "Wait tables" << Endl; runtime.SimulateSleep(TDuration::Seconds(20)); Cerr << "Initialization tables" << Endl; @@ -647,8 +624,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { lHelper.DropTable("/Root/olapStore/olapTable"); lHelper.StartDataRequest("DELETE FROM `/Root/olapStore/olapTable`"); */ - lHelper.StartSchemaRequest("UPSERT OBJECT tiering1 (" - "TYPE TIERING_RULE) WITH (defaultColumn = timestamp, description = `" + ConfigTieringNothingStr + "` )"); + lHelper.StartSchemaRequest(R"(ALTER TABLE `/Root/olapStore/olapTable` SET TTL Interval("P10000D") TO EXTERNAL DATA SOURCE tier1, Interval("P20000D") TO EXTERNAL DATA SOURCE tier2 ON timestamp)"); { const TInstant start = Now(); bool check = false; @@ -939,11 +915,11 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { { TVector> result; lHelper.StartScanRequest("SELECT MAX(timestamp) as a, MIN(timestamp) as b, COUNT(*) as c FROM `/Root/olapStore/olapTable`", true, &result); - UNIT_ASSERT(result.size() == 1); - UNIT_ASSERT(result.front().size() == 3); - UNIT_ASSERT(GetValueResult(result.front(), "c")->GetProto().uint64_value() == 600000); - UNIT_ASSERT(GetValueResult(result.front(), "a")->GetProto().uint64_value() == 599999000000); - UNIT_ASSERT(GetValueResult(result.front(), "b")->GetProto().uint64_value() == 0); + UNIT_ASSERT_VALUES_EQUAL(result.size(), 1); + UNIT_ASSERT_VALUES_EQUAL(result.front().size(), 3); + UNIT_ASSERT_VALUES_EQUAL(GetValueResult(result.front(), "c")->GetProto().uint64_value(), 600000); + UNIT_ASSERT_VALUES_EQUAL(GetValueResult(result.front(), "a")->GetProto().uint64_value(), 599999000000); + UNIT_ASSERT_VALUES_EQUAL(GetValueResult(result.front(), "b")->GetProto().uint64_value(), 0); } const ui32 reduceStepsCount = 1; for (ui32 i = 0; i < reduceStepsCount; ++i) { diff --git a/ydb/core/tx/tiering/ya.make b/ydb/core/tx/tiering/ya.make index b7412d358938..4090ce51fb6d 100644 --- a/ydb/core/tx/tiering/ya.make +++ b/ydb/core/tx/tiering/ya.make @@ -19,7 +19,6 @@ PEERDIR( ydb/core/blobstorage ydb/core/protos ydb/core/tx/schemeshard - ydb/core/tx/tiering/rule ydb/core/tx/tiering/tier ydb/core/tablet_flat/protos ydb/core/wrappers diff --git a/ydb/core/ydb_convert/table_description.cpp b/ydb/core/ydb_convert/table_description.cpp index ba5207084a3c..e35b05368cfd 100644 --- a/ydb/core/ydb_convert/table_description.cpp +++ b/ydb/core/ydb_convert/table_description.cpp @@ -49,8 +49,6 @@ THashSet GetAlterOperationKinds(const Ydb::Table::AlterTabl req->alter_columns_size() || req->ttl_action_case() != Ydb::Table::AlterTableRequest::TTL_ACTION_NOT_SET || - req->tiering_action_case() != - Ydb::Table::AlterTableRequest::TIERING_ACTION_NOT_SET || req->has_alter_storage_settings() || req->add_column_families_size() || req->alter_column_families_size() || req->set_compaction_policy() || req->has_alter_partitioning_settings() || @@ -545,10 +543,6 @@ void FillColumnDescriptionImpl(TYdbProto& out, ythrow yexception() << "invalid TTL settings: " << error; } } - - if (in.GetTTLSettings().HasUseTiering()) { - out.set_tiering(in.GetTTLSettings().GetUseTiering()); - } } } @@ -589,10 +583,6 @@ void FillColumnDescription(Ydb::Table::DescribeTableResult& out, const NKikimrSc ythrow yexception() << "invalid TTL settings: " << error; } } - - if (in.GetTtlSettings().HasUseTiering()) { - out.set_tiering(in.GetTtlSettings().GetUseTiering()); - } } out.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN); @@ -867,12 +857,6 @@ bool BuildAlterColumnTableModifyScheme(const TString& path, const Ydb::Table::Al } else if (req->has_drop_ttl_settings()) { alterColumnTable->MutableAlterTtlSettings()->MutableDisabled(); } - - if (req->has_set_tiering()) { - alterColumnTable->MutableAlterTtlSettings()->SetUseTiering(req->set_tiering()); - } else if (req->has_drop_tiering()) { - alterColumnTable->MutableAlterTtlSettings()->SetUseTiering(""); - } } return true; diff --git a/ydb/core/ydb_convert/table_settings.cpp b/ydb/core/ydb_convert/table_settings.cpp index 367eb7a8db89..9047391c958c 100644 --- a/ydb/core/ydb_convert/table_settings.cpp +++ b/ydb/core/ydb_convert/table_settings.cpp @@ -228,10 +228,6 @@ bool FillCreateTableSettingsDesc(NKikimrSchemeOp::TTableDescription& tableDesc, } } - if (proto.tiering().size()) { - tableDesc.MutableTTLSettings()->SetUseTiering(proto.tiering()); - } - if (proto.has_storage_settings()) { TColumnFamilyManager families(tableDesc.MutablePartitionConfig()); if (!families.ApplyStorageSettings(proto.storage_settings(), &code, &error)) { @@ -391,12 +387,6 @@ bool FillAlterTableSettingsDesc(NKikimrSchemeOp::TTableDescription& tableDesc, tableDesc.MutableTTLSettings()->MutableDisabled(); } - if (proto.has_set_tiering()) { - tableDesc.MutableTTLSettings()->SetUseTiering(proto.set_tiering()); - } else if (proto.has_drop_tiering()) { - tableDesc.MutableTTLSettings()->SetUseTiering(""); - } - if (!changed && !hadPartitionConfig) { tableDesc.ClearPartitionConfig(); } diff --git a/ydb/public/api/protos/draft/ydb_logstore.proto b/ydb/public/api/protos/draft/ydb_logstore.proto index 8c0a24c53aaa..34705aa0f593 100644 --- a/ydb/public/api/protos/draft/ydb_logstore.proto +++ b/ydb/public/api/protos/draft/ydb_logstore.proto @@ -60,10 +60,6 @@ message Tier { Ydb.Table.TtlSettings eviction = 2; // When to evict data to the next tier (or remove if none) } -message TieringSettings { - optional string tiering_id = 2; -} - message CreateLogStoreRequest { Ydb.Operations.OperationParams operation_params = 1; @@ -135,8 +131,8 @@ message CreateLogTableRequest { }; oneof ttl_specification { Ydb.Table.TtlSettings ttl_settings = 5; - TieringSettings tiering_settings = 6; }; + reserved 6; // Specifies the desired number of ColumnShards for this table uint32 shards_count = 7; @@ -160,9 +156,9 @@ message DescribeLogTableResult { string schema_preset_name = 2; Schema schema = 3; + reserved 4; oneof ttl_specification { Ydb.Table.TtlSettings ttl_settings = 5; - TieringSettings tiering_settings = 4; } // Specifies the desired number of ColumnShards for this table @@ -195,9 +191,9 @@ message AlterLogTableRequest { oneof ttl_action { google.protobuf.Empty drop_ttl_settings = 3; Ydb.Table.TtlSettings set_ttl_settings = 4; - TieringSettings set_tiering_settings = 5; google.protobuf.Empty drop_tiering_settings = 6; } + reserved 5; } message AlterLogTableResponse { diff --git a/ydb/public/api/protos/ydb_table.proto b/ydb/public/api/protos/ydb_table.proto index cb6b86286579..172c97ceb3d0 100644 --- a/ydb/public/api/protos/ydb_table.proto +++ b/ydb/public/api/protos/ydb_table.proto @@ -667,8 +667,7 @@ message CreateTableRequest { Ydb.FeatureFlag.Status key_bloom_filter = 16; // Read replicas settings for table ReadReplicasSettings read_replicas_settings = 17; - // Tiering rules name. It specifies how data migrates from one tier (logical storage) to another. - string tiering = 18; + reserved 18; // Is temporary table bool temporary = 19; // Is table column or row oriented @@ -747,11 +746,7 @@ message AlterTableRequest { repeated string drop_changefeeds = 20; // Rename existed index repeated RenameIndexItem rename_indexes = 21; - // Setup or remove tiering - oneof tiering_action { - string set_tiering = 22; - google.protobuf.Empty drop_tiering = 23; - } + reserved 22, 23; } message AlterTableResponse { diff --git a/ydb/public/lib/experimental/ydb_logstore.cpp b/ydb/public/lib/experimental/ydb_logstore.cpp index 758e14986afd..bbfe436889a1 100644 --- a/ydb/public/lib/experimental/ydb_logstore.cpp +++ b/ydb/public/lib/experimental/ydb_logstore.cpp @@ -186,8 +186,6 @@ void TLogTableDescription::SerializeTo(Ydb::LogStore::CreateLogTableRequest& req if (TtlSettings) { TtlSettings->SerializeTo(*request.mutable_ttl_settings()); - } else if (TieringSettings) { - TieringSettings->SerializeTo(*request.mutable_tiering_settings()); } } diff --git a/ydb/public/lib/experimental/ydb_logstore.h b/ydb/public/lib/experimental/ydb_logstore.h index 633730e015da..be8148b023f3 100644 --- a/ydb/public/lib/experimental/ydb_logstore.h +++ b/ydb/public/lib/experimental/ydb_logstore.h @@ -152,21 +152,6 @@ struct TLogTableSharding { TLogTableSharding(const Ydb::LogStore::DescribeLogTableResult& desc); }; -class TTieringSettings { -private: - TString TieringId; -public: - TTieringSettings(const TString& tieringId) - : TieringId(tieringId) { - - } - - void SerializeTo(Ydb::LogStore::TieringSettings& proto) const { - proto.set_tiering_id(TieringId); - } - -}; - class TLogTableDescription { public: TLogTableDescription(const TString& schemaPresetName, const TLogTableSharding& sharding); @@ -200,16 +185,11 @@ class TLogTableDescription { TtlSettings = settings; return *this; } - TLogTableDescription& SetTieringSettings(const TTieringSettings& settings) { - TieringSettings = settings; - return *this; - } private: const TString SchemaPresetName; const TSchema Schema; const TLogTableSharding Sharding; TMaybe TtlSettings; - TMaybe TieringSettings; TString Owner; TVector Permissions; TVector EffectivePermissions; diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.cpp b/ydb/public/sdk/cpp/client/ydb_table/table.cpp index 4f461f920607..ec1596a49334 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.cpp +++ b/ydb/public/sdk/cpp/client/ydb_table/table.cpp @@ -331,11 +331,6 @@ class TTableDescription::TImpl { TtlSettings_ = std::move(*ttlSettings); } - // tiering - if (proto.tiering().size()) { - Tiering_ = proto.tiering(); - } - if (proto.store_type()) { StoreType_ = (proto.store_type() == Ydb::Table::STORE_TYPE_COLUMN) ? EStoreType::Column : EStoreType::Row; } @@ -407,9 +402,7 @@ class TTableDescription::TImpl { } for (const auto& shardStats : Proto_.table_stats().partition_stats()) { - PartitionStats_.emplace_back( - TPartitionStats{shardStats.rows_estimate(), shardStats.store_size(), shardStats.leader_node_id()} - ); + PartitionStats_.emplace_back(TPartitionStats{ shardStats.rows_estimate(), shardStats.store_size(), shardStats.leader_node_id() }); } TableStats.Rows = Proto_.table_stats().rows_estimate(); @@ -566,10 +559,6 @@ class TTableDescription::TImpl { return TtlSettings_; } - const TMaybe& GetTiering() const { - return Tiering_; - } - EStoreType GetStoreType() const { return StoreType_; } @@ -650,7 +639,6 @@ class TTableDescription::TImpl { TVector Indexes_; TVector Changefeeds_; TMaybe TtlSettings_; - TMaybe Tiering_; TString Owner_; TVector Permissions_; TVector EffectivePermissions_; @@ -717,7 +705,7 @@ TMaybe TTableDescription::GetTtlSettings() const { } TMaybe TTableDescription::GetTiering() const { - return Impl_->GetTiering(); + return Nothing(); } EStoreType TTableDescription::GetStoreType() const { @@ -940,10 +928,6 @@ void TTableDescription::SerializeTo(Ydb::Table::CreateTableRequest& request) con ttl->SerializeTo(*request.mutable_ttl_settings()); } - if (const auto& tiering = Impl_->GetTiering()) { - request.set_tiering(*tiering); - } - if (Impl_->GetStoreType() == EStoreType::Column) { request.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN); } diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.h b/ydb/public/sdk/cpp/client/ydb_table/table.h index b58b99a70f4c..56bad7682c5f 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.h +++ b/ydb/public/sdk/cpp/client/ydb_table/table.h @@ -660,6 +660,7 @@ class TTableDescription { TVector GetIndexDescriptions() const; TVector GetChangefeedDescriptions() const; TMaybe GetTtlSettings() const; + // Deprecated. Use GetTtlSettings() instead TMaybe GetTiering() const; EStoreType GetStoreType() const; From 2908bf9c5adf928e4cf6d547075cab14f5e6319f Mon Sep 17 00:00:00 2001 From: Semyon Yentsov Date: Thu, 28 Nov 2024 12:27:37 +0000 Subject: [PATCH 2/3] fix build --- ydb/core/kqp/provider/yql_kikimr_gateway.cpp | 2 +- ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ydb/core/kqp/provider/yql_kikimr_gateway.cpp b/ydb/core/kqp/provider/yql_kikimr_gateway.cpp index 717b393478a3..d4533f7d8960 100644 --- a/ydb/core/kqp/provider/yql_kikimr_gateway.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_gateway.cpp @@ -316,7 +316,7 @@ void ConvertTtlSettingsToProto(const NYql::TTtlSettings& settings, Ydb::Table::T auto* tierProto = proto.add_tiers(); tierProto->set_apply_after_seconds(tier.ApplyAfter.Seconds()); if (tier.StorageName) { - tierProto->mutable_evict_to_external_storage()->set_storage_name(tier.StorageName); + tierProto->mutable_evict_to_external_storage()->set_storage_name(*tier.StorageName); } else { tierProto->mutable_delete_(); } diff --git a/ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp b/ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp index ac27997fe55f..6ca31686c344 100644 --- a/ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp @@ -57,7 +57,7 @@ bool ValidateTtlSettings(const NKikimrSchemeOp::TTTLSettings& ttl, return false; } - if (!NValidation::TTTLValidator::ValidateTiers(enabled, errStr)) { + if (!NValidation::TTTLValidator::ValidateTiers(enabled.GetTiers(), errStr)) { return false; } From 3de03258742e5e4a276f4309d005fea5195dceec Mon Sep 17 00:00:00 2001 From: Semyon Yentsov Date: Thu, 28 Nov 2024 15:04:50 +0000 Subject: [PATCH 3/3] fix build --- ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 37 +++++++++++-------- ydb/public/sdk/cpp/client/ydb_table/table.cpp | 12 +++--- ydb/public/sdk/cpp/client/ydb_table/table.h | 4 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index 6ea265d820a5..72d0cb9d77b0 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -5444,10 +5444,10 @@ Y_UNIT_TEST_SUITE(KqpScheme) { UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); - auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); + auto ttl = desc.GetTableDescription().GetTtlSettings(); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(std::get(ttl->GetTiers()[0].GetAction()).StorageName, "tier1"); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers()[0].GetApplyAfter(), TDuration::Seconds(10)); } auto query2 = TStringBuilder() << R"( --!syntax_v1 @@ -5460,10 +5460,10 @@ Y_UNIT_TEST_SUITE(KqpScheme) { UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); - auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier2"); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); + auto ttl = desc.GetTableDescription().GetTtlSettings(); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(std::get(ttl->GetTiers()[0].GetAction()).StorageName, "tier2"); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers()[0].GetApplyAfter(), TDuration::Seconds(10)); } auto query3 = TStringBuilder() << R"( @@ -5491,10 +5491,10 @@ Y_UNIT_TEST_SUITE(KqpScheme) { UNIT_ASSERT_C(desc.IsSuccess(), desc.GetIssues().ToString()); UNIT_ASSERT(desc.GetTableDescription().GetTtlSettings()); - auto ttl = desc.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetEvictionDelay(), TDuration::Seconds(10)); + auto ttl = desc.GetTableDescription().GetTtlSettings(); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers().size(), 1); + UNIT_ASSERT_VALUES_EQUAL(std::get(ttl->GetTiers()[0].GetAction()).StorageName, "tier1"); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers()[0].GetApplyAfter(), TDuration::Seconds(10)); } auto query5 = TStringBuilder() << R"( @@ -8191,10 +8191,15 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { const auto& description = describeResult.GetTableDescription(); UNIT_ASSERT(describeResult.GetTableDescription().GetTtlSettings()); - auto ttl = describeResult.GetTableDescription().GetTtlSettings()->GetDateTypeColumn(); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetExpireAfter(), TDuration::Hours(1)); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers().size(), 1); - UNIT_ASSERT_VALUES_EQUAL(ttl.GetTiers()[0].GetStorageName(), "tier1"); + auto ttl = describeResult.GetTableDescription().GetTtlSettings(); + UNIT_ASSERT_VALUES_EQUAL(ttl->GetTiers().size(), 2); + auto evictTier = ttl->GetTiers()[0]; + UNIT_ASSERT(std::holds_alternative(evictTier.GetAction())); + UNIT_ASSERT_VALUES_EQUAL(std::get(evictTier.GetAction()).StorageName, "tier1"); + UNIT_ASSERT_VALUES_EQUAL(evictTier.GetApplyAfter(), TDuration::Seconds(10)); + auto deleteTier = ttl->GetTiers()[1]; + UNIT_ASSERT(std::holds_alternative(deleteTier.GetAction())); + UNIT_ASSERT_VALUES_EQUAL(deleteTier.GetApplyAfter(), TDuration::Hours(1)); } { auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << R"(` RESET (TTL);)"; diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.cpp b/ydb/public/sdk/cpp/client/ydb_table/table.cpp index ec1596a49334..f738d00c0681 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.cpp +++ b/ydb/public/sdk/cpp/client/ydb_table/table.cpp @@ -2912,12 +2912,12 @@ bool operator!=(const TChangefeedDescription& lhs, const TChangefeedDescription& //////////////////////////////////////////////////////////////////////////////// TTtlTierSettings::TTtlTierSettings(TDuration evictionDelay, const TAction& action) - : EvictAfter_(evictionDelay) + : ApplyAfter_(evictionDelay) , Action_(action) { } TTtlTierSettings::TTtlTierSettings(const Ydb::Table::TtlTier& tier) - : EvictAfter_(TDuration::Seconds(tier.apply_after_seconds())) { + : ApplyAfter_(TDuration::Seconds(tier.apply_after_seconds())) { switch (tier.action_case()) { case Ydb::Table::TtlTier::kDelete: Action_ = TTtlDeleteAction(); @@ -2931,7 +2931,7 @@ TTtlTierSettings::TTtlTierSettings(const Ydb::Table::TtlTier& tier) } void TTtlTierSettings::SerializeTo(Ydb::Table::TtlTier& proto) const { - proto.set_apply_after_seconds(EvictAfter_.Seconds()); + proto.set_apply_after_seconds(ApplyAfter_.Seconds()); std::visit(TOverloaded{ [&proto](const TTtlDeleteAction&) { proto.mutable_delete_(); }, @@ -2943,8 +2943,8 @@ void TTtlTierSettings::SerializeTo(Ydb::Table::TtlTier& proto) const { Action_); } -TDuration TTtlTierSettings::GetEvictAfter() const { - return EvictAfter_; +TDuration TTtlTierSettings::GetApplyAfter() const { + return ApplyAfter_; } const TTtlTierSettings::TAction& TTtlTierSettings::GetAction() const { @@ -3145,7 +3145,7 @@ std::optional TTtlSettings::GetExpireAfter() const { std::optional TTtlSettings::GetExpireAfterFrom(const TVector& tiers) { for (const auto& tier : tiers) { if (std::holds_alternative(tier.GetAction())) { - return tier.GetEvictAfter(); + return tier.GetApplyAfter(); } } return std::nullopt; diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.h b/ydb/public/sdk/cpp/client/ydb_table/table.h index 56bad7682c5f..e727656fdee9 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.h +++ b/ydb/public/sdk/cpp/client/ydb_table/table.h @@ -443,11 +443,11 @@ class TTtlTierSettings { explicit TTtlTierSettings(const Ydb::Table::TtlTier& tier); void SerializeTo(Ydb::Table::TtlTier& proto) const; - TDuration GetEvictAfter() const; + TDuration GetApplyAfter() const; const TAction& GetAction() const; private: - TDuration EvictAfter_; + TDuration ApplyAfter_; TAction Action_; };