Skip to content

Commit be9240e

Browse files
authored
Merge 3bf480f into 7b9c7e3
2 parents 7b9c7e3 + 3bf480f commit be9240e

File tree

7 files changed

+168
-57
lines changed

7 files changed

+168
-57
lines changed

ydb/core/protos/flat_scheme_op.proto

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

224+
message TTier {
225+
optional uint32 EvictAfterSeconds = 1;
226+
optional string StorageName = 2;
227+
optional TCompressionOptions Compression = 3;
228+
}
229+
224230
message TEnabled {
225231
optional string ColumnName = 1;
226232
optional uint32 ExpireAfterSeconds = 2;
227233
optional EUnit ColumnUnit = 3;
228234
optional TSysSettings SysSettings = 4;
235+
repeated TTier Tiers = 5;
229236
}
230237

231238
message TDisabled {
@@ -555,6 +562,7 @@ message TColumnDataLifeCycle {
555562
uint64 ExpireAfterBytes = 4;
556563
}
557564
optional TTTLSettings.EUnit ColumnUnit = 3;
565+
repeated TTTLSettings.TTier Tiers = 5;
558566
}
559567

560568
message TDisabled {

ydb/core/ydb_convert/table_settings.h

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

31+
static const auto& fillCommonFields = []<class TModeSettings>(TTtlSettingsEnabled& out, const TModeSettings& in) {
32+
out.SetColumnName(in.column_name());
33+
if (in.has_expire_after_seconds()) {
34+
out.SetExpireAfterSeconds(in.expire_after_seconds());
35+
}
36+
for (const auto& in_tier : in.storage_tiers()) {
37+
auto* out_tier = out.AddTiers();
38+
out_tier->SetEvictAfterSeconds(in_tier.evict_after_seconds());
39+
out_tier->SetStorageName(in_tier.storage_name());
40+
}
41+
};
42+
3143
switch (in.mode_case()) {
3244
case Ydb::Table::TtlSettings::kDateTypeColumn:
33-
out.SetColumnName(in.date_type_column().column_name());
34-
out.SetExpireAfterSeconds(in.date_type_column().expire_after_seconds());
45+
fillCommonFields(out, in.date_type_column());
3546
break;
3647

3748
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());
49+
fillCommonFields(out, in.value_since_unix_epoch());
4050

4151
#define CASE_UNIT(type) \
4252
case Ydb::Table::ValueSinceUnixEpochModeSettings::type: \

ydb/public/api/protos/ydb_table.proto

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ message ColumnMeta {
433433
}
434434
}
435435

