Skip to content

Commit a569234

Browse files
author
ignat
committed
YT-22751: Extract BigRT-style proto configs to ads/bsyeti/libs/ytex/client/
\[nodiff:caesar\] e25f12b34361bc76958c1b795c2adcd00bc4c443
1 parent fe92253 commit a569234

33 files changed

+367
-563
lines changed

yt/yt/client/cache/cache.cpp

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,71 @@
11
#include "cache_base.h"
22
#include "rpc.h"
3+
#include "config.h"
34

45
#include <yt/yt/client/api/options.h>
56

67
#include <yt/yt/core/net/address.h>
78

8-
#include <yt/yt_proto/yt/client/cache/proto/config.pb.h>
9-
109
#include <util/stream/str.h>
1110

1211
namespace NYT::NClient::NCache {
12+
13+
using namespace NNet;
14+
using NApi::NRpcProxy::TConnectionConfig;
15+
using NApi::NRpcProxy::TConnectionConfigPtr;
16+
1317
namespace {
1418

1519
////////////////////////////////////////////////////////////////////////////////
1620

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+
1733
TStringBuf GetNormalClusterName(TStringBuf clusterName)
1834
{
1935
return NNet::InferYTClusterFromClusterUrlRaw(clusterName).value_or(clusterName);
2036
}
2137

22-
TClustersConfig GetClustersConfigWithNormalClusterName(const TClustersConfig& config)
38+
// TODO(ignat): move this logic to ads/bsyeti/libs/ytex/client/
39+
TClientsCacheConfigPtr GetClustersConfigWithNormalClusterName(const TClientsCacheConfigPtr& config)
2340
{
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);
2846
}
2947
return newConfig;
3048
}
3149

50+
////////////////////////////////////////////////////////////////////////////////
51+
3252
} // namespace
3353

34-
TConfig MakeClusterConfig(
35-
const TClustersConfig& clustersConfig,
54+
TConnectionConfigPtr MakeClusterConfig(
55+
const TClientsCacheConfigPtr& clustersConfig,
3656
TStringBuf clusterUrl)
3757
{
3858
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);
4265
if (!proxyRole.empty()) {
43-
config.SetProxyRole(ToString(proxyRole));
66+
newConfig->ProxyRole = ToString(proxyRole);
4467
}
45-
return config;
68+
return newConfig;
4669
}
4770

4871
////////////////////////////////////////////////////////////////////////////////
@@ -55,7 +78,7 @@ class TClientsCache
5578
: public TClientsCacheBase
5679
{
5780
public:
58-
TClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options)
81+
TClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options)
5982
: ClustersConfig_(GetClustersConfigWithNormalClusterName(config))
6083
, Options_(options)
6184
{ }
@@ -67,7 +90,7 @@ class TClientsCache
6790
}
6891

6992
private:
70-
const TClustersConfig ClustersConfig_;
93+
const TClientsCacheConfigPtr ClustersConfig_;
7194
const NApi::TClientOptions Options_;
7295
};
7396

@@ -77,26 +100,30 @@ class TClientsCache
77100

78101
////////////////////////////////////////////////////////////////////////////////
79102

80-
IClientsCachePtr CreateClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options)
103+
IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options)
81104
{
82105
return New<TClientsCache>(config, options);
83106
}
84107

85-
IClientsCachePtr CreateClientsCache(const TConfig& config, const NApi::TClientOptions& options)
108+
IClientsCachePtr CreateClientsCache(
109+
const TConnectionConfigPtr& config,
110+
const NApi::TClientOptions& options)
86111
{
87-
TClustersConfig clustersConfig;
88-
*clustersConfig.MutableDefaultConfig() = config;
112+
auto clustersConfig = New<TClientsCacheConfig>();
113+
clustersConfig->DefaultConfig = CopyConfig(config);
89114
return CreateClientsCache(clustersConfig, options);
90115
}
91116

92-
IClientsCachePtr CreateClientsCache(const TConfig& config)
117+
IClientsCachePtr CreateClientsCache(const TConnectionConfigPtr& config)
93118
{
94119
return CreateClientsCache(config, NApi::GetClientOpsFromEnvStatic());
95120
}
96121

