aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcoteeq <coteeq@yandex-team.com>2024-11-05 12:14:24 +0300
committercoteeq <coteeq@yandex-team.com>2024-11-05 12:52:25 +0300
commitbed766bef5787bd5bdbb0b73caab878b3c85f3eb (patch)
treed710c84eeff941d03633b7f54f4a4cc89e9321c0
parentc9443bc610787ad98408ed453356e7163f3c5cad (diff)
downloadydb-bed766bef5787bd5bdbb0b73caab878b3c85f3eb.tar.gz
[phoenix2] Do not serialize fields, whose InVersion filter does not match latest version
commit_hash:9f8f12afe3d5ab1d3d6d4cfb597ddf02b1a98d57
-rw-r--r--yt/yt/core/phoenix/type_def-inl.h20
-rw-r--r--yt/yt/core/phoenix/unittests/phoenix_ut.cpp17
2 files changed, 31 insertions, 6 deletions
diff --git a/yt/yt/core/phoenix/type_def-inl.h b/yt/yt/core/phoenix/type_def-inl.h
index f4614180c2..34112eaad5 100644
--- a/yt/yt/core/phoenix/type_def-inl.h
+++ b/yt/yt/core/phoenix/type_def-inl.h
@@ -131,6 +131,11 @@ struct TTraits
////////////////////////////////////////////////////////////////////////////////
+template <class TThis>
+using TVersionFilter = bool (*)(typename TTraits<TThis>::TVersion version);
+
+////////////////////////////////////////////////////////////////////////////////
+
#define PHOENIX_REGISTRAR_NODISCARD [[nodiscard("Did you forget to call operator()?")]]
class PHOENIX_REGISTRAR_NODISCARD TDummyFieldRegistrar
@@ -357,8 +362,9 @@ public:
return TFieldSaveRegistrar(std::move(*this));
}
- auto InVersions(auto /*filter*/) &&
+ auto InVersions(TVersionFilter<TThis> filter) &&
{
+ VersionFilter_ = filter;
return TFieldSaveRegistrar(std::move(*this));
}
@@ -375,7 +381,9 @@ public:
void operator()() &&
{
- TFieldSerializer::Save(Context_, This_->*Member);
+ if (!VersionFilter_ || VersionFilter_(Context_.GetVersion())) {
+ TFieldSerializer::Save(Context_, This_->*Member);
+ }
}
private:
@@ -384,6 +392,8 @@ private:
const TThis* const This_;
TContext& Context_;
+
+ TVersionFilter<TThis> VersionFilter_ = nullptr;
};
template <class TThis, class TContext>
@@ -556,9 +566,7 @@ public:
return TFieldLoadRegistrar(std::move(*this));
}
- using TVersionFilter = bool (*)(TVersion version);
-
- auto InVersions(TVersionFilter filter) &&
+ auto InVersions(TVersionFilter<TThis> filter) &&
{
VersionFilter_ = filter;
return TFieldLoadRegistrar(std::move(*this));
@@ -592,7 +600,7 @@ private:
const TStringBuf Name_;
TVersion MinVersion_ = static_cast<TVersion>(std::numeric_limits<int>::min());
- TVersionFilter VersionFilter_ = nullptr;
+ TVersionFilter<TThis> VersionFilter_ = nullptr;
TFieldMissingHandler<TThis, TContext> MissingHandler_ = nullptr;
};
diff --git a/yt/yt/core/phoenix/unittests/phoenix_ut.cpp b/yt/yt/core/phoenix/unittests/phoenix_ut.cpp
index a4297105ab..5fae7ef44c 100644
--- a/yt/yt/core/phoenix/unittests/phoenix_ut.cpp
+++ b/yt/yt/core/phoenix/unittests/phoenix_ut.cpp
@@ -447,6 +447,23 @@ TEST(TPhoenixTest, InVersion5)
EXPECT_EQ(s1, s3);
}
+TEST(TPhoenixTest, InVersionSave)
+{
+ using namespace NInVersions;
+
+ S s;
+ s.A = 123;
+ s.B = 0;
+ s.C = 777;
+
+ auto expected = MakeBuffer([] (auto& context) {
+ Save<int>(context, 123);
+ });
+
+ auto serialized = Serialize(s);
+ EXPECT_EQ(expected, serialized);
+}
+
////////////////////////////////////////////////////////////////////////////////
namespace NAfterLoad {