Skip to content

Commit f8d448e

Browse files
authored
Merge eea3575 into d353cb0
2 parents d353cb0 + eea3575 commit f8d448e

File tree

9 files changed

+305
-115
lines changed

9 files changed

+305
-115
lines changed

ydb/core/protos/flat_scheme_op.proto

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,29 @@ 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 TEvictionToColumnFamilySettings {
229+
optional string FamilyName = 1;
230+
}
231+
232+
message TTier {
233+
optional uint32 EvictAfterSeconds = 1;
234+
oneof Action {
235+
google.protobuf.Empty Delete = 2;
236+
TEvictionToExternalStorageSettings EvictToExternalStorage = 3;
237+
TEvictionToColumnFamilySettings EvictToColumnFamily = 4;
238+
}
239+
}
240+
224241
message TEnabled {
225242
optional string ColumnName = 1;
226-
optional uint32 ExpireAfterSeconds = 2;
243+
optional uint32 ExpireAfterSeconds = 2 [deprecated = true];
227244
optional EUnit ColumnUnit = 3;
228245
optional TSysSettings SysSettings = 4;
246+
repeated TTier Tiers = 5;
229247
}
230248

231249
message TDisabled {
@@ -570,10 +588,11 @@ message TColumnDataLifeCycle {
570588
message TTtl {
571589
optional string ColumnName = 1;
572590
oneof Expire {
573-
uint32 ExpireAfterSeconds = 2;
591+
uint32 ExpireAfterSeconds = 2 [deprecated = true];
574592
uint64 ExpireAfterBytes = 4;
575593
}
576594
optional TTTLSettings.EUnit ColumnUnit = 3;
595+
repeated TTTLSettings.TTier Tiers = 5;
577596
}
578597

579598
message TDisabled {

ydb/core/ydb_convert/table_description.cpp

Lines changed: 37 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,45 @@ 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::kEvictToColumnFamily:
538+
outTier->mutable_evict_to_column_family()->set_family_name(inTier.GetEvictToColumnFamily().GetFamilyName());
539+
break;
540+
case NKikimrSchemeOp::TTTLSettings::TTier::ActionCase::ACTION_NOT_SET:
541+
break;
542+
}
543+
}
544+
512545
switch (inTTL.GetColumnUnit()) {
513546
case NKikimrSchemeOp::TTTLSettings::UNIT_AUTO: {
514547
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());
548+
fillCommonFields(outTTL, inTTL);
517549
break;
518550
}
519551

@@ -522,9 +554,8 @@ static void AddTtl(TYdbProto& out, const TTtl& inTTL) {
522554
case NKikimrSchemeOp::TTTLSettings::UNIT_MICROSECONDS:
523555
case NKikimrSchemeOp::TTTLSettings::UNIT_NANOSECONDS: {
524556
auto& outTTL = *out.mutable_ttl_settings()->mutable_value_since_unix_epoch();
525-
outTTL.set_column_name(inTTL.GetColumnName());
557+
fillCommonFields(outTTL, inTTL);
526558
outTTL.set_column_unit(static_cast<Ydb::Table::ValueSinceUnixEpochModeSettings::Unit>(inTTL.GetColumnUnit()));
527-
outTTL.set_expire_after_seconds(inTTL.GetExpireAfterSeconds());
528559
break;
529560
}
530561

@@ -572,10 +603,6 @@ void FillColumnDescriptionImpl(TYdbProto& out,
572603
if (in.GetTTLSettings().HasEnabled()) {
573604
AddTtl(out, in.GetTTLSettings().GetEnabled());
574605
}
575-
576-
if (in.GetTTLSettings().HasUseTiering()) {
577-
out.set_tiering(in.GetTTLSettings().GetUseTiering());
578-
}
579606
}
580607
}
581608

@@ -612,10 +639,6 @@ void FillColumnDescription(Ydb::Table::DescribeTableResult& out, const NKikimrSc
612639
if (in.GetTtlSettings().HasEnabled()) {
613640
AddTtl(out, in.GetTtlSettings().GetEnabled());
614641
}
615-
616-
if (in.GetTtlSettings().HasUseTiering()) {
617-
out.set_tiering(in.GetTtlSettings().GetUseTiering());
618-
}
619642
}
620643

621644
out.set_store_type(Ydb::Table::StoreType::STORE_TYPE_COLUMN);
@@ -829,12 +852,6 @@ bool BuildAlterColumnTableModifyScheme(const TString& path, const Ydb::Table::Al
829852
} else if (req->has_drop_ttl_settings()) {
830853
alterColumnTable->MutableAlterTtlSettings()->MutableDisabled();
831854
}
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-
}
838855
}
839856