97122
IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options)
98123
{
99-
return CreateClientsCache(TClustersConfig(), options);
124+
auto config = New<TClientsCacheConfig>();
125+
config->SetDefaults();
126+
return CreateClientsCache(config, options);
100127
}
101128

102129
IClientsCachePtr CreateClientsCache()

yt/yt/client/cache/cache.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ DEFINE_REFCOUNTED_TYPE(IClientsCache)
2424
////////////////////////////////////////////////////////////////////////////////
2525

2626
//! Creates clients cache which explicitly given config. Server name is always overwritten with requested.
27-
IClientsCachePtr CreateClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options);
27+
IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options);
2828

2929
//! Creates clients cache which shares same config (except server name).
30-
IClientsCachePtr CreateClientsCache(const TConfig& config, const NApi::TClientOptions& options);
30+
IClientsCachePtr CreateClientsCache(
31+
const NApi::NRpcProxy::TConnectionConfigPtr& config,
32+
const NApi::TClientOptions& options);
3133

3234
//! Shortcut to use client options from env.
33-
IClientsCachePtr CreateClientsCache(const TConfig& config);
35+
IClientsCachePtr CreateClientsCache(const NApi::NRpcProxy::TConnectionConfigPtr& config);
3436

3537
//! Shortcut to create cache with custom options and proxy role.
3638
IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options);
@@ -39,7 +41,7 @@ IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options);
3941
IClientsCachePtr CreateClientsCache();
4042

4143
//! Helper function to create one cluster config from cluster URL and clusters config.
42-
TConfig MakeClusterConfig(const TClustersConfig& config, TStringBuf clusterUrl);
44+
NApi::NRpcProxy::TConnectionConfigPtr MakeClusterConfig(const TClientsCacheConfigPtr& config, TStringBuf clusterUrl);
4345

4446
////////////////////////////////////////////////////////////////////////////////
4547

yt/yt/client/cache/config.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "config.h"
2+
3+
namespace NYT::NClient::NCache {
4+
5+
////////////////////////////////////////////////////////////////////////////////
6+
7+
void TClientsCacheConfig::Register(TRegistrar registrar)
8+
{
9+
registrar.Parameter("default_config", &TThis::DefaultConfig)
10+
.DefaultNew();
11+
registrar.Parameter("cluster_configs", &TThis::ClusterConfigs)
12+
.Default();
13+
}
14+
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
} // namespace NYT::NClient::NHedging::NRpc

yt/yt/client/cache/config.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include "public.h"
4+
5+
#include <yt/yt/client/api/rpc_proxy/config.h>
6+
7+
#include <yt/yt/core/ytree/yson_struct.h>
8+
9+
#include <util/generic/vector.h>
10+
11+
namespace NYT::NClient::NCache {
12+
13+
////////////////////////////////////////////////////////////////////////////////
14+
15+
struct TClientsCacheConfig
16+
: public virtual NYTree::TYsonStruct
17+
{
18+
NApi::NRpcProxy::TConnectionConfigPtr DefaultConfig;
19+
20+
THashMap<TString, NApi::NRpcProxy::TConnectionConfigPtr> ClusterConfigs;
21+
22+
REGISTER_YSON_STRUCT(TClientsCacheConfig);
23+
24+
static void Register(TRegistrar registrar);
25+
};
26+
27+
DEFINE_REFCOUNTED_TYPE(TClientsCacheConfig)
28+
29+
////////////////////////////////////////////////////////////////////////////////
30+
31+
} // namespace NYT::NClient::NHedging::NRpc

yt/yt/client/cache/public.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace NYT::NClient::NCache {
77
////////////////////////////////////////////////////////////////////////////////
88

99
DECLARE_REFCOUNTED_STRUCT(IClientsCache)
10-
11-
class TConfig;
12-
class TClustersConfig;
10+
DECLARE_REFCOUNTED_STRUCT(TClientsCacheConfig)
1311

1412
////////////////////////////////////////////////////////////////////////////////
1513

0 commit comments

Comments
 (0)