Skip to content

Commit 64b7462

Browse files
swalrus1Gazizonoki
authored andcommitted
Moved commit "new tiered_ttl mode in public TtlSettings" from ydb repo
1 parent a861465 commit 64b7462

File tree

3 files changed

+150
-187
lines changed

3 files changed

+150
-187
lines changed

include/ydb-cpp-sdk/client/table/table.h

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class TtlTier;
3232
class TableIndex;
3333
class TableIndexDescription;
3434
class ValueSinceUnixEpochModeSettings;
35-
class DateTypeColumnModeSettingsV1;
36-
class ValueSinceUnixEpochModeSettingsV1;
35+
class EvictionToExternalStorageSettings;
3736

3837
} // namespace Table
3938
} // namespace Ydb
@@ -434,46 +433,17 @@ struct TPartitionStats {
434433
uint32_t LeaderNodeId = 0;
435434
};
436435

437-
struct TTtlDeleteAction {};
438-
439-
struct TTtlEvictToExternalStorageAction {
440-
std::string StorageName;
441-
};
442-
443-
class TTtlTierSettings {
444-
public:
445-
using TAction = std::variant<
446-
std::monostate,
447-
TTtlDeleteAction,
448-
TTtlEvictToExternalStorageAction
449-
>;
450-
451-
public:
452-
explicit TTtlTierSettings(TDuration applyAfter, const TAction& action);
453-
explicit TTtlTierSettings(const Ydb::Table::TtlTier& tier);
454-
void SerializeTo(Ydb::Table::TtlTier& proto) const;
455-
456-
TDuration GetApplyAfter() const;
457-
const TAction& GetAction() const;
458-
459-
private:
460-
TDuration ApplyAfter_;
461-
TAction Action_;
462-
};
463-
464436
class TDateTypeColumnModeSettings {
465437
public:
466-
explicit TDateTypeColumnModeSettings(const std::string& columnName, const TDuration& deprecatedExpireAfter = TDuration::Max());
438+
explicit TDateTypeColumnModeSettings(const std::string& columnName, const TDuration& applyAfter);
467439
void SerializeTo(Ydb::Table::DateTypeColumnModeSettings& proto) const;
468-
void SerializeTo(Ydb::Table::DateTypeColumnModeSettingsV1& proto) const;
469440

470441
const std::string& GetColumnName() const;
471-
// Deprecated. Use TTtlSettings::GetExpireAfter()
472442
const TDuration& GetExpireAfter() const;
473443

474444
private:
475445
std::string ColumnName_;
476-
TDuration DeprecatedExpireAfter_;
446+
TDuration ApplyAfter_;
477447
};
478448

479449
class TValueSinceUnixEpochModeSettings {
@@ -488,9 +458,8 @@ class TValueSinceUnixEpochModeSettings {
488458
};
489459

490460
public:
491-
explicit TValueSinceUnixEpochModeSettings(const std::string& columnName, EUnit columnUnit, const TDuration& deprecatedExpireAfter = TDuration::Max());
461+
explicit TValueSinceUnixEpochModeSettings(const std::string& columnName, EUnit columnUnit, const TDuration& applyAfter);
492462
void SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettings& proto) const;
493-
void SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettingsV1& proto) const;
494463

495464
const std::string& GetColumnName() const;
496465
EUnit GetColumnUnit() const;
@@ -503,7 +472,45 @@ class TValueSinceUnixEpochModeSettings {
503472
private:
504473
std::string ColumnName_;
505474
EUnit ColumnUnit_;
506-
TDuration DeprecatedExpireAfter_;
475+
TDuration ApplyAfter_;
476+
};
477+
478+
class TTtlDeleteAction {};
479+
class TTtlEvictToExternalStorageAction {
480+
public:
481+
TTtlEvictToExternalStorageAction(const std::string& storageName);
482+
void SerializeTo(Ydb::Table::EvictionToExternalStorageSettings& proto) const;
483+
484+
std::string GetStorage() const;
485+
486+
private:
487+
std::string Storage_;
488+
};
489+
490+
class TTtlTierSettings {
491+
public:
492+
using TExpression = std::variant<
493+
TDateTypeColumnModeSettings,
494+
TValueSinceUnixEpochModeSettings
495+
>;
496+
497+
using TAction = std::variant<
498+
TTtlDeleteAction,
499+
TTtlEvictToExternalStorageAction
500+
>;
501+
502+
public:
503+
explicit TTtlTierSettings(const TExpression& expression, const TAction& action);
504+
505+
static std::optional<TTtlTierSettings> FromProto(const Ydb::Table::TtlTier& tier);
506+
void SerializeTo(Ydb::Table::TtlTier& proto) const;
507+
508+
const TExpression& GetExpression() const;
509+
const TAction& GetAction() const;
510+
511+
private:
512+
TExpression Expression_;
513+
TAction Action_;
507514
};
508515

509516
//! Represents ttl settings
@@ -522,16 +529,14 @@ class TTtlSettings {
522529
ValueSinceUnixEpoch = 1,
523530
};
524531