840857
return true;

ydb/core/ydb_convert/table_settings.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,43 @@ 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::kEvictToColumnFamily:
50+
outTier->MutableEvictToColumnFamily()->SetFamilyName(inTier.evict_to_column_family().family_name());
51+
break;
52+
case Ydb::Table::TtlTier::ACTION_NOT_SET:
53+
break;
54+
}
55+
}
56+
if (!expireAfterSeconds) {
57+
expireAfterSeconds = std::numeric_limits<uint32_t>::max();
58+
}
59+
}
60+
3161
switch (in.mode_case()) {
3262
case Ydb::Table::TtlSettings::kDateTypeColumn:
33-
out.SetColumnName(in.date_type_column().column_name());
34-
out.SetExpireAfterSeconds(in.date_type_column().expire_after_seconds());
63+
fillCommonFields(out, in.date_type_column(), expireAfterSeconds);
3564
break;
3665

3766
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());
67+
fillCommonFields(out, in.value_since_unix_epoch(), expireAfterSeconds);
4068

4169
#define CASE_UNIT(type) \
4270
case Ydb::Table::ValueSinceUnixEpochModeSettings::type: \

ydb/public/api/protos/ydb_table.proto

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,37 @@ 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+
EvictionToFamilySettings evict_to_column_family = 3;
453+
}
454+
}
455+
436456
message DateTypeColumnModeSettings {
437-
// The row will be considered as expired at the moment of time, when the value
457+
// The row will be belong to a tier at the moment of time, when the value
438458
// 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>.
459+
// time format), and <evict_after_seconds> has passed since that moment;
460+
// i.e. the eviction threshold is the value of <column_name> plus <evict_after_seconds>.
441461

442462
// The column type must be a date type
443463
string column_name = 1;
444464

465+
// Deprecated. Use TtlSettings.tiers instead. If TtlSettings.tiers is not empty,
466+
// expire_after_seconds does not take effect
445467
uint32 expire_after_seconds = 2;
446468
}
447469

@@ -466,8 +488,8 @@ message ValueSinceUnixEpochModeSettings {
466488
// Interpretation of the value stored in <column_name>
467489
Unit column_unit = 2;
468490

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

@@ -490,6 +512,8 @@ message TtlSettings {
490512
// How often to run BRO on the same partition.
491513
// BRO will not be started more often, but may be started less often.
492514
uint32 run_interval_seconds = 3;
515+
516+
repeated TtlTier tiers = 4;
493517
}
494518

495519
message StorageSettings {
@@ -624,7 +648,7 @@ message CreateTableRequest {
624648
Ydb.FeatureFlag.Status key_bloom_filter = 16;
625649
// Read replicas settings for table
626650
ReadReplicasSettings read_replicas_settings = 17;
627-
// Tiering rules name. It specifies how data migrates from one tier (logical storage) to another.
651+
// Deprecated. Use TTL instead.
628652
string tiering = 18;
629653
// Is temporary table
630654
bool temporary = 19;
@@ -704,7 +728,7 @@ message AlterTableRequest {
704728
repeated string drop_changefeeds = 20;
705729
// Rename existed index
706730
repeated RenameIndexItem rename_indexes = 21;
707-
// Setup or remove tiering
731+
// Deprecated. Use ttl_action instead
708732
oneof tiering_action {
709733
string set_tiering = 22;
710734
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)