Skip to content

Commit 3f9f3a3

Browse files
authored
Merge dec871f into 804f3d6
2 parents 804f3d6 + dec871f commit 3f9f3a3

File tree

5 files changed

+154
-16
lines changed

5 files changed

+154
-16
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: 13 additions & 2 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 {

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

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,22 +2941,64 @@ bool operator!=(const TChangefeedDescription& lhs, const TChangefeedDescription&
29412941

29422942
////////////////////////////////////////////////////////////////////////////////
29432943

2944+
TEvictionTierSettings::TEvictionTierSettings(TString storageName, TDuration evictionDelay)
2945+
: StorageName_(storageName)
2946+
, EvictionDelay_(evictionDelay)
2947+
{}
2948+
2949+
TEvictionTierSettings::TEvictionTierSettings(const Ydb::Table::EvictionTier& tier)
2950+
: StorageName_(tier.storage_name())
2951+
, EvictionDelay_(TDuration::Seconds(tier.evict_after_seconds()))
2952+
{}
2953+
2954+
void TEvictionTierSettings::SerializeTo(Ydb::Table::EvictionTier& proto) const {
2955+
proto.set_storage_name(StorageName_);
2956+
proto.set_evict_after_seconds(EvictionDelay_.Seconds());
2957+
}
2958+
2959+
const TString& TEvictionTierSettings::GetStorageName() const {
2960+
return StorageName_;
2961+
}
2962+
2963+
TDuration TEvictionTierSettings::GetEvictionDelay() const {
2964+
return EvictionDelay_;
2965+
}
2966+
29442967
TDateTypeColumnModeSettings::TDateTypeColumnModeSettings(const TString& columnName, const TDuration& expireAfter)
29452968
: ColumnName_(columnName)
29462969
, ExpireAfter_(expireAfter)
29472970
{}
29482971

2972+
TDateTypeColumnModeSettings::TDateTypeColumnModeSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
2973+
: ColumnName_(columnName)
2974+
, ExpireAfter_(expireAfter)
2975+
, Tiers_(tiers)
2976+
{}
2977+
29492978
void TDateTypeColumnModeSettings::SerializeTo(Ydb::Table::DateTypeColumnModeSettings& proto) const {
29502979
proto.set_column_name(ColumnName_);
2951-
proto.set_expire_after_seconds(ExpireAfter_.Seconds());
2980+
if (ExpireAfter_) {
2981+
proto.set_expire_after_seconds(ExpireAfter_->Seconds());
2982+
}
2983+
for (const auto& tier : Tiers_) {
2984+
tier.SerializeTo(*proto.Addstorage_tiers());
2985+
}
29522986
}
29532987

29542988
const TString& TDateTypeColumnModeSettings::GetColumnName() const {
29552989
return ColumnName_;
29562990
}
29572991

29582992
const TDuration& TDateTypeColumnModeSettings::GetExpireAfter() const {
2959-
return ExpireAfter_;
2993+
if (ExpireAfter_) {
2994+
return *ExpireAfter_;
2995+
}
2996+
static constexpr TDuration DurationMax = TDuration::Max();
2997+
return DurationMax;
2998+
}
2999+
3000+
bool TDateTypeColumnModeSettings::HasExpireAfter() const {
3001+
return !!ExpireAfter_;
29603002
}
29613003

29623004
TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter)
@@ -2965,10 +3007,22 @@ TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString
29653007
, ExpireAfter_(expireAfter)
29663008
{}
29673009

3010+
TValueSinceUnixEpochModeSettings::TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3011+
: ColumnName_(columnName)
3012+
, ColumnUnit_(columnUnit)
3013+
, ExpireAfter_(expireAfter)
3014+
, Tiers_(tiers)
3015+
{}
3016+
29683017
void TValueSinceUnixEpochModeSettings::SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettings& proto) const {
29693018
proto.set_column_name(ColumnName_);
29703019
proto.set_column_unit(TProtoAccessor::GetProto(ColumnUnit_));
2971-
proto.set_expire_after_seconds(ExpireAfter_.Seconds());
3020+
if (ExpireAfter_) {
3021+
proto.set_expire_after_seconds(ExpireAfter_->Seconds());
3022+
}
3023+
for (const auto& tier : Tiers_) {
3024+
tier.SerializeTo(*proto.Addstorage_tiers());
3025+
}
29723026
}
29733027

