Skip to content

Commit 6b2cb14

Browse files
swalrus1Gazizonoki
authored andcommitted
Moved commit "add tiering info to TTL in public api" from ydb repo
1 parent 6f2f7a0 commit 6b2cb14

File tree

3 files changed

+247
-47
lines changed

3 files changed

+247
-47
lines changed

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

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ class KMeansTreeSettings;
2828
class PartitioningSettings;
2929
class DateTypeColumnModeSettings;
3030
class TtlSettings;
31+
class TtlTier;
3132
class TableIndex;
3233
class TableIndexDescription;
3334
class ValueSinceUnixEpochModeSettings;
35+
class DateTypeColumnModeSettingsV1;
36+
class ValueSinceUnixEpochModeSettingsV1;
3437

3538
} // namespace Table
3639
} // namespace Ydb
@@ -427,17 +430,46 @@ struct TPartitionStats {
427430
uint32_t LeaderNodeId = 0;
428431
};
429432

433+
struct TTtlDeleteAction {};
434+
435+
struct TTtlEvictToExternalStorageAction {
436+
std::string StorageName;
437+
};
438+
439+
class TTtlTierSettings {
440+
public:
441+
using TAction = std::variant<
442+
std::monostate,
443+
TTtlDeleteAction,
444+
TTtlEvictToExternalStorageAction
445+
>;
446+
447+
public:
448+
explicit TTtlTierSettings(TDuration applyAfter, const TAction& action);
449+
explicit TTtlTierSettings(const Ydb::Table::TtlTier& tier);
450+
void SerializeTo(Ydb::Table::TtlTier& proto) const;
451+
452+
TDuration GetApplyAfter() const;
453+
const TAction& GetAction() const;
454+
455+
private:
456+
TDuration ApplyAfter_;
457+
TAction Action_;
458+
};
459+
430460
class TDateTypeColumnModeSettings {
431461
public:
432-
explicit TDateTypeColumnModeSettings(const std::string& columnName, const TDuration& expireAfter);
462+
explicit TDateTypeColumnModeSettings(const std::string& columnName, const TDuration& deprecatedExpireAfter = TDuration::Max());
433463
void SerializeTo(Ydb::Table::DateTypeColumnModeSettings& proto) const;
464+
void SerializeTo(Ydb::Table::DateTypeColumnModeSettingsV1& proto) const;
434465

435466
const std::string& GetColumnName() const;
467+
// Deprecated. Use TTtlSettings::GetExpireAfter()
436468
const TDuration& GetExpireAfter() const;
437469

438470
private:
439471
std::string ColumnName_;
440-
TDuration ExpireAfter_;
472+
TDuration DeprecatedExpireAfter_;
441473
};
442474

443475
class TValueSinceUnixEpochModeSettings {
@@ -452,8 +484,9 @@ class TValueSinceUnixEpochModeSettings {
452484
};
453485

454486
public:
455-
explicit TValueSinceUnixEpochModeSettings(const std::string& columnName, EUnit columnUnit, const TDuration& expireAfter);
487+
explicit TValueSinceUnixEpochModeSettings(const std::string& columnName, EUnit columnUnit, const TDuration& deprecatedExpireAfter = TDuration::Max());
456488
void SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettings& proto) const;
489+
void SerializeTo(Ydb::Table::ValueSinceUnixEpochModeSettingsV1& proto) const;
457490

458491
const std::string& GetColumnName() const;
459492
EUnit GetColumnUnit() const;
@@ -466,11 +499,17 @@ class TValueSinceUnixEpochModeSettings {
466499
private:
467500
std::string ColumnName_;
468501
EUnit ColumnUnit_;
469-
TDuration ExpireAfter_;
502+
TDuration DeprecatedExpireAfter_;
470503
};
471504