525-
explicit TTtlSettings(const std::string& columnName, const std::vector<TTtlTierSettings>& tiers);
532+
explicit TTtlSettings(const std::vector<TTtlTierSettings>& tiers);
533+
526534
explicit TTtlSettings(const std::string& columnName, const TDuration& expireAfter);
527535
const TDateTypeColumnModeSettings& GetDateTypeColumn() const;
528-
// Deprecated. Use FromProto()
529536
explicit TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, uint32_t runIntervalSeconds);
530537

531-
explicit TTtlSettings(const std::string& columnName, EUnit columnUnit, const std::vector<TTtlTierSettings>& tiers);
532538
explicit TTtlSettings(const std::string& columnName, EUnit columnUnit, const TDuration& expireAfter);
533539
const TValueSinceUnixEpochModeSettings& GetValueSinceUnixEpoch() const;
534-
// Deprecated. Use FromProto()
535540
explicit TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, uint32_t runIntervalSeconds);
536541

537542
static std::optional<TTtlSettings> FromProto(const Ydb::Table::TtlSettings& proto);
@@ -542,14 +547,8 @@ class TTtlSettings {
542547
const TDuration& GetRunInterval() const;
543548

544549
const std::vector<TTtlTierSettings>& GetTiers() const;
545-
std::optional<TDuration> GetExpireAfter() const;
546-
547-
private:
548-
explicit TTtlSettings(TMode mode, const std::vector<TTtlTierSettings>& tiers, ui32 runIntervalSeconds);
549-
static std::optional<TDuration> GetExpireAfterFrom(const std::vector<TTtlTierSettings>& tiers);
550550

551551
private:
552-
TMode Mode_;
553552
std::vector<TTtlTierSettings> Tiers_;
554553
TDuration RunInterval_ = TDuration::Zero();
555554
};

src/api/protos/ydb_table.proto

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -435,44 +435,11 @@ message ColumnMeta {
435435

436436
message EvictionToExternalStorageSettings {
437437
// Path to external data source
438-
string storage_name = 1;
439-
}
440-
441-
message TtlTier {
442-
uint32 apply_after_seconds = 1;
443-
444-
oneof action {
445-
google.protobuf.Empty delete = 2;
446-
EvictionToExternalStorageSettings evict_to_external_storage = 3;
447-
}
448-
}
449-
450-
message DateTypeColumnModeSettingsV1 {
451-
// The row will be assigned a tier at the moment of time, when the value
452-
// stored in <column_name> is less than or equal to the current time (in epoch
453-
// time format), and <tier.apply_after_seconds> has passed since that moment;
454-
// i.e. the eviction threshold is the value of <column_name> plus <tier.apply_after_seconds>.
455-
456-
// The column type must be a date type
457-
string column_name = 1;
458-
}
459-
460-
message ValueSinceUnixEpochModeSettingsV1 {
461-
// Same as DateTypeColumnModeSettings (above), but useful when type of the
462-
// value stored in <column_name> is not a date type.
463-
464-
// The column type must be one of:
465-
// - Uint32
466-
// - Uint64
467-
// - DyNumber
468-
string column_name = 1;
469-
470-
// Interpretation of the value stored in <column_name>
471-
ValueSinceUnixEpochModeSettings.Unit column_unit = 2;
438+
string storage = 1;
472439
}
473440

474441
message DateTypeColumnModeSettings {
475-
// The row will be assigned a tier at the moment of time, when the value
442+
// The row will be considered as expired or assigned a tier at the moment of time, when the value
476443
// stored in <column_name> is less than or equal to the current time (in epoch
477444
// time format), and <expire_after_seconds> has passed since that moment;
478445
// i.e. the expiration threshold is the value of <column_name> plus <expire_after_seconds>.
@@ -509,12 +476,27 @@ message ValueSinceUnixEpochModeSettings {
509476
uint32 expire_after_seconds = 3;
510477
}
511478

479+
message TtlTier {
480+
oneof expression {
481+
DateTypeColumnModeSettings date_type_column = 1;
482+
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 2;
483+
}
484+
485+
oneof action {
486+
google.protobuf.Empty delete = 3;
487+
EvictionToExternalStorageSettings evict_to_external_storage = 4;
488+
}
489+
}
490+
491+
message TieredModeSettings {
492+
repeated TtlTier tiers = 1;
493+
}
494+
512495
message TtlSettings {
513496
oneof mode {
514-
DateTypeColumnModeSettings date_type_column = 1 [deprecated = true];
515-
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 2 [deprecated = true];
516-
DateTypeColumnModeSettingsV1 date_type_column_v1 = 4;
517-
ValueSinceUnixEpochModeSettingsV1 value_since_unix_epoch_v1 = 5;
497+
DateTypeColumnModeSettings date_type_column = 1;
498+
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 2;
499+
TieredModeSettings tiered_ttl = 4;
518500
}
519501

520502
// There is no guarantee that expired row will be deleted immediately upon
@@ -530,8 +512,6 @@ message TtlSettings {
530512
// How often to run BRO on the same partition.
531513
// BRO will not be started more often, but may be started less often.
532514
uint32 run_interval_seconds = 3;
533-
534-
repeated TtlTier tiers = 6;
535515
}
536516

537517
message StorageSettings {

0 commit comments

Comments
 (0)