29743028
const TString& TValueSinceUnixEpochModeSettings::GetColumnName() const {
@@ -2980,7 +3034,15 @@ TValueSinceUnixEpochModeSettings::EUnit TValueSinceUnixEpochModeSettings::GetCol
29803034
}
29813035

29823036
const TDuration& TValueSinceUnixEpochModeSettings::GetExpireAfter() const {
2983-
return ExpireAfter_;
3037+
if (ExpireAfter_) {
3038+
return *ExpireAfter_;
3039+
}
3040+
static constexpr TDuration DurationMax = TDuration::Max();
3041+
return DurationMax;
3042+
}
3043+
3044+
bool TValueSinceUnixEpochModeSettings::HasExpireAfter() const {
3045+
return !!ExpireAfter_;
29843046
}
29853047

29863048
void TValueSinceUnixEpochModeSettings::Out(IOutputStream& out, EUnit unit) {
@@ -3023,12 +3085,24 @@ TValueSinceUnixEpochModeSettings::EUnit TValueSinceUnixEpochModeSettings::UnitFr
30233085
return EUnit::Unknown;
30243086
}
30253087

3088+
TTtlSettings::TTtlSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3089+
: Mode_(TDateTypeColumnModeSettings(columnName, expireAfter, tiers))
3090+
{}
3091+
30263092
TTtlSettings::TTtlSettings(const TString& columnName, const TDuration& expireAfter)
3027-
: Mode_(TDateTypeColumnModeSettings(columnName, expireAfter))
3093+
: TTtlSettings(columnName, expireAfter, {})
30283094
{}
30293095

30303096
TTtlSettings::TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, ui32 runIntervalSeconds)
3031-
: TTtlSettings(mode.column_name(), TDuration::Seconds(mode.expire_after_seconds()))
3097+
: TTtlSettings(mode.column_name(),
3098+
mode.has_expire_after_seconds() ? std::optional<TDuration>(TDuration::Seconds(mode.expire_after_seconds())) : std::nullopt,
3099+
[&tiers = mode.storage_tiers()]() {
3100+
TVector<TEvictionTierSettings> result;
3101+
for (const auto& tier : tiers) {
3102+
result.push_back(TEvictionTierSettings(tier));
3103+
}
3104+
return result;
3105+
}())
30323106
{
30333107
RunInterval_ = TDuration::Seconds(runIntervalSeconds);
30343108
}
@@ -3037,12 +3111,24 @@ const TDateTypeColumnModeSettings& TTtlSettings::GetDateTypeColumn() const {
30373111
return std::get<TDateTypeColumnModeSettings>(Mode_);
30383112
}
30393113

3114+
TTtlSettings::TTtlSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers)
3115+
: Mode_(TValueSinceUnixEpochModeSettings(columnName, columnUnit, expireAfter, tiers))
3116+
{}
3117+
30403118
TTtlSettings::TTtlSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter)
3041-
: Mode_(TValueSinceUnixEpochModeSettings(columnName, columnUnit, expireAfter))
3119+
: TTtlSettings(columnName, columnUnit, expireAfter, {})
30423120
{}
30433121

