summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorachains <[email protected]>2025-09-23 15:38:31 +0300
committerachains <[email protected]>2025-09-23 16:23:09 +0300
commit6e3513d8ec0b4f82b63c04f808d553e798c3ec5f (patch)
treeb4ae4cb7333fc85a7e5685e7f3c6d613965406a7
parent13183af1efa6b08ffa7a942d1282ee35f66094f2 (diff)
YT-26145: Revert visible changes for config serialization
<Message NOT for release notes> * Changelog entry Type: fix Component: cpp-sdk Revert breaking public changes in header files commit_hash:e25a66243042b5961984505e6ecd67cb9f9f2635
-rw-r--r--yt/cpp/mapreduce/interface/config.cpp89
-rw-r--r--yt/cpp/mapreduce/interface/config.h26
-rw-r--r--yt/cpp/mapreduce/interface/serialize.cpp34
-rw-r--r--yt/cpp/mapreduce/interface/serialize.h40
4 files changed, 105 insertions, 84 deletions
diff --git a/yt/cpp/mapreduce/interface/config.cpp b/yt/cpp/mapreduce/interface/config.cpp
index f03af58c845..9ae1ddefce0 100644
--- a/yt/cpp/mapreduce/interface/config.cpp
+++ b/yt/cpp/mapreduce/interface/config.cpp
@@ -12,6 +12,9 @@
#include <library/cpp/yson/json/yson2json_adapter.h>
+#include <library/cpp/yt/misc/cast.h>
+
+#include <util/datetime/base.h>
#include <util/folder/dirut.h>
#include <util/folder/path.h>
#include <util/generic/singleton.h>
@@ -77,8 +80,8 @@ EUploadDeduplicationMode TConfig::GetUploadingDeduplicationMode(
const char* var,
EUploadDeduplicationMode defaultValue)
{
- const TString deduplicationMode = GetEnv(var, ::ToString(defaultValue));
- return ::FromString(deduplicationMode);
+ const TString deduplicationMode = GetEnv(var, TEnumTraits<EUploadDeduplicationMode>::ToString(defaultValue));
+ return TEnumTraits<EUploadDeduplicationMode>::FromString(deduplicationMode);
}
void TConfig::ValidateToken(const TString& token)
@@ -302,6 +305,85 @@ TConfigPtr TConfig::Get()
////////////////////////////////////////////////////////////////////////////////
+template <std::integral T>
+void Deserialize(T& value, const TNode& node)
+{
+ if (node.GetType() == TNode::EType::Int64) {
+ value = CheckedIntegralCast<T>(node.AsInt64());
+ } else if (node.GetType() == TNode::EType::Uint64) {
+ value = CheckedIntegralCast<T>(node.AsUint64());
+ } else {
+ throw yexception() << "Cannot parse integral value from node of type " << node.GetType();
+ }
+}
+
+template <typename T>
+void Deserialize(THashSet<T>& hs, const TNode& node)
+{
+ if (node.GetType() != TNode::EType::List) {
+ throw yexception() << "Cannot parse hashset from node of type " << node.GetType();
+ }
+ for (const auto& value : node.AsList()) {
+ T deserialized;
+ Deserialize(deserialized, value);
+ hs.insert(deserialized);
+ }
+}
+
+template <typename T>
+requires TEnumTraits<T>::IsEnum
+void Deserialize(T& value, const TNode& node)
+{
+ if (auto nodeType = node.GetType(); nodeType != TNode::EType::String) {
+ throw yexception() << "Enum deserialization expects EType::String, got " << node.GetType();
+ }
+ value = TEnumTraits<T>::FromString(node.AsString());
+}
+
+template <typename T>
+requires (!TEnumTraits<T>::IsEnum) && std::is_enum_v<T>
+void Deserialize(T& value, const TNode& node)
+{
+ if (auto nodeType = node.GetType(); nodeType != TNode::EType::String) {
+ throw yexception() << "Enum deserialization expects EType::String, got " << node.GetType();
+ }
+ value = ::FromString<T>(node.AsString());
+}
+
+void Deserialize(TDuration& value, const TNode& node)
+{
+ switch (node.GetType()) {
+ case TNode::EType::Int64: {
+ auto ms = node.AsInt64();
+ if (ms < 0) {
+ ythrow yexception() << "Duration cannot be negative";
+ }
+ value = TDuration::MilliSeconds(static_cast<ui64>(ms));
+ break;
+ }
+
+ case TNode::EType::Uint64:
+ value = TDuration::MilliSeconds(node.AsUint64());
+ break;
+
+ case TNode::EType::Double: {
+ auto ms = node.AsDouble();
+ if (ms < 0) {
+ ythrow yexception() << "Duration cannot be negative";
+ }
+ value = TDuration::MicroSeconds(static_cast<ui64>(ms * 1'000.0));
+ break;
+ }
+
+ case TNode::EType::String:
+ value = TDuration::Parse(node.AsString());
+ break;
+
+ default:
+ ythrow yexception() << "Cannot parse duration from " << node.GetType();
+ }
+}
+
// const auto& nodeMap = node.AsMap();
#define DESERIALIZE_ITEM(NAME, MEMBER) \
if (const auto* item = nodeMap.FindPtr(NAME)) { \
@@ -370,7 +452,8 @@ void Serialize(const TConfig& config, NYson::IYsonConsumer* consumer)
.Item("connection_pool_size").Value(config.ConnectionPoolSize)
.Item("file_cache_replication_factor").Value(config.FileCacheReplicationFactor)
.Item("cache_lock_timeout_per_gb").Value(config.CacheLockTimeoutPerGb.ToString())
- .Item("cache_upload_deduplication_mode").Value(::ToString(config.CacheUploadDeduplicationMode))
+ .Item("cache_upload_deduplication_mode")
+ .Value(TEnumTraits<EUploadDeduplicationMode>::ToString(config.CacheUploadDeduplicationMode))
.Item("cache_upload_deduplication_threshold").Value(config.CacheUploadDeduplicationThreshold)
.Item("mount_sandbox_in_tmpfs").Value(config.MountSandboxInTmpfs)
.Item("api_file_path_options").Value(config.ApiFilePathOptions)
diff --git a/yt/cpp/mapreduce/interface/config.h b/yt/cpp/mapreduce/interface/config.h
index c9f359b1d8b..82fe3f9da8c 100644
--- a/yt/cpp/mapreduce/interface/config.h
+++ b/yt/cpp/mapreduce/interface/config.h
@@ -8,7 +8,6 @@
#include <library/cpp/yt/yson_string/public.h>
#include <library/cpp/yson/node/node.h>
-#include <library/cpp/yson/node/serialize.h>
#include <util/generic/maybe.h>
#include <util/generic/string.h>
@@ -21,6 +20,20 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+namespace NYson {
+
+////////////////////////////////////////////////////////////////////////////////
+
+struct IYsonConsumer;
+
+enum class EYsonFormat : int;
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYson
+
+////////////////////////////////////////////////////////////////////////////////
+
namespace NLogLevel {
inline constexpr std::string_view Fatal = "fatal";
inline constexpr std::string_view Error = "error";
@@ -61,19 +74,18 @@ enum class ETraceHttpRequestsMode
Always /* "always" */,
};
-enum class EUploadDeduplicationMode : int
-{
+DEFINE_ENUM(EUploadDeduplicationMode,
// For each file only one process' thread from all possible hosts can upload it to the file cache at the same time.
// The others will wait for the uploading to finish and use already cached file.
- Global,
+ ((Global) (0))
// For each file and each particular host only one process' thread can upload it to the file cache at the same time.
// The others will wait for the uploading to finish and use already cached file.
- Host,
+ ((Host) (1))
// All processes' threads will upload a file to the cache concurrently.
- Disabled,
-};
+ ((Disabled) (2))
+);
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/cpp/mapreduce/interface/serialize.cpp b/yt/cpp/mapreduce/interface/serialize.cpp
index 869b39addb4..28a734a500b 100644
--- a/yt/cpp/mapreduce/interface/serialize.cpp
+++ b/yt/cpp/mapreduce/interface/serialize.cpp
@@ -572,40 +572,6 @@ void Deserialize(TTabletInfo& value, const TNode& node)
DESERIALIZE_ITEM("barrier_timestamp", value.BarrierTimestamp)
}
-void Deserialize(TDuration& value, const TNode& node)
-{
- switch (node.GetType()) {
- case TNode::EType::Int64: {
- auto ms = node.AsInt64();
- if (ms < 0) {
- ythrow yexception() << "Duration cannot be negative";
- }
- value = TDuration::MilliSeconds(static_cast<ui64>(ms));
- break;
- }
-
- case TNode::EType::Uint64:
- value = TDuration::MilliSeconds(node.AsUint64());
- break;
-
- case TNode::EType::Double: {
- auto ms = node.AsDouble();
- if (ms < 0) {
- ythrow yexception() << "Duration cannot be negative";
- }
- value = TDuration::MicroSeconds(static_cast<ui64>(ms * 1'000.0));
- break;
- }
-
- case TNode::EType::String:
- value = TDuration::Parse(node.AsString());
- break;
-
- default:
- ythrow yexception() << "Cannot parse duration from " << node.GetType();
- }
-}
-
void Serialize(const NTi::TTypePtr& type, NYson::IYsonConsumer* consumer)
{
auto yson = NTi::NIo::SerializeYson(type.Get());
diff --git a/yt/cpp/mapreduce/interface/serialize.h b/yt/cpp/mapreduce/interface/serialize.h
index 8ed94a178a1..6127b808c77 100644
--- a/yt/cpp/mapreduce/interface/serialize.h
+++ b/yt/cpp/mapreduce/interface/serialize.h
@@ -9,10 +9,6 @@
#include <library/cpp/yson/writer.h>
-#include <util/datetime/base.h>
-
-#include <library/cpp/yt/misc/cast.h>
-
#include <library/cpp/type_info/fwd.h>
namespace NYT::NYson {
@@ -84,7 +80,6 @@ void Deserialize(TTableColumnarStatistics& statistics, const TNode& node);
void Deserialize(TMultiTablePartition& partition, const TNode& node);
void Deserialize(TMultiTablePartitions& partitions, const TNode& node);
void Deserialize(TTabletInfo& tabletInfos, const TNode& node);
-void Deserialize(TDuration& duration, const TNode& node);
void Serialize(const TGUID& path, NYT::NYson::IYsonConsumer* consumer);
void Deserialize(TGUID& value, const TNode& node);
@@ -92,41 +87,6 @@ void Deserialize(TGUID& value, const TNode& node);
void Serialize(const NTi::TTypePtr& type, NYT::NYson::IYsonConsumer* consumer);
void Deserialize(NTi::TTypePtr& type, const TNode& node);
-template <std::integral T>
-void Deserialize(T& value, const TNode& node)
-{
- if (node.GetType() == TNode::EType::Int64) {
- value = CheckedIntegralCast<T>(node.AsInt64());
- } else if (node.GetType() == TNode::EType::Uint64) {
- value = CheckedIntegralCast<T>(node.AsUint64());
- } else {
- throw yexception() << "Cannot parse integral value from node of type " << node.GetType();
- }
-}
-
-template <typename T>
-void Deserialize(THashSet<T>& hs, const TNode& node)
-{
- if (node.GetType() != TNode::EType::List) {
- throw yexception() << "Cannot parse hashset from node of type " << node.GetType();
- }
- for (const auto& value : node.AsList()) {
- T deserialized;
- Deserialize(deserialized, value);
- hs.insert(deserialized);
- }
-}
-
-template <typename T>
-requires std::is_enum_v<T>
-void Deserialize(T& value, const TNode& node)
-{
- if (auto nodeType = node.GetType(); nodeType != TNode::EType::String) {
- throw yexception() << "Enum deserialization expects EType::String, got " << node.GetType();
- }
- value = ::FromString<T>(node.AsString());
-}
-
template <typename T>
TString ToYsonText(const T& value)
{