Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tiering info to TTL in public api #11390

Merged
merged 33 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1e34ba2
wip
swalrus1 Nov 4, 2024
c2000ce
fix serializer
swalrus1 Nov 7, 2024
1fe6117
more changes
swalrus1 Nov 11, 2024
260435e
remove compression
swalrus1 Nov 11, 2024
f76ddc2
fix table description
swalrus1 Nov 11, 2024
d512add
fix backwards-compatibility
swalrus1 Nov 12, 2024
5ba569c
add evict to family action
swalrus1 Nov 13, 2024
84a4c9a
remove family action
swalrus1 Nov 14, 2024
0f11471
fix typo
swalrus1 Nov 15, 2024
5b55648
change api proto
swalrus1 Nov 15, 2024
e80a72e
fix risk: client with new proto, server with old proto -> server inte…
swalrus1 Nov 19, 2024
1d228d0
fix usage of api
swalrus1 Nov 19, 2024
d3ddb6a
handle new ttl proto on DS and SS
swalrus1 Nov 19, 2024
582f5d8
fix ut_restore
swalrus1 Nov 19, 2024
c38a382
return tiering
swalrus1 Nov 19, 2024
ea55797
rename modes
swalrus1 Nov 20, 2024
4324236
fix build
swalrus1 Nov 20, 2024
ae53876
clean up
swalrus1 Nov 20, 2024
4021220
clean up
swalrus1 Nov 20, 2024
056ae4b
nit
swalrus1 Nov 20, 2024
45c41d6
post-review fixes
swalrus1 Nov 21, 2024
3cf2fc8
fix sdk: serialization
swalrus1 Nov 21, 2024
f579fbe
evict_after_seconds -> apply_after_seconds
swalrus1 Nov 21, 2024
91b067d
add backwards-compatibility on output
swalrus1 Nov 22, 2024
6524215
fix conversion
swalrus1 Nov 22, 2024
ddff785
move GetExpireAfter
swalrus1 Nov 26, 2024
dfce877
revert changing a test
swalrus1 Nov 26, 2024
96b2914
fix
swalrus1 Nov 26, 2024
ab917e9
move GetExpireAfter
swalrus1 Nov 27, 2024
4f9ce7a
add delete tier validation
swalrus1 Nov 27, 2024
93d6e8c
nit
swalrus1 Nov 27, 2024
035c779
add negative tests
swalrus1 Nov 27, 2024
651d8f8
extend more negative tests
swalrus1 Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions ydb/core/grpc_services/rpc_log_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,29 +508,8 @@ class TDescribeLogTableRPC : public TRpcSchemeRequestActor<TDescribeLogTableRPC,
}

