aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorignat <ignat@yandex-team.com>2024-09-05 17:46:31 +0300
committerignat <ignat@yandex-team.com>2024-09-05 18:06:30 +0300
commitdb4754b956955532cb1ad5fd119d5d199b790a0e (patch)
tree809528026b15b3ca5c44d957091217c92b3ede26
parente499a26b5883717ac50c8aaf568fcbcf696b64a8 (diff)
downloadydb-db4754b956955532cb1ad5fd119d5d199b790a0e.tar.gz
YT-22751: Drop custom CopyConfig methods
f5788694973061a735a7b65e45abe9ce6d889a87
-rw-r--r--yt/yt/client/cache/cache.cpp21
-rw-r--r--yt/yt/client/federated/cache.cpp17
-rw-r--r--yt/yt/core/ytree/yson_struct-inl.h15
-rw-r--r--yt/yt/core/ytree/yson_struct.h4
4 files changed, 19 insertions, 38 deletions
diff --git a/yt/yt/client/cache/cache.cpp b/yt/yt/client/cache/cache.cpp
index 4ff7559032..95a7386103 100644
--- a/yt/yt/client/cache/cache.cpp
+++ b/yt/yt/client/cache/cache.cpp
@@ -18,18 +18,6 @@ namespace {
////////////////////////////////////////////////////////////////////////////////
-template<class T>
-TIntrusivePtr<T> CopyConfig(const TIntrusivePtr<T>& config)
-{
- auto newConfig = New<T>();
- newConfig->Load(
- ConvertToNode(config),
- /*postprocess*/ false,
- /*setDefaults*/ false,
- /*path*/ "");
- return newConfig;
-}
-
TStringBuf GetNormalClusterName(TStringBuf clusterName)
{
return NNet::InferYTClusterFromClusterUrlRaw(clusterName).value_or(clusterName);
@@ -40,9 +28,10 @@ TClientsCacheConfigPtr GetClustersConfigWithNormalClusterName(const TClientsCach
{
auto newConfig = New<TClientsCacheConfig>();
- newConfig->DefaultConfig = CopyConfig(config->DefaultConfig);
+ newConfig->DefaultConfig = CloneYsonStruct(config->DefaultConfig, /*postprocess*/ false, /*setDefaults*/ false);
for (const auto& [clusterName, clusterConfig] : config->ClusterConfigs) {
- newConfig->ClusterConfigs[ToString(GetNormalClusterName(clusterName))] = CopyConfig(clusterConfig);
+ newConfig->ClusterConfigs[ToString(GetNormalClusterName(clusterName))] =
+ CloneYsonStruct(clusterConfig, /*postprocess*/ false, /*setDefaults*/ false);
}
return newConfig;
}
@@ -59,7 +48,7 @@ TConnectionConfigPtr MakeClusterConfig(
auto it = clustersConfig->ClusterConfigs.find(GetNormalClusterName(cluster));
auto config = (it != clustersConfig->ClusterConfigs.end()) ? it->second : clustersConfig->DefaultConfig;
- auto newConfig = CopyConfig(config);
+ auto newConfig = CloneYsonStruct(config, /*postprocess*/ false, /*setDefaults*/ false);
newConfig->ClusterUrl = ToString(cluster);
newConfig->ClusterName = InferYTClusterFromClusterUrl(*newConfig->ClusterUrl);
if (!proxyRole.empty()) {
@@ -110,7 +99,7 @@ IClientsCachePtr CreateClientsCache(
const NApi::TClientOptions& options)
{
auto clustersConfig = New<TClientsCacheConfig>();
- clustersConfig->DefaultConfig = CopyConfig(config);
+ clustersConfig->DefaultConfig = CloneYsonStruct(config, /*postprocess*/ false, /*setDefaults*/ false);
return CreateClientsCache(clustersConfig, options);
}
diff --git a/yt/yt/client/federated/cache.cpp b/yt/yt/client/federated/cache.cpp
index 1cf3347b84..f04e99a2ad 100644
--- a/yt/yt/client/federated/cache.cpp
+++ b/yt/yt/client/federated/cache.cpp
@@ -16,21 +16,6 @@ namespace {
////////////////////////////////////////////////////////////////////////////////
-// TODO(ignat): move this function to yt/yt/core/
-template<class T>
-TIntrusivePtr<T> CopyConfig(const TIntrusivePtr<T>& config)
-{
- auto newConfig = New<T>();
- newConfig->Load(
- ConvertToNode(config),
- /*postprocess*/ false,
- /*setDefaults*/ false,
- /*path*/ "");
- return newConfig;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
class TClientsCache
: public NCache::TClientsCacheBase
{
@@ -124,7 +109,7 @@ IClientsCachePtr CreateFederatedClientsCache(
TString clusterSeparator)
{
auto clientsCacheConfig = New<TClientsCacheConfig>();
- clientsCacheConfig->DefaultConfig = CopyConfig(cacheConfig);
+ clientsCacheConfig->DefaultConfig = CloneYsonStruct(cacheConfig, /*postprocess*/ false, /*setDefaults*/ false);
return NYT::New<TClientsCache>(
std::move(clientsCacheConfig),
diff --git a/yt/yt/core/ytree/yson_struct-inl.h b/yt/yt/core/ytree/yson_struct-inl.h
index cb1cb90562..ccb68c0910 100644
--- a/yt/yt/core/ytree/yson_struct-inl.h
+++ b/yt/yt/core/ytree/yson_struct-inl.h
@@ -282,18 +282,25 @@ void Deserialize(T& value, TSource source, bool postprocess, bool setDefaults)
}
template <class T>
-TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<const T>& obj)
+TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<const T>& obj, bool postprocess, bool setDefaults)
{
if (!obj) {
return nullptr;
}
- return ConvertTo<TIntrusivePtr<T>>(NYson::ConvertToYsonString(*obj));
+ if constexpr(std::derived_from<T, TYsonStructBase>) {
+ auto node = ConvertToNode(NYson::ConvertToYsonString(*obj));
+ auto cloneObj = New<T>();
+ cloneObj->Load(node, postprocess, setDefaults);
+ return cloneObj;
+ } else {
+ return ConvertTo<TIntrusivePtr<T>>(NYson::ConvertToYsonString(*obj));
+ }
}
template <class T>
-TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<T>& obj)
+TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<T>& obj, bool postprocess, bool setDefaults)
{
- return CloneYsonStruct(ConstPointerCast<const T>(obj));
+ return CloneYsonStruct(ConstPointerCast<const T>(obj), postprocess, setDefaults);
}
template <class T>
diff --git a/yt/yt/core/ytree/yson_struct.h b/yt/yt/core/ytree/yson_struct.h
index e0f9b81346..d90ca75efc 100644
--- a/yt/yt/core/ytree/yson_struct.h
+++ b/yt/yt/core/ytree/yson_struct.h
@@ -326,9 +326,9 @@ private:
////////////////////////////////////////////////////////////////////////////////
template <class T>
-TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<const T>& obj);
+TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<const T>& obj, bool postprocess = true, bool setDefaults = true);
template <class T>
-TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<T>& obj);
+TIntrusivePtr<T> CloneYsonStruct(const TIntrusivePtr<T>& obj, bool postprocess = true, bool setDefaults = true);
template <class T>
std::vector<TIntrusivePtr<T>> CloneYsonStructs(const std::vector<TIntrusivePtr<T>>& objs);
template <class T>