Skip to content

Commit 634a292

Browse files
authored
Merge 2ab2a19 into 4239317
2 parents 4239317 + 2ab2a19 commit 634a292

File tree

9 files changed

+284
-115
lines changed

9 files changed

+284
-115
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: 34 additions & 20 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,42 @@ 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+
static const auto& fillCommonFields = []<class TModeSettings>(TModeSettings& out, const TTtl& in) {
511+
out.set_column_name(in.GetColumnName());
512+
if (in.TiersSize()) {
513+
std::optional<ui32> expireInSeconds;
514+
for (const auto& inTier : in.GetTiers()) {
515+
if (inTier.HasDelete()) {
516+
expireInSeconds = inTier.GetEvictAfterSeconds();
517+
break;
518+
}
519+
}
520+
out.set_expire_after_seconds(expireInSeconds.value_or(std::numeric_limits<uint32_t>::max()));
521+
} else {
522+
// legacy schema
523+
out.set_expire_after_seconds(in.GetExpireAfterSeconds());
524+
}
525+
};
526+
527+
for (const auto& inTier : inTTL.GetTiers()) {
528+
auto* outTier = out.mutable_ttl_settings()->add_tiers();
529+
outTier->set_evict_after_seconds(inTier.GetEvictAfterSeconds());
530+
switch (inTier.GetActionCase()) {
531+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::kDelete:
532+
outTier->mutable_delete_();
533+
break;
534+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::kEvictToExternalStorage:
535+
outTier->mutable_evict_to_external_storage()->set_storage_name(inTier.GetEvictToExternalStorage().GetStorageName());
536+
break;
537+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::ACTION_NOT_SET:
538+
break;
539+
}
540+
}
541+
512542
switch (inTTL.GetColumnUnit()) {
513543
case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: {
514544
auto& outTTL = *out.mutable_ttl_settings()->mutable_date_type_column();
515-
outTTL.set_column_name(inTTL.GetColumnName());
516-
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
545+
fillCommonFields(outTTL, inTTL);
517546
break;
518547
}
519548

@@ -522,9 +551,8 @@ static void AddTtl(TYdbProto& out, const TTtl& inTTL) {
522551
case NKikimrSchemeOp::TTTLSettings::UNIT_MICROSECONDS:
523552
case NKikimrSchemeOp::TTTLSettings::UNIT_NANOSECONDS: {
524553
auto& outTTL = *out.mutable_ttl_settings()->mutable_value_since_unix_epoch();
525-
outTTL.set_column_name(inTTL.GetColumnName());
554+
fillCommonFields(outTTL, inTTL);
526555
outTTL.set_column_unit(static_cast<Ydb::Table::ValueSinceUnixEpochModeSettings::Unit>(inTTL.GetColumnUnit()));
527-
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
528556
break;
529557
}
530558

@@ -572,10 +600,6 @@ void FillColumnDescriptionImpl(TYdbProto& out,
572600
if (in.GetTTLSettings().HasEnabled()) {
573601
AddTtl(out, in.GetTTLSettings().GetEnabled());
574602
}
575-
576-
if (in.GetTTLSettings().HasUseTiering()) {
577-
out.set_tiering(in.GetTTLSettings().GetUseTiering());
578-
}
579603
}
580604
}
581605

@@ -612,10 +636,6 @@ void FillColumnDescription(Ydb::Table::DescribeTableResult& out, const NKikimrSc
612636
if (in.GetTtlSettings().HasEnabled()) {
613637
AddTtl(out, in.GetTtlSettings().GetEnabled());
614638
}
615-
616-
if (in.GetTtlSettings().HasUseTiering()) {
617-
out.set_tiering(in.GetTtlSettings().GetUseTiering());
618-
}
619639
}
620640

621641
out.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN);
@@ -829,12 +849,6 @@ bool BuildAlterColumnTableModifyScheme(const TString& path, const Ydb::Table::Al
829849
} else if (req->has_drop_ttl_settings()) {
830850
alterColumnTable->MutableAlterTtlSettings()->MutableDisabled();
831851
}
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-
}
838852
}
839853

840854
return true;

