Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swalrus1 committed Nov 29, 2024
1 parent f73c70c commit ab1a0d2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
6 changes: 3 additions & 3 deletions ydb/core/tx/schemeshard/ut_olap/ut_olap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ Y_UNIT_TEST_SUITE(TOlap) {
ColumnName: "timestamp"
ColumnUnit: UNIT_AUTO
Tiers: {
EvictAfterSeconds: 360
ApplyAfterSeconds: 360
StorageName: "Tier1"
}
}
Expand All @@ -498,7 +498,7 @@ Y_UNIT_TEST_SUITE(TOlap) {
ColumnName: "timestamp"
ColumnUnit: UNIT_AUTO
Tiers: {
EvictAfterSeconds: 3600000000
ApplyAfterSeconds: 3600000000
StorageName: "Tier1"
}
}
Expand Down Expand Up @@ -649,7 +649,7 @@ Y_UNIT_TEST_SUITE(TOlap) {
ColumnName: "timestamp"
ColumnUnit: UNIT_AUTO
Tiers: {
EvictAfterSeconds: 3600000000
ApplyAfterSeconds: 3600000000
StorageName: "Tier1"
}
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/public/lib/experimental/ydb_logstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace NYdb {
namespace NLogStore {

TMaybe<TTtlSettings> TtlSettingsFromProto(const Ydb::Table::TtlSettings& proto) {
if (auto settings = TTtlSettings::DeserializeFromProto(proto)) {
if (auto settings = TTtlSettings::FromProto(proto)) {
return *settings;
}
return Nothing();
Expand Down
61 changes: 39 additions & 22 deletions ydb/public/sdk/cpp/client/ydb_table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class TTableDescription::TImpl {
}

// ttl settings
if (auto ttlSettings = TTtlSettings::DeserializeFromProto(proto.ttl_settings())) {
if (auto ttlSettings = TTtlSettings::FromProto(proto.ttl_settings())) {
TtlSettings_ = std::move(*ttlSettings);
}

Expand Down Expand Up @@ -2913,8 +2913,8 @@ bool operator!=(const TChangefeedDescription& lhs, const TChangefeedDescription&

TTtlTierSettings::TTtlTierSettings(TDuration evictionDelay, const TAction& action)
: ApplyAfter_(evictionDelay)
, Action_(action) {
}
, Action_(action)
{ }

TTtlTierSettings::TTtlTierSettings(const Ydb::Table::TtlTier& tier)
: ApplyAfter_(TDuration::Seconds(tier.apply_after_seconds())) {
Expand Down Expand Up @@ -3078,42 +3078,55 @@ const TValueSinceUnixEpochModeSettings& TTtlSettings::GetValueSinceUnixEpoch() c
return std::get<TValueSinceUnixEpochModeSettings>(Mode_);
}

std::optional<TTtlSettings> TTtlSettings::DeserializeFromProto(const Ydb::Table::TtlSettings& proto) {
TDuration legacyExpireAfter = TDuration::Max();
std::optional<TTtlSettings> TTtlSettings::FromProto(const Ydb::Table::TtlSettings& proto) {
TVector<TTtlTierSettings> tiers;
for (const auto& tier : proto.tiers()) {
if (tier.has_delete_()) {
legacyExpireAfter = TDuration::Seconds(tier.apply_after_seconds());
break;
}
tiers.emplace_back(tier);
}
TDuration legacyExpireAfter = GetExpireAfterFrom(tiers).value_or(TDuration::Max());

switch(proto.mode_case()) {
case Ydb::Table::TtlSettings::kDateTypeColumn:
return TTtlSettings(proto.date_type_column(), proto.run_interval_seconds());
case Ydb::Table::TtlSettings::kValueSinceUnixEpoch:
return TTtlSettings(proto.value_since_unix_epoch(), proto.run_interval_seconds());
case Ydb::Table::TtlSettings::kDateTypeColumnV1:
return TTtlSettings(TDateTypeColumnModeSettings(proto.date_type_column_v1().column_name(), legacyExpireAfter), proto.run_interval_seconds());
return TTtlSettings(
TDateTypeColumnModeSettings(proto.date_type_column_v1().column_name(), legacyExpireAfter), tiers, proto.run_interval_seconds());
case Ydb::Table::TtlSettings::kValueSinceUnixEpochV1:
return TTtlSettings(TValueSinceUnixEpochModeSettings(proto.value_since_unix_epoch_v1().column_name(), TProtoAccessor::FromProto(proto.value_since_unix_epoch_v1().column_unit()), legacyExpireAfter), proto.run_interval_seconds());
return TTtlSettings(TValueSinceUnixEpochModeSettings(proto.value_since_unix_epoch_v1().column_name(),
TProtoAccessor::FromProto(proto.value_since_unix_epoch_v1().column_unit()), legacyExpireAfter),
tiers, proto.run_interval_seconds());
case Ydb::Table::TtlSettings::MODE_NOT_SET:
return std::nullopt;
break;
}
}

void TTtlSettings::SerializeTo(Ydb::Table::TtlSettings& proto) const {
switch (GetMode()) {
case EMode::DateTypeColumn:
GetDateTypeColumn().SerializeTo(*proto.mutable_date_type_column_v1());
break;
case EMode::ValueSinceUnixEpoch:
GetValueSinceUnixEpoch().SerializeTo(*proto.mutable_value_since_unix_epoch_v1());
break;
}
if (Tiers_.size() == 1 && std::holds_alternative<TTtlDeleteAction>(Tiers_.back().GetAction())) {
// serialize DELETE-only TTL to legacy format for backwards-compatibility
switch (GetMode()) {
case EMode::DateTypeColumn:
GetDateTypeColumn().SerializeTo(*proto.mutable_date_type_column());
break;
case EMode::ValueSinceUnixEpoch:
GetValueSinceUnixEpoch().SerializeTo(*proto.mutable_value_since_unix_epoch());
break;
}
} else {
switch (GetMode()) {
case EMode::DateTypeColumn:
GetDateTypeColumn().SerializeTo(*proto.mutable_date_type_column_v1());
break;
case EMode::ValueSinceUnixEpoch:
GetValueSinceUnixEpoch().SerializeTo(*proto.mutable_value_since_unix_epoch_v1());
break;
}

for (const auto& tier : Tiers_) {
tier.SerializeTo(*proto.add_tiers());
for (const auto& tier : Tiers_) {
tier.SerializeTo(*proto.add_tiers());
}
}

if (RunInterval_) {
Expand Down Expand Up @@ -3151,7 +3164,11 @@ std::optional<TDuration> TTtlSettings::GetExpireAfterFrom(const TVector<TTtlTier
return std::nullopt;
}

TTtlSettings::TTtlSettings(TMode mode, ui32 runIntervalSeconds) : Mode_(std::move(mode)), RunInterval_(TDuration::Seconds(runIntervalSeconds)) {}
TTtlSettings::TTtlSettings(TMode mode, const TVector<TTtlTierSettings>& tiers, ui32 runIntervalSeconds)
: Mode_(std::move(mode))
, Tiers_(tiers)
, RunInterval_(TDuration::Seconds(runIntervalSeconds))
{}

TAlterTtlSettings::EAction TAlterTtlSettings::GetAction() const {
return static_cast<EAction>(Action_.index());
Expand Down
8 changes: 4 additions & 4 deletions ydb/public/sdk/cpp/client/ydb_table/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,16 @@ class TTtlSettings {
explicit TTtlSettings(const TString& columnName, const TVector<TTtlTierSettings>& tiers);
explicit TTtlSettings(const TString& columnName, const TDuration& expireAfter);
const TDateTypeColumnModeSettings& GetDateTypeColumn() const;
// Deprecated. Use DeserializeFromProto()
// Deprecated. Use FromProto()
explicit TTtlSettings(const Ydb::Table::DateTypeColumnModeSettings& mode, ui32 runIntervalSeconds);

explicit TTtlSettings(const TString& columnName, EUnit columnUnit, const TVector<TTtlTierSettings>& tiers);
explicit TTtlSettings(const TString& columnName, EUnit columnUnit, const TDuration& expireAfter);
const TValueSinceUnixEpochModeSettings& GetValueSinceUnixEpoch() const;
// Deprecated. Use DeserializeFromProto()
// Deprecated. Use FromProto()
explicit TTtlSettings(const Ydb::Table::ValueSinceUnixEpochModeSettings& mode, ui32 runIntervalSeconds);

static std::optional<TTtlSettings> DeserializeFromProto(const Ydb::Table::TtlSettings& proto);
static std::optional<TTtlSettings> FromProto(const Ydb::Table::TtlSettings& proto);
void SerializeTo(Ydb::Table::TtlSettings& proto) const;
EMode GetMode() const;

Expand All @@ -536,7 +536,7 @@ class TTtlSettings {
std::optional<TDuration> GetExpireAfter() const;

private:
explicit TTtlSettings(TMode mode, ui32 runIntervalSeconds);
explicit TTtlSettings(TMode mode, const TVector<TTtlTierSettings>& tiers, ui32 runIntervalSeconds);
static std::optional<TDuration> GetExpireAfterFrom(const TVector<TTtlTierSettings>& tiers);

private:
Expand Down

0 comments on commit ab1a0d2

Please sign in to comment.