if (tableDescription.HasTtlSettings() && tableDescription.GetTtlSettings().HasEnabled()) {
const auto& inTTL = tableDescription.GetTtlSettings().GetEnabled();

switch (inTTL.GetColumnUnit()) {
case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: {
auto& outTTL = *describeLogTableResult.mutable_ttl_settings()->mutable_date_type_column();
outTTL.set_column_name(inTTL.GetColumnName());
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
break;
}

case NKikimrSchemeOp::TTTLSettings::UNIT_SECONDS:
case NKikimrSchemeOp::TTTLSettings::UNIT_MILLISECONDS:
case NKikimrSchemeOp::TTTLSettings::UNIT_MICROSECONDS:
case NKikimrSchemeOp::TTTLSettings::UNIT_NANOSECONDS: {
auto& outTTL = *describeLogTableResult.mutable_ttl_settings()->mutable_value_since_unix_epoch();
outTTL.set_column_name(inTTL.GetColumnName());
outTTL.set_column_unit(static_cast<Ydb::Table::ValueSinceUnixEpochModeSettings::Unit>(inTTL.GetColumnUnit()));
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
break;
}

default:
break;
if (!FillTtlSettings(*describeLogTableResult.mutable_ttl_settings(), tableDescription.GetTtlSettings().GetEnabled(), status, error)) {
return Reply(status, error, NKikimrIssues::TIssuesIds::DEFAULT_ERROR, ctx);
}
}

Expand Down
9 changes: 5 additions & 4 deletions ydb/core/kqp/provider/yql_kikimr_gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,16 @@ bool ConvertReadReplicasSettingsToProto(const TString settings, Ydb::Table::Read

void ConvertTtlSettingsToProto(const NYql::TTtlSettings& settings, Ydb::Table::TtlSettings& proto) {
if (!settings.ColumnUnit) {
auto& opts = *proto.mutable_date_type_column();
auto& opts = *proto.mutable_date_type_column_v1();
opts.set_column_name(settings.ColumnName);
opts.set_expire_after_seconds(settings.ExpireAfter.Seconds());
} else {
auto& opts = *proto.mutable_value_since_unix_epoch();
auto& opts = *proto.mutable_value_since_unix_epoch_v1();
opts.set_column_name(settings.ColumnName);
opts.set_column_unit(static_cast<Ydb::Table::ValueSinceUnixEpochModeSettings::Unit>(*settings.ColumnUnit));
opts.set_expire_after_seconds(settings.ExpireAfter.Seconds());
}
auto* deleteTier = proto.add_tiers();
deleteTier->set_evict_after_seconds(settings.ExpireAfter.Seconds());
deleteTier->mutable_delete_();
}

Ydb::FeatureFlag::Status GetFlagValue(const TMaybe<bool>& value) {
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/kqp/proxy_service/kqp_script_executions_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ NKikimrSchemeOp::TColumnDescription Col(const TString& columnName, NScheme::TTyp

[[maybe_unused]] NKikimrSchemeOp::TTTLSettings TtlCol(const TString& columnName) {
NKikimrSchemeOp::TTTLSettings settings;
auto* deleteTier = settings.MutableEnabled()->AddTiers();
deleteTier->MutableDelete();
deleteTier->SetEvictAfterSeconds(TDuration::Minutes(20).Seconds());
settings.MutableEnabled()->SetExpireAfterSeconds(TDuration::Minutes(20).Seconds());
settings.MutableEnabled()->SetColumnName(columnName);
settings.MutableEnabled()->MutableSysSettings()->SetRunInterval(TDuration::Minutes(60).MicroSeconds());
Expand Down
6 changes: 4 additions & 2 deletions ydb/core/persqueue/writer/metadata_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ void TSrcIdMetaInitializer::DoPrepare(NInitializer::IInitializerInput::TPtr cont
}
{
auto* ttlSettings = request.mutable_ttl_settings();
auto* columnTtl = ttlSettings->mutable_value_since_unix_epoch();
auto* columnTtl = ttlSettings->mutable_value_since_unix_epoch_v1();
columnTtl->set_column_name("AccessTime");
columnTtl->set_expire_after_seconds(1382400);
columnTtl->set_column_unit(Ydb::Table::ValueSinceUnixEpochModeSettings::UNIT_MILLISECONDS);
auto* deleteTier = ttlSettings->add_tiers();
deleteTier->mutable_delete_();
deleteTier->set_evict_after_seconds(1382400);
}

result.emplace_back(new NInitializer::TGenericTableModifier<NRequest::TDialogCreateTable>(request, "create"));
Expand Down
18 changes: 16 additions & 2 deletions ydb/core/protos/flat_scheme_op.proto
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,24 @@ message TTTLSettings {
optional uint32 MaxShardsInFlight = 6 [default = 0]; // zero means no limit
}

message TEvictionToExternalStorageSettings {
optional string StorageName = 1;
}

message TTier {
optional uint32 EvictAfterSeconds = 1;
oneof Action {
google.protobuf.Empty Delete = 2;
TEvictionToExternalStorageSettings EvictToExternalStorage = 3;
}
}

message TEnabled {
optional string ColumnName = 1;
optional uint32 ExpireAfterSeconds = 2;
optional uint32 ExpireAfterSeconds = 2 [deprecated = true];
optional EUnit ColumnUnit = 3;
optional TSysSettings SysSettings = 4;
repeated TTier Tiers = 5;
}

message TDisabled {
Expand Down Expand Up @@ -571,10 +584,11 @@ message TColumnDataLifeCycle {
message TTtl {
optional string ColumnName = 1;
oneof Expire {
uint32 ExpireAfterSeconds = 2;
uint32 ExpireAfterSeconds = 2 [deprecated = true]; // ignored if Tiers are not empty
uint64 ExpireAfterBytes = 4;
}
optional TTTLSettings.EUnit ColumnUnit = 3;
repeated TTTLSettings.TTier Tiers = 5;
}

message TDisabled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class TConverterModifyToAlter {
if (enabled.HasColumnUnit()) {
alterEnabled->SetColumnUnit(enabled.GetColumnUnit());
}
for (const auto& tier : enabled.GetTiers()) {
alterEnabled->AddTiers()->CopyFrom(tier);
}
} else if (tableTtl.HasDisabled()) {
alterTtl->MutableDisabled();
}
Expand Down
16 changes: 15 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard__conditional_erase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,21 @@ struct TSchemeShard::TTxRunConditionalErase: public TSchemeShard::TRwTxBase {
}

const auto& settings = tableInfo->TTLSettings().GetEnabled();
const TDuration expireAfter = TDuration::Seconds(settings.GetExpireAfterSeconds());

TDuration expireAfter;
if (settings.TiersSize()) {
if (settings.TiersSize() > 1 || !settings.GetTiers(0).HasDelete()) {
LOG_WARN_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "Invalid ttl setting: external storage tiers"
<< ": shardIdx: " << tableShardInfo.ShardIdx
<< ": pathId: " << shardInfo.PathId
<< ", at schemeshard: " << Self->TabletID());
return false;
}
expireAfter = TDuration::Seconds(settings.GetTiers(0).GetEvictAfterSeconds());
} else {
// legacy format
expireAfter = TDuration::Seconds(settings.GetExpireAfterSeconds());
}
const TInstant wallClock = ctx.Now() - expireAfter;

NKikimrTxDataShard::TEvConditionalEraseRowsRequest request;
Expand Down
14 changes: 13 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard_validate_ttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ bool ValidateTtlSettings(const NKikimrSchemeOp::TTTLSettings& ttl,
return false;
}

ui32 expireInSeconds;
if (enabled.TiersSize()) {
if (enabled.TiersSize() > 1 || !enabled.GetTiers(0).HasDelete()) {
errStr = Sprintf("Only DELETE via TTL is allowed for row-oriented tables");
return false;
}
expireInSeconds = enabled.GetTiers(0).GetEvictAfterSeconds();
} else {
// legacy format
expireInSeconds = enabled.GetExpireAfterSeconds();
}

const TInstant now = TInstant::Now();
if (enabled.GetExpireAfterSeconds() > now.Seconds()) {
if (expireInSeconds > now.Seconds()) {
errStr = Sprintf("TTL should be less than %" PRIu64 " seconds (%" PRIu64 " days, %" PRIu64 " years). The ttl behaviour is undefined before 1970.", now.Seconds(), now.Days(), now.Days() / 365);
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,9 @@ TCheckFunc HasTtlEnabled(const TString& columnName, const TDuration& expireAfter
UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().GetColumnName(), columnName);
UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().GetColumnUnit(), columnUnit);
UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().GetExpireAfterSeconds(), expireAfter.Seconds());
UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().TiersSize(), 1);
UNIT_ASSERT(ttl.GetEnabled().GetTiers(0).HasDelete());
UNIT_ASSERT_VALUES_EQUAL(ttl.GetEnabled().GetTiers(0).GetEvictAfterSeconds(), expireAfter.Seconds());
};
}

Expand Down
14 changes: 10 additions & 4 deletions ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,9 +2661,12 @@ Y_UNIT_TEST_SUITE(TImportTests) {
Y_UNIT_TEST(ShouldRestoreTtlSettingsInDateTypeColumnMode) {
ShouldRestoreSettings(R"(
ttl_settings {
date_type_column {
date_type_column_v1 {
column_name: "created_at"
expire_after_seconds: 3600
}
tiers {
evict_after_seconds: 3600
delete {}
}
}
)", {
Expand All @@ -2674,10 +2677,13 @@ Y_UNIT_TEST_SUITE(TImportTests) {
Y_UNIT_TEST(ShouldRestoreTtlSettingsInValueSinceUnixEpochMode) {
ShouldRestoreSettings(R"(
ttl_settings {
value_since_unix_epoch {
value_since_unix_epoch_v1 {
column_name: "modified_at"
column_unit: UNIT_SECONDS
expire_after_seconds: 7200
}
tiers {
evict_after_seconds: 7200
delete {}
}
}
)", {
Expand Down
Loading
Loading