ydb/core/ydb_convert/table_settings.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,40 @@ 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, std::optional<ui32> expireAfterSeconds) {
32+
out.SetColumnName(in.column_name());
33+
out.SetExpireAfterSeconds(expireAfterSeconds.value_or(in.expire_after_seconds()));
34+
};
35+
36+
std::optional<ui32> expireAfterSeconds;
37+
if (in.tiers_size()) {
38+
for (const auto& inTier : in.tiers()) {
39+
auto* outTier = out.AddTiers();
40+
outTier->SetEvictAfterSeconds(inTier.evict_after_seconds());
41+
switch (inTier.action_case()) {
42+
case Ydb::Table::TtlTier::kDelete:
43+
outTier->MutableDelete();
44+
expireAfterSeconds = inTier.evict_after_seconds();
45+
break;
46+
case Ydb::Table::TtlTier::kEvictToExternalStorage:
47+
outTier->MutableEvictToExternalStorage()->SetStorageName(inTier.evict_to_external_storage().storage_name());
48+
break;
49+
case Ydb::Table::TtlTier::ACTION_NOT_SET:
50+
break;
51+
}
52+
}
53+
if (!expireAfterSeconds) {
54+
expireAfterSeconds = std::numeric_limits<uint32_t>::max();
55+
}
56+
}
57+
3158
switch (in.mode_case()) {
3259
case Ydb::Table::TtlSettings::kDateTypeColumn:
33-
out.SetColumnName(in.date_type_column().column_name());
34-
out.SetExpireAfterSeconds(in.date_type_column().expire_after_seconds());
60+
fillCommonFields(out, in.date_type_column(), expireAfterSeconds);
3561
break;
3662

3763
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());
64+
fillCommonFields(out, in.value_since_unix_epoch(), expireAfterSeconds);
4065

4166
#define CASE_UNIT(type) \
4267
case Ydb::Table::ValueSinceUnixEpochModeSettings::type: \

ydb/public/api/protos/ydb_table.proto

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,36 @@ 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 belong to 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 <evict_after_seconds> has passed since that moment;
459+
// i.e. the eviction threshold is the value of <column_name> plus <evict_after_seconds>.
441460

442461
// The column type must be a date type
443462
string column_name = 1;
444463

464+
// Deprecated. Use TtlSettings.tiers instead. If TtlSettings.tiers is not empty,
465+
// expire_after_seconds does not take effect
445466
uint32 expire_after_seconds = 2;
446467
}
447468

@@ -466,8 +487,8 @@ message ValueSinceUnixEpochModeSettings {
466487
// Interpretation of the value stored in <column_name>
467488
Unit column_unit = 2;
468489

469-
// This option is always interpreted as seconds regardless of the
470-
// <column_unit> value.
490+
// Deprecated. Use TtlSettings.tiers instead. If TtlSettings.tiers is not empty,
491+
// expire_after_seconds does not take effect
471492
uint32 expire_after_seconds = 3;
472493
}
473494

@@ -490,6 +511,8 @@ message TtlSettings {
490511
// How often to run BRO on the same partition.
491512
// BRO will not be started more often, but may be started less often.
492513
uint32 run_interval_seconds = 3;
514+
515+
repeated TtlTier tiers = 4;
493516
}
494517

495518
message StorageSettings {
@@ -624,7 +647,7 @@ message CreateTableRequest {
624647
Ydb.FeatureFlag.Status key_bloom_filter = 16;
625648
// Read replicas settings for table
626649
ReadReplicasSettings read_replicas_settings = 17;
627-
// Tiering rules name. It specifies how data migrates from one tier (logical storage) to another.
650+
// Deprecated. Use TTL instead.
628651
string tiering = 18;
629652
// Is temporary table
630653
bool temporary = 19;
@@ -704,7 +727,7 @@ message AlterTableRequest {
704727
repeated string drop_changefeeds = 20;
705728
// Rename existed index
706729
repeated RenameIndexItem rename_indexes = 21;
707-
// Setup or remove tiering
730+
// Deprecated. Use ttl_action instead
708731
oneof tiering_action {
709732
string set_tiering = 22;
710733
google.protobuf.Empty drop_tiering = 23;

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;

ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ namespace {
845845

846846
void PrintPartitionInfo(const NTable::TTableDescription& tableDescription, bool showBoundaries, bool showStats) {
847847
const TVector<NTable::TKeyRange>& ranges = tableDescription.GetKeyRanges();
848-
const TVector<NTable::TPartitionStats>& stats = tableDescription.GetPartitionStats();
848+
const TVector<NTable::TTPartitionStats>& stats = tableDescription.GetPartitionStats();
849849
if (showBoundaries) {
850850
if (showStats) {
851851
Cout << Endl << "Partitions info:" << Endl;
@@ -921,7 +921,7 @@ namespace {
921921
}
922922
}
923923
if (showStats) {
924-
const NTable::TPartitionStats& partStats = stats[i];
924+
const NTable::TTPartitionStats& partStats = stats[i];
925925
row.Column(j++, partStats.Rows);
926926
row.Column(j++, PrettySize(partStats.Size));
927927
}

0 commit comments

Comments
 (0)