Skip to content

Commit dcbea0f

Browse files
authored
Merge 3536ce2 into 481ccad
2 parents 481ccad + 3536ce2 commit dcbea0f

File tree

8 files changed

+309
-145
lines changed

8 files changed

+309
-145
lines changed

ydb/core/protos/flat_scheme_op.proto

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,24 @@ message TTTLSettings {
221221
optional uint32 MaxShardsInFlight = 6 [default = 0]; // zero means no limit
222222
}
223223

224+
message TEvictionToExternalStorageSettings {
225+
optional string StorageName = 1;
226+
}
227+
228+
message TTier {
229+
optional uint32 EvictAfterSeconds = 1;
230+
oneof Action {
231+
google.protobuf.Empty Delete = 2;
232+
TEvictionToExternalStorageSettings EvictToExternalStorage = 3;
233+
}
234+
}
235+
224236
message TEnabled {
225237
optional string ColumnName = 1;
226-
optional uint32 ExpireAfterSeconds = 2;
238+
optional uint32 ExpireAfterSeconds = 2 [deprecated = true];
227239
optional EUnit ColumnUnit = 3;
228240
optional TSysSettings SysSettings = 4;
241+
repeated TTier Tiers = 5;
229242
}
230243

231244
message TDisabled {
@@ -570,10 +583,11 @@ message TColumnDataLifeCycle {
570583
message TTtl {
571584
optional string ColumnName = 1;
572585
oneof Expire {
573-
uint32 ExpireAfterSeconds = 2;
586+
uint32 ExpireAfterSeconds = 2 [deprecated = true];
574587
uint64 ExpireAfterBytes = 4;
575588
}
576589
optional TTTLSettings.EUnit ColumnUnit = 3;
590+
repeated TTTLSettings.TTier Tiers = 5;
577591
}
578592

579593
message TDisabled {

ydb/core/ydb_convert/table_description.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ THashSet<EAlterOperationKind> GetAlterOperationKinds(const Ydb::Table::AlterTabl
4848
req->alter_columns_size() ||
4949
req->ttl_action_case() !=
5050
Ydb::Table::AlterTableRequest::TTL_ACTION_NOT_SET ||
51-
req->tiering_action_case() !=
52-
Ydb::Table::AlterTableRequest::TIERING_ACTION_NOT_SET ||
5351
req->has_alter_storage_settings() || req->add_column_families_size() ||
5452
req->alter_column_families_size() || req->set_compaction_policy() ||
5553
req->has_alter_partitioning_settings() ||
@@ -509,11 +507,25 @@ Ydb::Type* AddColumn<NKikimrSchemeOp::TColumnDescription>(Ydb::Table::ColumnMeta
509507

510508
template <typename TYdbProto, typename TTtl>
511509
static void AddTtl(TYdbProto& out, const TTtl& inTTL) {
510+
for (const auto& inTier : inTTL.GetTiers()) {
511+
auto* outTier = out.mutable_ttl_settings()->add_tiers();
512+
outTier->set_evict_after_seconds(inTier.GetEvictAfterSeconds());
513+
switch (inTier.GetActionCase()) {
514+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::kDelete:
515+
outTier->mutable_delete_();
516+
break;
517+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::kEvictToExternalStorage:
518+
outTier->mutable_evict_to_external_storage()->set_storage_name(inTier.GetEvictToExternalStorage().GetStorageName());
519+
break;
520+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::ACTION_NOT_SET:
521+
break;
522+
}
523+
}
524+
512525
switch (inTTL.GetColumnUnit()) {
513526
case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: {
514527
auto& outTTL = *out.mutable_ttl_settings()->mutable_date_type_column();
515528
outTTL.set_column_name(inTTL.GetColumnName());
516-
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
517529
break;
518530
}
519531

@@ -524,7 +536,6 @@ static void AddTtl(TYdbProto& out, const TTtl& inTTL) {
524536
auto& outTTL = *out.mutable_ttl_settings()->mutable_value_since_unix_epoch();
525537
outTTL.set_column_name(inTTL.GetColumnName());
526538
outTTL.set_column_unit(static_cast<Ydb::Table::ValueSinceUnixEpochModeSettings::Unit>(inTTL.GetColumnUnit()));
527-
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
528539
break;
529540
}
530541

@@ -572,10 +583,6 @@ void FillColumnDescriptionImpl(TYdbProto& out,
572583
if (in.GetTTLSettings().HasEnabled()) {
573584
AddTtl(out, in.GetTTLSettings().GetEnabled());
574585
}
575-
576-
if (in.GetTTLSettings().HasUseTiering()) {
577-
out.set_tiering(in.GetTTLSettings().GetUseTiering());
578-
}
579586
}
580587
}
581588

@@ -612,10 +619,6 @@ void FillColumnDescription(Ydb::Table::DescribeTableResult& out, const NKikimrSc
612619
if (in.GetTtlSettings().HasEnabled()) {
613620
AddTtl(out, in.GetTtlSettings().GetEnabled());
614621
}
615-
616-
if (in.GetTtlSettings().HasUseTiering()) {
617-
out.set_tiering(in.GetTtlSettings().GetUseTiering());
618-
}
619622
}
620623

621624
out.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN);
@@ -829,12 +832,6 @@ bool BuildAlterColumnTableModifyScheme(const TString& path, const Ydb::Table::Al
829832
} else if (req->has_drop_ttl_settings()) {
830833
alterColumnTable->MutableAlterTtlSettings()->MutableDisabled();
831834
}
832-
833-
if (req->has_set_tiering()) {
834-
alterColumnTable->MutableAlterTtlSettings()->SetUseTiering(req->set_tiering());
835-
} else if (req->has_drop_tiering()) {
836-
alterColumnTable->MutableAlterTtlSettings()->SetUseTiering("");
837-
}
838835
}
839836

840837
return true;

ydb/core/ydb_convert/table_settings.h

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ bool FillTtlSettings(TTtlSettingsEnabled& out, const Ydb::Table::TtlSettings& in
2828
return false;
2929
};
3030

31-
switch (in.mode_case()) {
32-
case Ydb::Table::TtlSettings::kDateTypeColumn:
33-
out.SetColumnName(in.date_type_column().column_name());
34-
out.SetExpireAfterSeconds(in.date_type_column().expire_after_seconds());
35-
break;
31+
static const auto& fillModeSettings = []<class TModeSettings>(TTtlSettingsEnabled& out, const TModeSettings& in) {
32+
out.SetColumnName(in.column_name());
33+
};
3634

37-
case Ydb::Table::TtlSettings::kValueSinceUnixEpoch:
38-
out.SetColumnName(in.value_since_unix_epoch().column_name());
39-
out.SetExpireAfterSeconds(in.value_since_unix_epoch().expire_after_seconds());
35+
static const auto& fillDeleteTier = []<class TModeSettings>(TTtlSettingsEnabled& out, const TModeSettings& in) {
36+
auto* deleteTier = out.AddTiers();
37+
deleteTier->SetEvictAfterSeconds(in.expire_after_seconds());
38+
deleteTier->MutableDelete();
39+
};
4040

41+
static const auto& fillColumnUnit = []<class TModeSettings> (TTtlSettingsEnabled& out, const TModeSettings& in) -> bool {
4142
#define CASE_UNIT(type) \
4243
case Ydb::Table::ValueSinceUnixEpochModeSettings::type: \
4344
out.SetColumnUnit(NKikimrSchemeOp::TTTLSettings::type); \
4445
break
4546

46-
switch (in.value_since_unix_epoch().column_unit()) {
47+
switch (in.column_unit()) {
4748
CASE_UNIT(UNIT_SECONDS);
4849
CASE_UNIT(UNIT_MILLISECONDS);
4950
CASE_UNIT(UNIT_MICROSECONDS);
@@ -54,12 +55,62 @@ bool FillTtlSettings(TTtlSettingsEnabled& out, const Ydb::Table::TtlSettings& in
5455
}
5556

5657
#undef CASE_UNIT
58+
};
59+
60+
if (in.tiers_size()) {
61+
for (const auto& inTier : in.tiers()) {
62+
auto* outTier = out.AddTiers();
63+
outTier->SetEvictAfterSeconds(inTier.evict_after_seconds());
64+
switch (inTier.action_case()) {
65+
case Ydb::Table::TtlTier::kDelete:
66+
outTier->MutableDelete();
67+
break;
68+
case Ydb::Table::TtlTier::kEvictToExternalStorage:
69+
outTier->MutableEvictToExternalStorage()->SetStorageName(inTier.evict_to_external_storage().storage_name());
70+
break;
71+
case Ydb::Table::TtlTier::ACTION_NOT_SET:
72+
break;
73+
}
74+
}
75+
}
76+
77+
switch (in.mode_case()) {
78+
case Ydb::Table::TtlSettings::kDeprecatedDateTypeColumn:
79+
fillModeSettings(out, in.deprecated_date_type_column());
80+
fillDeleteTier(out, in.deprecated_date_type_column());
5781
break;
5882

59-
default:
83+
case Ydb::Table::TtlSettings::kDeprecatedValueSinceUnixEpoch:
84+
fillModeSettings(out, in.deprecated_value_since_unix_epoch());
85+
fillDeleteTier(out, in.deprecated_date_type_column());
86+
if (!fillColumnUnit(out, in.value_since_unix_epoch())) {
87+
return false;
88+
}
89+
break;
90+
91+
case Ydb::Table::TtlSettings::kDateTypeColumn:
92+
fillModeSettings(out, in.date_type_column());
93+
break;
94+
95+
case Ydb::Table::TtlSettings::kValueSinceUnixEpoch:
96+
fillModeSettings(out, in.value_since_unix_epoch());
97+
if (!fillColumnUnit(out, in.value_since_unix_epoch())) {
98+
return false;
99+
}
100+
break;
101+
102+
case Ydb::Table::TtlSettings::MODE_NOT_SET:
60103
return unsupported("Unsupported ttl settings");
61104
}
62105

106+
std::optional<ui32> expireInSeconds = 0;
107+
for (const auto& tier : out.GetTiers()) {
108+
if (tier.HasDelete()) {
109+
expireInSeconds = tier.GetEvictInSeconds();
110+
}
111+
}
112+
out.SetExpireInSeconds(expireInSeconds.value_or(std::numeric_limits<uint32_t>::max()));
113+
63114
if constexpr (std::is_same_v<TTtlSettingsEnabled, NKikimrSchemeOp::TTTLSettings::TEnabled>) {
64115
if (in.run_interval_seconds()) {
65116
out.MutableSysSettings()->SetRunInterval(TDuration::Seconds(in.run_interval_seconds()).GetValue());

ydb/public/api/protos/ydb_table.proto

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,33 @@ message ColumnMeta {
433433
}
434434
}
435435

436+
message EvictionToExternalStorageSettings {
437+
// Path to external data source
438+
string storage_name = 1;
439+
}
440+
441+
message EvictionToFamilySettings {
442+
// Name of column family
443+
string family_name = 1;
444+
}
445+
446+
message TtlTier {
447+
uint32 evict_after_seconds = 1;
448+
449+
oneof action {
450+
google.protobuf.Empty delete = 2;
451+
EvictionToExternalStorageSettings evict_to_external_storage = 3;
452+
}
453+
}
454+
436455
message DateTypeColumnModeSettings {
437-
// The row will be considered as expired at the moment of time, when the value
456+
// The row will be assigned a tier at the moment of time, when the value
438457
// stored in <column_name> is less than or equal to the current time (in epoch
439-
// time format), and <expire_after_seconds> has passed since that moment;
440-
// i.e. the expiration threshold is the value of <column_name> plus <expire_after_seconds>.
458+
// time format), and <tier.evict_after_seconds> has passed since that moment;
459+
// i.e. the eviction threshold is the value of <column_name> plus <tier.evict_after_seconds>.
441460

442461
// The column type must be a date type
443462
string column_name = 1;
444-
445-
uint32 expire_after_seconds = 2;
446463
}
447464

448465
message ValueSinceUnixEpochModeSettings {
@@ -465,16 +482,27 @@ message ValueSinceUnixEpochModeSettings {
465482

466483
// Interpretation of the value stored in <column_name>
467484
Unit column_unit = 2;
485+
}
468486

469-
// This option is always interpreted as seconds regardless of the
470-
// <column_unit> value.
487+
message DeprecatedDateTypeColumnModeSettings {
488+
// Deprecated TTL mode for internal use only
489+
string column_name = 1;
490+
uint32 expire_after_seconds = 2;
491+
}
492+
493+
message DeprecatedValueSinceUnixEpochModeSettings {
494+
// Deprecated TTL mode for internal use only
495+
string column_name = 1;
496+
ValueSinceUnixEpochModeSettings.Unit column_unit = 2;
471497
uint32 expire_after_seconds = 3;
472498
}
473499

474500
message TtlSettings {
475501
oneof mode {
476-
DateTypeColumnModeSettings date_type_column = 1;
477-
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 2;
502+
DeprecatedDateTypeColumnModeSettings deprecated_date_type_column = 1 [deprecated = true];
503+
DeprecatedValueSinceUnixEpochModeSettings deprecated_value_since_unix_epoch = 2 [deprecated = true];
504+
DateTypeColumnModeSettings date_type_column = 4;
505+
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 5;
478506
}
479507

480508
// There is no guarantee that expired row will be deleted immediately upon
@@ -490,6 +518,8 @@ message TtlSettings {
490518
// How often to run BRO on the same partition.
491519
// BRO will not be started more often, but may be started less often.
492520
uint32 run_interval_seconds = 3;
521+
522+
repeated TtlTier tiers = 6;
493523
}
494524

495525
message StorageSettings {
@@ -624,8 +654,7 @@ message CreateTableRequest {
624654
Ydb.FeatureFlag.Status key_bloom_filter = 16;
625655
// Read replicas settings for table
626656
ReadReplicasSettings read_replicas_settings = 17;
627-
// Tiering rules name. It specifies how data migrates from one tier (logical storage) to another.
628-
string tiering = 18;
657+
reserved 18; // tiering
629658
// Is temporary table
630659
bool temporary = 19;
631660
// Is table column or row oriented
@@ -704,11 +733,7 @@ message AlterTableRequest {
704733
repeated string drop_changefeeds = 20;
705734
// Rename existed index
706735
repeated RenameIndexItem rename_indexes = 21;
707-
// Setup or remove tiering
708-
oneof tiering_action {
709-
string set_tiering = 22;
710-
google.protobuf.Empty drop_tiering = 23;
711-
}
736+
reserved 22, 23; // tiering_action
712737
}
713738

714739
message AlterTableResponse {

ydb/public/lib/experimental/ydb_logstore.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,10 @@ namespace NYdb {
1616
namespace NLogStore {
1717

1818
TMaybe<TTtlSettings> TtlSettingsFromProto(const Ydb::Table::TtlSettings& proto) {
19-
switch (proto.mode_case()) {
20-
case Ydb::Table::TtlSettings::kDateTypeColumn:
21-
return TTtlSettings(
22-
proto.date_type_column(),
23-
proto.run_interval_seconds()
24-
);
25-
26-
case Ydb::Table::TtlSettings::kValueSinceUnixEpoch:
27-
return TTtlSettings(
28-
proto.value_since_unix_epoch(),
29-
proto.run_interval_seconds()
30-
);
31-
32-
default:
33-
break;
19+
if (auto settings = TTtlSettings::DeserializeFromProto(proto)) {
20+
return *settings;
3421
}
35-
return {};
22+
return Nothing();
3623
}
3724

3825
static TCompression CompressionFromProto(const Ydb::LogStore::Compression& compression) {
@@ -199,8 +186,6 @@ void TLogTableDescription::SerializeTo(Ydb::LogStore::CreateLogTableRequest& req
199186

200187
if (TtlSettings) {
201188
TtlSettings->SerializeTo(*request.mutable_ttl_settings());
202-
} else if (TieringSettings) {
203-
TieringSettings->SerializeTo(*request.mutable_tiering_settings());
204189
}
205190
}
206191

ydb/public/lib/experimental/ydb_logstore.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,6 @@ struct TLogTableSharding {
152152
TLogTableSharding(const Ydb::LogStore::DescribeLogTableResult& desc);
153153
};
154154

155-
class TTieringSettings {
156-
private:
157-
TString TieringId;
158-
public:
159-
TTieringSettings(const TString& tieringId)
160-
: TieringId(tieringId) {
161-
162-
}
163-
164-
void SerializeTo(Ydb::LogStore::TieringSettings& proto) const {
165-
proto.set_tiering_id(TieringId);
166-
}
167-
168-
};
169-
170155
class TLogTableDescription {
171156
public:
172157
TLogTableDescription(const TString& schemaPresetName, const TLogTableSharding& sharding);
@@ -200,16 +185,11 @@ class TLogTableDescription {
200185
TtlSettings = settings;
201186
return *this;
202187
}
203-
TLogTableDescription& SetTieringSettings(const TTieringSettings& settings) {
204-
TieringSettings = settings;
205-
return *this;
206-
}
207188
private:
208189
const TString SchemaPresetName;
209190
const TSchema Schema;
210191
const TLogTableSharding Sharding;
211192
TMaybe<TTtlSettings> TtlSettings;
212-
TMaybe<TTieringSettings> TieringSettings;
213193
TString Owner;
214194
TVector<NScheme::TPermissions> Permissions;
215195
TVector<NScheme::TPermissions> EffectivePermissions;

0 commit comments

Comments
 (0)