Skip to content

Commit

Permalink
Some fixes in erase_rows_condition.cpp
Browse files Browse the repository at this point in the history
- set CannotSerialize flag on Unsupported unit
- fix typo
- refactor WallClock serialization functions
  • Loading branch information
lex007in committed Oct 11, 2024
1 parent 38747d7 commit d172930
Showing 1 changed file with 57 additions and 49 deletions.
106 changes: 57 additions & 49 deletions ydb/core/tx/datashard/erase_rows_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ class TExpirationCondition: public IEraseRowsCondition {
}
}

TMaybe<TString> GetWallClockDyNumber() const {
const auto instantValue = InstantValue(WallClockInstant, Unit);
if (!instantValue) {
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Unsupported unit: " << static_cast<ui32>(Unit));
CannotSerialize = true;
return Nothing();
}

const auto strInstant = ToString(*instantValue);
WallClockSerialized = NDyNumber::ParseDyNumberString(strInstant);
if (!WallClockSerialized) {
CannotSerialize = true;
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Cannot parse DyNumber from: " << strInstant.Quote());
}

return WallClockSerialized;
}

void ParsePgFromText(const TString& value) const {
const auto& result = NPg::PgNativeBinaryFromNativeText(value, Type.GetPgTypeDesc());
if (result.Error) {
Expand All @@ -44,6 +64,34 @@ class TExpirationCondition: public IEraseRowsCondition {
}
}

TMaybe<TString> GetWallClockPg() const {
switch (NPg::PgTypeIdFromTypeDesc(Type.GetPgTypeDesc())) {
case DATEOID:
case TIMESTAMPOID: {
const auto& wallClockIsoString = WallClockInstant.ToString();
ParsePgFromText(wallClockIsoString);
break;
}
case INT4OID:
case INT8OID: {
const auto instantValue = InstantValue(WallClockInstant, Unit);
if (!instantValue) {
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Unsupported unit: " << static_cast<ui32>(Unit));
CannotSerialize = true;
return Nothing();
}
const auto strInstant = ToString(*instantValue);
ParsePgFromText(strInstant);
break;
}
default:
CannotSerialize = true;
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, "Unsupported PG type");
}
return WallClockSerialized;
}

TMaybe<TString> GetWallClockSerialized() const {
if (WallClockSerialized) {
return WallClockSerialized;
Expand All @@ -54,53 +102,13 @@ class TExpirationCondition: public IEraseRowsCondition {
}

switch (Type.GetTypeId()) {
case NScheme::NTypeIds::DyNumber: {
const auto instantValue = InstantValue(WallClockInstant, Unit);
if (!instantValue) {
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Unsupported unit: " << static_cast<ui32>(Unit));
return Nothing();
}

const auto strInstant = ToString(*instantValue);
const auto wallClockDyNumber = NDyNumber::ParseDyNumberString(strInstant);
if (!wallClockDyNumber) {
CannotSerialize = true;
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Cannot parse DyNumber from: " << strInstant.Quote());
} else {
WallClockSerialized = *wallClockDyNumber;
}
break;
}
case NScheme::NTypeIds::Pg: {
switch (NPg::PgTypeIdFromTypeDesc(Type.GetPgTypeDesc())) {
case DATEOID:
case TIMESTAMPOID: {
const auto& wallClockIsoString = WallClockInstant.ToString();
ParsePgFromText(wallClockIsoString);
break;
}
case INT4OID:
case INT8OID: {
const auto instantValue = InstantValue(WallClockInstant, Unit);
if (!instantValue) {
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD,
"Unsupported unit: " << static_cast<ui32>(Unit));
return Nothing();
}
const auto strInstant = ToString(*instantValue);
ParsePgFromText(strInstant);
break;
}
default:
CannotSerialize = true;
LOG_CRIT_S(*TlsActivationContext, NKikimrServices::TX_DATASHARD, "Unsupported PG type");
}
break;
}
case NScheme::NTypeIds::DyNumber:
return GetWallClockDyNumber();
case NScheme::NTypeIds::Pg:
return GetWallClockPg();
default:
Y_ABORT("Unreachable");
}
return WallClockSerialized;
}

bool CheckUi64(ui64 value) const {
Expand Down Expand Up @@ -154,15 +162,15 @@ class TExpirationCondition: public IEraseRowsCondition {
}

bool CheckSerialized(TStringBuf value) const {
if (const auto& wallClockDSerialized = GetWallClockSerialized()) {
if (const auto& wallClockSerialized = GetWallClockSerialized()) {
switch (Type.GetTypeId()) {
// 'value since epoch' mode
case NScheme::NTypeIds::DyNumber:
return value <= *wallClockDSerialized;
return value <= *wallClockSerialized;
case NScheme::NTypeIds::Pg: {
int result = NPg::PgNativeBinaryCompare(
value.Data(), value.Size(),
wallClockDSerialized->Data(), wallClockDSerialized->Size(),
wallClockSerialized->Data(), wallClockSerialized->Size(),
Type.GetPgTypeDesc());
return result <= 0;
}
Expand Down

0 comments on commit d172930

Please sign in to comment.