436+
message EvictionTier {
437+
// Name of tiered storage
438+
string storage_name = 1;
439+
440+
uint32 evict_after_seconds = 2;
441+
}
442+
436443
message DateTypeColumnModeSettings {
437444
// The row will be considered as expired at the moment of time, when the value
438445
// stored in <column_name> is less than or equal to the current time (in epoch
@@ -442,7 +449,9 @@ message DateTypeColumnModeSettings {
442449
// The column type must be a date type
443450
string column_name = 1;
444451

445-
uint32 expire_after_seconds = 2;
452+
optional uint32 expire_after_seconds = 2;
453+
454+
repeated EvictionTier storage_tiers = 3;
446455
}
447456

448457
message ValueSinceUnixEpochModeSettings {
@@ -468,7 +477,9 @@ message ValueSinceUnixEpochModeSettings {
468477

469478
// This option is always interpreted as seconds regardless of the
470479
// <column_unit> value.
471-
uint32 expire_after_seconds = 3;
480+
optional uint32 expire_after_seconds = 3;
481+
482+
repeated EvictionTier storage_tiers = 4;
472483
}
473484

474485
message TtlSettings {
@@ -624,7 +635,7 @@ message CreateTableRequest {
624635
Ydb.FeatureFlag.Status key_bloom_filter = 16;
625636
// Read replicas settings for table
626637
ReadReplicasSettings read_replicas_settings = 17;
627-
// Tiering rules name. It specifies how data migrates from one tier (logical storage) to another.
638+
// Deprecated. Use TTL instead.
628639
string tiering = 18;
629640
// Is temporary table
630641
bool temporary = 19;
@@ -704,7 +715,7 @@ message AlterTableRequest {
704715
repeated string drop_changefeeds = 20;
705716
// Rename existed index
706717
repeated RenameIndexItem rename_indexes = 21;
707-
// Setup or remove tiering
718+
// Deprecated. Use ttl_action instead
708719
oneof tiering_action {
709720
string set_tiering = 22;
710721
google.protobuf.Empty drop_tiering = 23;

ydb/public/lib/experimental/ydb_logstore.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ void TLogTableDescription::SerializeTo(Ydb::LogStore::CreateLogTableRequest& req
199199

200200
if (TtlSettings) {
201201
TtlSettings->SerializeTo(*request.mutable_ttl_settings());
202-
} else if (TieringSettings) {
203-
TieringSettings->SerializeTo(*request.mutable_tiering_settings());
204202
}
205203
}
206204

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;

ydb/public/sdk/cpp/client/ydb_table/table.cpp

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,6 @@ class TTableDescription::TImpl {
345345
break;
346346
}
347347

348-
// tiering
349-
if (proto.tiering().size()) {
350-
Tiering_ = proto.tiering();
351-
}
352-
353348
if (proto.store_type()) {
354349
StoreType_ = (proto.store_type() == Ydb::Table::STORE_TYPE_COLUMN) ? EStoreType::Column : EStoreType::Row;
355350
}
@@ -580,10 +575,6 @@ class TTableDescription::TImpl {
580575
return TtlSettings_;
581576
}
582577

583-
const TMaybe<TString>& GetTiering() const {
584-
return Tiering_;
585-
}
586-
587578
EStoreType GetStoreType() const {
588579
return StoreType_;
589580
}
@@ -664,7 +655,6 @@ class TTableDescription::TImpl {
664655
TVector<TIndexDescription> Indexes_;
665656
TVector<TChangefeedDescription> Changefeeds_;
666657
TMaybe<TTtlSettings> TtlSettings_;
667-
TMaybe<TString> Tiering_;
668658
TString Owner_;
669659
TVector<NScheme::TPermissions> Permissions_;
670660
TVector<NScheme::TPermissions> EffectivePermissions_;
@@ -731,7 +721,7 @@ TMaybe<TTtlSettings> TTableDescription::GetTtlSettings() const {
731721
}
732722

733723
TMaybe<TString> TTableDescription::GetTiering() const {
734-
return Impl_->GetTiering();
724+
return Nothing();
735725
}
736726

737727
EStoreType TTableDescription::GetStoreType() const {
@@ -954,10 +944,6 @@ void TTableDescription::SerializeTo(Ydb::Table::CreateTableRequest& request) con
954944
ttl->SerializeTo(*request.mutable_ttl_settings());
955945
}
956946

957-
if (const auto& tiering = Impl_->GetTiering()) {
958-
request.set_tiering(*tiering);
959-
}
960-
961947
if (Impl_->GetStoreType() == EStoreType::Column) {
962948
request.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN);
963949
}
@@ -2941,22 +2927,80 @@ bool operator!=(const TChangefeedDescription& lhs, const TChangefeedDescription&
29412927

29422928
////////////////////////////////////////////////////////////////////////////////
29432929

2930+
namespace {
2931+
2932+
TVector<TEvictionTierSettings> DeserializeTiers(const NProtoBuf::RepeatedPtrField<Ydb::Table::EvictionTier>& serialized) {
2933+
TVector<TEvictionTierSettings> tiers;
2934+
for (const auto& tier : serialized) {
2935+
tiers.push_back(TEvictionTierSettings(tier));
2936+
}
2937+
return tiers;
2938+
}
2939+
2940+
}
2941+
2942+
TEvictionTierSettings::TEvictionTierSettings(TString storageName, TDuration evictionDelay)
2943+
: StorageName_(storageName)
2944+
, EvictionDelay_(evictionDelay)
2945+
{}
2946+
2947+
TEvictionTierSettings::TEvictionTierSettings(const Ydb::Table::EvictionTier& tier)
2948+
: StorageName_(tier.storage_name())
2949+
, EvictionDelay_(TDuration::Seconds(tier.evict_after_seconds()))
2950+
{}
2951+
2952+
void TEvictionTierSettings::SerializeTo(Ydb::Table::EvictionTier& proto) const {
2953+
proto.set_storage_name(StorageName_);
2954+
proto.set_evict_after_seconds(EvictionDelay_.Seconds());
2955+
}
2956+
2957+
const TString& TEvictionTierSettings::GetStorageName() const {
2958+
return StorageName_;
2959+
}
2960+
2961+
TDuration TEvictionTierSettings::GetEvictionDelay() const {
2962+
return EvictionDelay_;
2963+
}
2964+
29442965
TDateTypeColumnModeSettings::TDateTypeColumnModeSettings(const TString& columnName, const TDuration& expireAfter)
29452966
: ColumnName_(columnName)
29462967
, ExpireAfter_(expireAfter)
29472968
{}
29482969

2970+
TDateTypeColumnModeSettings::TDateTypeColumnModeSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
2971+
: ColumnName_(columnName)
2972+
, ExpireAfter_(expireAfter)
2973+
, Tiers_(tiers)
2974+
{}
2975+
29492976
void TDateTypeColumnModeSettings::SerializeTo(Ydb::Table::DateTypeColumnModeSettings& proto) const {
29502977
proto.set_column_name(ColumnName_);
2951-
proto.set_expire_after_seconds(ExpireAfter_.Seconds());
2978+
if (ExpireAfter_) {
2979+
proto.set_expire_after_seconds(ExpireAfter_->Seconds());
2980+
}
2981+
for (const auto& tier : Tiers_) {
2982+
tier.SerializeTo(*proto.add_storage_tiers());
2983+
}
29522984
}
29532985

29542986
const TString& TDateTypeColumnModeSettings::GetColumnName() const {
29552987
return ColumnName_;
29562988
}
29572989

29582990
const TDuration& TDateTypeColumnModeSettings::GetExpireAfter() const {
2959-
return ExpireAfter_;
2991+
if (ExpireAfter_) {
2992+
return *ExpireAfter_;
2993+
}
2994+
static constexpr TDuration DurationMax = TDuration::Max();
2995+
return DurationMax;
2996+
}
2997+
2998+
bool TDateTypeColumnModeSettings::HasExpireAfter() const {
2999+
return !!ExpireAfter_;
3000+
}
3001+
3002+
const TVector<TEvictionTierSettings>& TDateTypeColumnModeSettings::GetTiers() const {
3003+
return Tiers_;
29603004
}
29613005

29623006
TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter)
@@ -2965,10 +3009,22 @@ TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString
29653009
, ExpireAfter_(expireAfter)
29663010
{}
29673011

3012+
TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3013+
: ColumnName_(columnName)
3014+
, ColumnUnit_(columnUnit)
3015+
, ExpireAfter_(expireAfter)
3016+
, Tiers_(tiers)
3017+
{}
3018+
29683019
void TValueSinceUnixEpochModeSettings::SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettings& proto) const {
29693020
proto.set_column_name(ColumnName_);
29703021
proto.set_column_unit(TProtoAccessor::GetProto(ColumnUnit_));
2971-
proto.set_expire_after_seconds(ExpireAfter_.Seconds());
3022+
if (ExpireAfter_) {
3023+
proto.set_expire_after_seconds(ExpireAfter_->Seconds());
3024+
}
3025+
for (const auto& tier : Tiers_) {
3026+
tier.SerializeTo(*proto.Addstorage_tiers());
3027+
}
29723028
}
29733029

29743030
const TString& TValueSinceUnixEpochModeSettings::GetColumnName() const {
@@ -2980,7 +3036,19 @@ TValueSinceUnixEpochModeSettings::EUnit TValueSinceUnixEpochModeSettings::GetCol
29803036
}
29813037

29823038
const TDuration& TValueSinceUnixEpochModeSettings::GetExpireAfter() const {
2983-
return ExpireAfter_;
3039+
if (ExpireAfter_) {
3040+
return *ExpireAfter_;
3041+
}
3042+
static constexpr TDuration DurationMax = TDuration::Max();
3043+
return DurationMax;
3044+
}
3045+
3046+
bool TValueSinceUnixEpochModeSettings::HasExpireAfter() const {
3047+
return !!ExpireAfter_;
3048+
}
3049+
3050+
const TVector<TEvictionTierSettings>& TValueSinceUnixEpochModeSettings::GetTiers() const {
3051+
return Tiers_;
29843052
}
29853053

29863054
void TValueSinceUnixEpochModeSettings::Out(IOutputStream& out, EUnit unit) {
@@ -3023,27 +3091,37 @@ TValueSinceUnixEpochModeSettings::EUnit TValueSinceUnixEpochModeSettings::UnitFr
30233091
return EUnit::Unknown;
30243092
}
30253093

3094+
TTtlSettings::TTtlSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3095+
: Mode_(TDateTypeColumnModeSettings(columnName, expireAfter, tiers))
3096+
{}
3097+
30263098
TTtlSettings::TTtlSettings(const TString& columnName, const TDuration& expireAfter)
3027-
: Mode_(TDateTypeColumnModeSettings(columnName, expireAfter))
3099+
: TTtlSettings(columnName, expireAfter, {})
30283100
{}
30293101

30303102
TTtlSettings::TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, ui32 runIntervalSeconds)
3031-
: TTtlSettings(mode.column_name(), TDuration::Seconds(mode.expire_after_seconds()))
3032-
{
3103+
: TTtlSettings(mode.column_name(),
3104+
mode.has_expire_after_seconds() ? std::optional<TDuration>(TDuration::Seconds(mode.expire_after_seconds())) : std::nullopt,
3105+
DeserializeTiers(mode.storage_tiers())) {
30333106
RunInterval_ = TDuration::Seconds(runIntervalSeconds);
30343107
}
30353108

30363109
const TDateTypeColumnModeSettings& TTtlSettings::GetDateTypeColumn() const {
30373110
return std::get<TDateTypeColumnModeSettings>(Mode_);
30383111
}
30393112

3113+
TTtlSettings::TTtlSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3114+
: Mode_(TValueSinceUnixEpochModeSettings(columnName, columnUnit, expireAfter, tiers))
3115+
{}
3116+
30403117
TTtlSettings::TTtlSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter)
3041-
: Mode_(TValueSinceUnixEpochModeSettings(columnName, columnUnit, expireAfter))
3118+
: TTtlSettings(columnName, columnUnit, expireAfter, {})
30423119
{}
30433120

30443121
TTtlSettings::TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, ui32 runIntervalSeconds)
3045-
: TTtlSettings(mode.column_name(), TProtoAccessor::FromProto(mode.column_unit()), TDuration::Seconds(mode.expire_after_seconds()))
3046-
{
3122+
: TTtlSettings(mode.column_name(), TProtoAccessor::FromProto(mode.column_unit()),
3123+
mode.has_expire_after_seconds() ? std::optional<TDuration>(TDuration::Seconds(mode.expire_after_seconds())) : std::nullopt,
3124+
DeserializeTiers(mode.storage_tiers())) {
30473125
RunInterval_ = TDuration::Seconds(runIntervalSeconds);
30483126
}
30493127

0 commit comments

Comments
 (0)