1
1
#include " cache_base.h"
2
2
#include " rpc.h"
3
+ #include " config.h"
3
4
4
5
#include < yt/yt/client/api/options.h>
5
6
6
7
#include < yt/yt/core/net/address.h>
7
8
8
- #include < yt/yt_proto/yt/client/cache/proto/config.pb.h>
9
-
10
9
#include < util/stream/str.h>
11
10
12
11
namespace NYT ::NClient::NCache {
12
+
13
+ using namespace NNet ;
14
+ using NApi::NRpcProxy::TConnectionConfig;
15
+ using NApi::NRpcProxy::TConnectionConfigPtr;
16
+
13
17
namespace {
14
18
15
19
// //////////////////////////////////////////////////////////////////////////////
16
20
21
+ template <class T >
22
+ TIntrusivePtr<T> CopyConfig (const TIntrusivePtr<T>& config)
23
+ {
24
+ auto newConfig = New<T>();
25
+ newConfig->Load (
26
+ ConvertToNode (config),
27
+ /* postprocess*/ false ,
28
+ /* setDefaults*/ false ,
29
+ /* path*/ " " );
30
+ return newConfig;
31
+ }
32
+
17
33
TStringBuf GetNormalClusterName (TStringBuf clusterName)
18
34
{
19
35
return NNet::InferYTClusterFromClusterUrlRaw (clusterName).value_or (clusterName);
20
36
}
21
37
22
- TClustersConfig GetClustersConfigWithNormalClusterName (const TClustersConfig& config)
38
+ // TODO(ignat): move this logic to ads/bsyeti/libs/ytex/client/
39
+ TClientsCacheConfigPtr GetClustersConfigWithNormalClusterName (const TClientsCacheConfigPtr& config)
23
40
{
24
- TClustersConfig newConfig (config);
25
- newConfig.ClearClusterConfigs ();
26
- for (auto & [clusterName, clusterConfig] : config.GetClusterConfigs ()) {
27
- (*newConfig.MutableClusterConfigs ())[ToString (GetNormalClusterName (clusterName))] = clusterConfig;
41
+ auto newConfig = New<TClientsCacheConfig>();
42
+
43
+ newConfig->DefaultConfig = CopyConfig (config->DefaultConfig );
44
+ for (const auto & [clusterName, clusterConfig] : config->ClusterConfigs ) {
45
+ newConfig->ClusterConfigs [ToString (GetNormalClusterName (clusterName))] = CopyConfig (clusterConfig);
28
46
}
29
47
return newConfig;
30
48
}
31
49
50
+ // //////////////////////////////////////////////////////////////////////////////
51
+
32
52
} // namespace
33
53
34
- TConfig MakeClusterConfig (
35
- const TClustersConfig & clustersConfig,
54
+ TConnectionConfigPtr MakeClusterConfig (
55
+ const TClientsCacheConfigPtr & clustersConfig,
36
56
TStringBuf clusterUrl)
37
57
{
38
58
auto [cluster, proxyRole] = ExtractClusterAndProxyRole (clusterUrl);
39
- auto it = clustersConfig.GetClusterConfigs ().find (GetNormalClusterName (cluster));
40
- auto config = (it != clustersConfig.GetClusterConfigs ().end ()) ? it->second : clustersConfig.GetDefaultConfig ();
41
- config.SetClusterName (ToString (cluster));
59
+ auto it = clustersConfig->ClusterConfigs .find (GetNormalClusterName (cluster));
60
+ auto config = (it != clustersConfig->ClusterConfigs .end ()) ? it->second : clustersConfig->DefaultConfig ;
61
+
62
+ auto newConfig = CopyConfig (config);
63
+ newConfig->ClusterUrl = ToString (cluster);
64
+ newConfig->ClusterName = InferYTClusterFromClusterUrl (*newConfig->ClusterUrl );
42
65
if (!proxyRole.empty ()) {
43
- config. SetProxyRole ( ToString (proxyRole) );
66
+ newConfig-> ProxyRole = ToString (proxyRole);
44
67
}
45
- return config ;
68
+ return newConfig ;
46
69
}
47
70
48
71
// //////////////////////////////////////////////////////////////////////////////
@@ -55,7 +78,7 @@ class TClientsCache
55
78
: public TClientsCacheBase
56
79
{
57
80
public:
58
- TClientsCache (const TClustersConfig & config, const NApi::TClientOptions& options)
81
+ TClientsCache (const TClientsCacheConfigPtr & config, const NApi::TClientOptions& options)
59
82
: ClustersConfig_(GetClustersConfigWithNormalClusterName(config))
60
83
, Options_(options)
61
84
{ }
@@ -67,7 +90,7 @@ class TClientsCache
67
90
}
68
91
69
92
private:
70
- const TClustersConfig ClustersConfig_;
93
+ const TClientsCacheConfigPtr ClustersConfig_;
71
94
const NApi::TClientOptions Options_;
72
95
};
73
96
@@ -77,26 +100,30 @@ class TClientsCache
77
100
78
101
// //////////////////////////////////////////////////////////////////////////////
79
102
80
- IClientsCachePtr CreateClientsCache (const TClustersConfig & config, const NApi::TClientOptions& options)
103
+ IClientsCachePtr CreateClientsCache (const TClientsCacheConfigPtr & config, const NApi::TClientOptions& options)
81
104
{
82
105
return New<TClientsCache>(config, options);
83
106
}
84
107
85
- IClientsCachePtr CreateClientsCache (const TConfig& config, const NApi::TClientOptions& options)
108
+ IClientsCachePtr CreateClientsCache (
109
+ const TConnectionConfigPtr& config,
110
+ const NApi::TClientOptions& options)
86
111
{
87
- TClustersConfig clustersConfig;
88
- * clustersConfig. MutableDefaultConfig () = config;
112
+ auto clustersConfig = New<TClientsCacheConfig>() ;
113
+ clustersConfig-> DefaultConfig = CopyConfig ( config) ;
89
114
return CreateClientsCache (clustersConfig, options);
90
115
}
91
116
92
- IClientsCachePtr CreateClientsCache (const TConfig & config)
117
+ IClientsCachePtr CreateClientsCache (const TConnectionConfigPtr & config)
93
118
{
94
119
return CreateClientsCache (config, NApi::GetClientOpsFromEnvStatic ());
95
120
}
96
121
97
122
IClientsCachePtr CreateClientsCache (const NApi::TClientOptions& options)
98
123
{
99
- return CreateClientsCache (TClustersConfig (), options);
124
+ auto config = New<TClientsCacheConfig>();
125
+ config->SetDefaults ();
126
+ return CreateClientsCache (config, options);
100
127
}
101
128
102
129
IClientsCachePtr CreateClientsCache ()
0 commit comments