472505
//! Represents ttl settings
473506
class TTtlSettings {
507+
private:
508+
using TMode = std::variant<
509+
TDateTypeColumnModeSettings,
510+
TValueSinceUnixEpochModeSettings
511+
>;
512+
474513
public:
475514
using EUnit = TValueSinceUnixEpochModeSettings::EUnit;
476515

@@ -479,25 +518,35 @@ class TTtlSettings {
479518
ValueSinceUnixEpoch = 1,
480519
};
481520

521+
explicit TTtlSettings(const std::string& columnName, const std::vector<TTtlTierSettings>& tiers);
482522
explicit TTtlSettings(const std::string& columnName, const TDuration& expireAfter);
483-
explicit TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, uint32_t runIntervalSeconds);
484523
const TDateTypeColumnModeSettings& GetDateTypeColumn() const;
524+
// Deprecated. Use FromProto()
525+
explicit TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, uint32_t runIntervalSeconds);
485526

527+
explicit TTtlSettings(const std::string& columnName, EUnit columnUnit, const std::vector<TTtlTierSettings>& tiers);
486528
explicit TTtlSettings(const std::string& columnName, EUnit columnUnit, const TDuration& expireAfter);
487-
explicit TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, uint32_t runIntervalSeconds);
488529
const TValueSinceUnixEpochModeSettings& GetValueSinceUnixEpoch() const;
530+
// Deprecated. Use FromProto()
531+
explicit TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, uint32_t runIntervalSeconds);
489532

533+
static std::optional<TTtlSettings> FromProto(const Ydb::Table::TtlSettings& proto);
490534
void SerializeTo(Ydb::Table::TtlSettings& proto) const;
491535
EMode GetMode() const;
492536

493537
TTtlSettings& SetRunInterval(const TDuration& value);
494538
const TDuration& GetRunInterval() const;
495539

540+
const std::vector<TTtlTierSettings>& GetTiers() const;
541+
std::optional<TDuration> GetExpireAfter() const;
542+
496543
private:
497-
std::variant<
498-
TDateTypeColumnModeSettings,
499-
TValueSinceUnixEpochModeSettings
500-
> Mode_;
544+
explicit TTtlSettings(TMode mode, const std::vector<TTtlTierSettings>& tiers, ui32 runIntervalSeconds);
545+
static std::optional<TDuration> GetExpireAfterFrom(const std::vector<TTtlTierSettings>& tiers);
546+
547+
private:
548+
TMode Mode_;
549+
std::vector<TTtlTierSettings> Tiers_;
501550
TDuration RunInterval_ = TDuration::Zero();
502551
};
503552

src/api/protos/ydb_table.proto

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,46 @@ message ColumnMeta {
433433
}
434434
}
435435

436+
message EvictionToExternalStorageSettings {
437+
// 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;
472+
}
473+
436474
message DateTypeColumnModeSettings {
437-
// The row will be considered as expired at the moment of time, when the value
475+
// The row will be assigned a tier at the moment of time, when the value
438476
// stored in <column_name> is less than or equal to the current time (in epoch
439477
// time format), and <expire_after_seconds> has passed since that moment;
440478
// i.e. the expiration threshold is the value of <column_name> plus <expire_after_seconds>.
@@ -473,8 +511,10 @@ message ValueSinceUnixEpochModeSettings {
473511

474512
message TtlSettings {
475513
oneof mode {
476-
DateTypeColumnModeSettings date_type_column = 1;
477-
ValueSinceUnixEpochModeSettings value_since_unix_epoch = 2;
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;
478518
}
479519

480520
// There is no guarantee that expired row will be deleted immediately upon
@@ -490,6 +530,8 @@ message TtlSettings {
490530
// How often to run BRO on the same partition.
491531
// BRO will not be started more often, but may be started less often.
492532
uint32 run_interval_seconds = 3;
533+
534+
repeated TtlTier tiers = 6;
493535
}
494536

495537
message StorageSettings {

0 commit comments

Comments
 (0)