summaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/config.cpp
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 /yt/cpp/mapreduce/interface/config.cpp
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
Diffstat (limited to 'yt/cpp/mapreduce/interface/config.cpp')
-rw-r--r--yt/cpp/mapreduce/interface/config.cpp89
1 files changed, 86 insertions, 3 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)