30443122
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()))
3123+
: TTtlSettings(mode.column_name(), TProtoAccessor::FromProto(mode.column_unit()),
3124+
mode.has_expire_after_seconds() ? std::optional<TDuration>(TDuration::Seconds(mode.expire_after_seconds())) : std::nullopt,
3125+
[&tiers = mode.storage_tiers()]() {
3126+
TVector<TEvictionTierSettings> result;
3127+
for (const auto& tier : tiers) {
3128+
result.push_back(TEvictionTierSettings(tier));
3129+
}
3130+
return result;
3131+
}())
30463132
{
30473133
RunInterval_ = TDuration::Seconds(runIntervalSeconds);
30483134
}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TtlSettings;
3333
class TableIndex;
3434
class TableIndexDescription;
3535
class ValueSinceUnixEpochModeSettings;
36+
class EvictionTier;
3637

3738
} // namespace Table
3839
} // namespace Ydb
@@ -421,17 +422,34 @@ struct TPartitionStats {
421422
ui32 LeaderNodeId = 0;
422423
};
423424

425+
class TEvictionTierSettings {
426+
public:
427+
explicit TEvictionTierSettings(TString storageName, TDuration evictionDelay);
428+
explicit TEvictionTierSettings(const Ydb::Table::EvictionTier& tier);
429+
void SerializeTo(Ydb::Table::EvictionTier& proto) const;
430+
431+
const TString& GetStorageName() const;
432+
TDuration GetEvictionDelay() const;
433+
434+
private:
435+
TString StorageName_;
436+
TDuration EvictionDelay_;
437+
};
438+
424439
class TDateTypeColumnModeSettings {
425440
public:
426441
explicit TDateTypeColumnModeSettings(const TString& columnName, const TDuration& expireAfter);
442+
explicit TDateTypeColumnModeSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers);
427443
void SerializeTo(Ydb::Table::DateTypeColumnModeSettings& proto) const;
428444

429445
const TString& GetColumnName() const;
430446
const TDuration& GetExpireAfter() const;
447+
bool HasExpireAfter() const;
431448

432449
private:
433450
TString ColumnName_;
434-
TDuration ExpireAfter_;
451+
std::optional<TDuration> ExpireAfter_;
452+
TVector<TEvictionTierSettings> Tiers_;
435453
};
436454

437455
class TValueSinceUnixEpochModeSettings {
@@ -447,11 +465,13 @@ class TValueSinceUnixEpochModeSettings {
447465

448466
public:
449467
explicit TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter);
468+
explicit TValueSinceUnixEpochModeSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers);
450469
void SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettings& proto) const;
451470

452471
const TString& GetColumnName() const;
453472
EUnit GetColumnUnit() const;
454473
const TDuration& GetExpireAfter() const;
474+
bool HasExpireAfter() const;
455475

456476
static void Out(IOutputStream& o, EUnit unit);
457477
static TString ToString(EUnit unit);
@@ -460,7 +480,8 @@ class TValueSinceUnixEpochModeSettings {
460480
private:
461481
TString ColumnName_;
462482
EUnit ColumnUnit_;
463-
TDuration ExpireAfter_;
483+
std::optional<TDuration> ExpireAfter_;
484+
TVector<TEvictionTierSettings> Tiers_;
464485
};
465486

466487
//! Represents ttl settings
@@ -473,10 +494,12 @@ class TTtlSettings {
473494
ValueSinceUnixEpoch = 1,
474495
};
475496

497+
explicit TTtlSettings(const TString& columnName, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers);
476498
explicit TTtlSettings(const TString& columnName, const TDuration& expireAfter);
477499
explicit TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, ui32 runIntervalSeconds);
478500
const TDateTypeColumnModeSettings& GetDateTypeColumn() const;
479501

502+
explicit TTtlSettings(const TString& columnName, EUnit columnUnit, const std::optional<TDuration>& expireAfter, const TVector<TEvictionTierSettings>& tiers);
480503
explicit TTtlSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter);
481504
explicit TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, ui32 runIntervalSeconds);
482505
const TValueSinceUnixEpochModeSettings& GetValueSinceUnixEpoch() const;

0 commit comments

Comments
 (0)