aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-08-25 13:11:45 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-08-25 13:43:44 +0300
commit03b54fe9cee65c8b7f2a74c9a5524f35980da866 (patch)
tree8eead14f2e43d15925985b29df0c584541a186ce
parent57c8576159f9581fc3a77718dfc7ca7e89e8636b (diff)
downloadydb-03b54fe9cee65c8b7f2a74c9a5524f35980da866.tar.gz
Intermediate changes
-rw-r--r--yt/yt/client/cache/cache.cpp (renamed from yt/yt/client/hedging/cache.cpp)43
-rw-r--r--yt/yt/client/cache/cache.h52
-rw-r--r--yt/yt/client/cache/cache_base.cpp25
-rw-r--r--yt/yt/client/cache/cache_base.h27
-rw-r--r--yt/yt/client/cache/options.cpp (renamed from yt/yt/client/hedging/options.cpp)4
-rw-r--r--yt/yt/client/cache/options.h (renamed from yt/yt/client/hedging/options.h)4
-rw-r--r--yt/yt/client/cache/public.h13
-rw-r--r--yt/yt/client/cache/rpc.cpp (renamed from yt/yt/client/hedging/rpc.cpp)6
-rw-r--r--yt/yt/client/cache/rpc.h50
-rw-r--r--yt/yt/client/cache/ya.make20
-rw-r--r--yt/yt/client/hedging/cache.h56
-rw-r--r--yt/yt/client/hedging/hedging.h4
-rw-r--r--yt/yt/client/hedging/public.h5
-rw-r--r--yt/yt/client/hedging/rpc.h55
-rw-r--r--yt/yt/client/hedging/unittests/cache_ut.cpp110
-rw-r--r--yt/yt/client/hedging/unittests/options_ut.cpp83
-rw-r--r--yt/yt/client/hedging/unittests/rpc_ut.cpp35
-rw-r--r--yt/yt/client/hedging/unittests/ya.make3
-rw-r--r--yt/yt/client/hedging/ya.make4
19 files changed, 234 insertions, 365 deletions
diff --git a/yt/yt/client/hedging/cache.cpp b/yt/yt/client/cache/cache.cpp
index cf725dbf1f..b9198841e5 100644
--- a/yt/yt/client/hedging/cache.cpp
+++ b/yt/yt/client/cache/cache.cpp
@@ -1,12 +1,12 @@
-#include "cache.h"
+#include "cache_base.h"
#include "options.h"
#include "rpc.h"
-#include <yt/yt_proto/yt/client/hedging/proto/config.pb.h>
+#include <yt/yt_proto/yt/client/cache/proto/config.pb.h>
-#include <library/cpp/yt/threading/rw_spin_lock.h>
+#include <util/stream/str.h>
-namespace NYT::NClient::NHedging::NRpc {
+namespace NYT::NClient::NCache {
////////////////////////////////////////////////////////////////////////////////
@@ -14,8 +14,7 @@ TConfig MakeClusterConfig(const TClustersConfig& clustersConfig, TStringBuf clus
{
auto [cluster, proxyRole] = ExtractClusterAndProxyRole(clusterUrl);
auto it = clustersConfig.GetClusterConfigs().find(cluster);
- TConfig config = (it != clustersConfig.GetClusterConfigs().end()) ?
- it->second : clustersConfig.GetDefaultConfig();
+ TConfig config = (it != clustersConfig.GetClusterConfigs().end()) ? it->second : clustersConfig.GetDefaultConfig();
config.SetClusterName(ToString(cluster));
if (!proxyRole.empty()) {
config.SetProxyRole(ToString(proxyRole));
@@ -23,10 +22,14 @@ TConfig MakeClusterConfig(const TClustersConfig& clustersConfig, TStringBuf clus
return config;
}
+////////////////////////////////////////////////////////////////////////////////
+
namespace {
+////////////////////////////////////////////////////////////////////////////////
+
class TClientsCache
- : public IClientsCache
+ : public TClientsCacheBase
{
public:
TClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options)
@@ -34,29 +37,19 @@ public:
, Options_(options)
{}
- NApi::IClientPtr GetClient(TStringBuf clusterUrl) override
+protected:
+ NApi::IClientPtr CreateClient(TStringBuf clusterUrl) override
{
- {
- auto guard = ReaderGuard(Lock_);
- auto clientIt = Clients_.find(clusterUrl);
- if (clientIt != Clients_.end()) {
- return clientIt->second;
- }
- }
-
- auto client = CreateClient(MakeClusterConfig(ClustersConfig_, clusterUrl), Options_);
-
- auto guard = WriterGuard(Lock_);
- return Clients_.try_emplace(clusterUrl, client).first->second;
+ return NCache::CreateClient(MakeClusterConfig(ClustersConfig_, clusterUrl), Options_);
}
private:
- TClustersConfig ClustersConfig_;
- NApi::TClientOptions Options_;
- NThreading::TReaderWriterSpinLock Lock_;
- THashMap<TString, NApi::IClientPtr> Clients_;
+ const TClustersConfig ClustersConfig_;
+ const NApi::TClientOptions Options_;
};
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -90,4 +83,4 @@ IClientsCachePtr CreateClientsCache()
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT::NClient::NHedging::NRpc
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/cache.h b/yt/yt/client/cache/cache.h
new file mode 100644
index 0000000000..260ac20efc
--- /dev/null
+++ b/yt/yt/client/cache/cache.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <yt/yt/client/api/public.h>
+#include <yt/yt/client/api/rpc_proxy/config.h>
+#include <yt/yt/client/api/rpc_proxy/connection.h>
+
+#include <util/generic/strbuf.h>
+
+namespace NYT::NClient::NCache {
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TConfig;
+class TClustersConfig;
+
+////////////////////////////////////////////////////////////////////////////////
+
+//! Cache of clients per cluster.
+class IClientsCache
+ : public TRefCounted
+{
+public:
+ virtual NApi::IClientPtr GetClient(TStringBuf clusterUrl) = 0;
+};
+
+DECLARE_REFCOUNTED_TYPE(IClientsCache)
+DEFINE_REFCOUNTED_TYPE(IClientsCache)
+
+////////////////////////////////////////////////////////////////////////////////
+
+//! Creates clients cache which explicitly given config. Server name is always overwritten with requested.
+IClientsCachePtr CreateClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options);
+
+//! Creates clients cache which shares same config (except server name).
+IClientsCachePtr CreateClientsCache(const TConfig& config, const NApi::TClientOptions& options);
+
+//! Shortcut to use client options from env.
+IClientsCachePtr CreateClientsCache(const TConfig& config);
+
+//! Shortcut to create cache with custom options and proxy role.
+IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options);
+
+//! Shortcut to create cache with default config.
+IClientsCachePtr CreateClientsCache();
+
+
+//! Helper function to create one cluster config from cluster url and clusters config
+TConfig MakeClusterConfig(const TClustersConfig& config, TStringBuf clusterUrl);
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/cache_base.cpp b/yt/yt/client/cache/cache_base.cpp
new file mode 100644
index 0000000000..ea8833b592
--- /dev/null
+++ b/yt/yt/client/cache/cache_base.cpp
@@ -0,0 +1,25 @@
+#include "cache_base.h"
+
+namespace NYT::NClient::NCache {
+
+////////////////////////////////////////////////////////////////////////////////
+
+NApi::IClientPtr TClientsCacheBase::GetClient(TStringBuf clusterUrl)
+{
+ {
+ auto guard = ReaderGuard(Lock_);
+ auto clientIt = Clients_.find(clusterUrl);
+ if (clientIt != Clients_.end()) {
+ return clientIt->second;
+ }
+ }
+
+ auto client = CreateClient(clusterUrl);
+
+ auto guard = WriterGuard(Lock_);
+ return Clients_.try_emplace(clusterUrl, client).first->second;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/cache_base.h b/yt/yt/client/cache/cache_base.h
new file mode 100644
index 0000000000..309b15ace8
--- /dev/null
+++ b/yt/yt/client/cache/cache_base.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "cache.h"
+
+#include <library/cpp/yt/threading/rw_spin_lock.h>
+
+namespace NYT::NClient::NCache {
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TClientsCacheBase
+ : public IClientsCache
+{
+public:
+ NApi::IClientPtr GetClient(TStringBuf clusterUrl) override;
+
+protected:
+ virtual NApi::IClientPtr CreateClient(TStringBuf clusterUrl) = 0;
+
+private:
+ YT_DECLARE_SPIN_LOCK(NThreading::TReaderWriterSpinLock, Lock_);
+ THashMap<TString, NApi::IClientPtr> Clients_;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/hedging/options.cpp b/yt/yt/client/cache/options.cpp
index f2f7cb772d..6eeaee7209 100644
--- a/yt/yt/client/hedging/options.cpp
+++ b/yt/yt/client/cache/options.cpp
@@ -8,7 +8,7 @@
#include <util/system/env.h>
-namespace NYT::NClient::NHedging {
+namespace NYT::NClient::NCache {
////////////////////////////////////////////////////////////////////////////////
@@ -45,4 +45,4 @@ const NApi::TClientOptions& GetClientOpsFromEnvStatic()
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT::NClient::NHedging
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/hedging/options.h b/yt/yt/client/cache/options.h
index a80d378792..a30784d49a 100644
--- a/yt/yt/client/hedging/options.h
+++ b/yt/yt/client/cache/options.h
@@ -2,7 +2,7 @@
#include <yt/yt/client/api/connection.h>
-namespace NYT::NClient::NHedging {
+namespace NYT::NClient::NCache {
////////////////////////////////////////////////////////////////////////////////
@@ -16,4 +16,4 @@ const NApi::TClientOptions& GetClientOpsFromEnvStatic();
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT::NClient::NHedging
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/public.h b/yt/yt/client/cache/public.h
new file mode 100644
index 0000000000..2739b01aaa
--- /dev/null
+++ b/yt/yt/client/cache/public.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <yt/yt/client/api/public.h>
+
+namespace NYT::NClient::NCache {
+
+////////////////////////////////////////////////////////////////////////////////
+
+DECLARE_REFCOUNTED_CLASS(IClientsCache)
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/hedging/rpc.cpp b/yt/yt/client/cache/rpc.cpp
index 1aad3dc908..4557ea044a 100644
--- a/yt/yt/client/hedging/rpc.cpp
+++ b/yt/yt/client/cache/rpc.cpp
@@ -1,7 +1,7 @@
#include "rpc.h"
#include "options.h"
-#include <yt/yt_proto/yt/client/hedging/proto/config.pb.h>
+#include <yt/yt_proto/yt/client/cache/proto/config.pb.h>
#include <yt/yt/client/api/client.h>
@@ -12,7 +12,7 @@
#include <util/system/env.h>
-namespace NYT::NClient::NHedging::NRpc {
+namespace NYT::NClient::NCache {
NCompression::ECodec GetResponseCodecFromProto(const ECompressionCodec& protoCodec)
{
@@ -153,4 +153,4 @@ NApi::IClientPtr CreateClient(TStringBuf clusterUrl, const NApi::TClientOptions&
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT::NClient::NHedging::NRpc
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/rpc.h b/yt/yt/client/cache/rpc.h
new file mode 100644
index 0000000000..9916b5d7c1
--- /dev/null
+++ b/yt/yt/client/cache/rpc.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <yt/yt/client/api/public.h>
+#include <yt/yt/client/api/rpc_proxy/config.h>
+
+#include <yt/yt_proto/yt/client/cache/proto/config.pb.h>
+
+#include <util/generic/strbuf.h>
+
+
+namespace NYT::NClient::NCache {
+
+////////////////////////////////////////////////////////////////////////////////
+
+NApi::NRpcProxy::TConnectionConfigPtr GetConnectionConfig(const TConfig& config);
+
+////////////////////////////////////////////////////////////////////////////////
+
+//! Helper function to extract ClusterName and ProxyRole from clusterUrl.
+std::pair<TStringBuf, TStringBuf> ExtractClusterAndProxyRole(TStringBuf clusterUrl);
+
+//! Helper function to properly set ClusterName and ProxyRole from clusterUrl.
+// Expected that clusterUrl will be in format cluster[/proxyRole].
+void SetClusterUrl(const NApi::NRpcProxy::TConnectionConfigPtr& config, TStringBuf clusterUrl);
+void SetClusterUrl(TConfig& config, TStringBuf clusterUrl);
+
+NApi::IClientPtr CreateClient(const NApi::NRpcProxy::TConnectionConfigPtr& config, const NApi::TClientOptions& options);
+NApi::IClientPtr CreateClient(const TConfig& config, const NApi::TClientOptions& options);
+
+//! Shortcut to create rpc client with options from env variables
+NApi::IClientPtr CreateClient(const NApi::NRpcProxy::TConnectionConfigPtr& config);
+NApi::IClientPtr CreateClient(const TConfig& config);
+
+//! Shortcut to create client to specified cluster.
+// `clusterUrl` may have format cluster[/proxyRole],
+// where cluster may be short name of yt cluster (markov, hahn) or ip address + port.
+NApi::IClientPtr CreateClient(TStringBuf clusterUrl);
+
+//! Allows to specify proxyRole as dedicated option.
+NApi::IClientPtr CreateClient(TStringBuf cluster, TStringBuf proxyRole);
+
+//! Shortcut to create client with default config and options from env variables (use env:YT_PROXY as serverName).
+NApi::IClientPtr CreateClient();
+
+//! Shortcut to create client to cluster with custom options.
+NApi::IClientPtr CreateClient(TStringBuf clusterUrl, const NApi::TClientOptions& options);
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NClient::NCache
diff --git a/yt/yt/client/cache/ya.make b/yt/yt/client/cache/ya.make
new file mode 100644
index 0000000000..62dc1d330c
--- /dev/null
+++ b/yt/yt/client/cache/ya.make
@@ -0,0 +1,20 @@
+LIBRARY()
+
+SRCS(
+ cache.cpp
+ cache_base.cpp
+ options.cpp
+ rpc.cpp
+)
+
+PEERDIR(
+ yt/yt/core
+ yt/yt/client
+ yt/yt_proto/yt/client/cache
+)
+
+END()
+
+RECURSE_FOR_TESTS(
+ unittests
+)
diff --git a/yt/yt/client/hedging/cache.h b/yt/yt/client/hedging/cache.h
index db994f7f8b..e635e80b2a 100644
--- a/yt/yt/client/hedging/cache.h
+++ b/yt/yt/client/hedging/cache.h
@@ -4,61 +4,15 @@
#include <yt/yt/client/api/public.h>
-#include <util/generic/strbuf.h>
-
-
-namespace NYT::NClient::NCache {
-
-////////////////////////////////////////////////////////////////////////////////
-
-class TConfig;
-class TClustersConfig;
+#include <yt/yt/client/cache/cache.h>
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NClient::NCache
+#include <util/generic/strbuf.h>
-////////////////////////////////////////////////////////////////////////////////
namespace NYT::NClient::NHedging::NRpc {
-using NYT::NClient::NCache::TConfig;
-using NYT::NClient::NCache::TClustersConfig;
-
-////////////////////////////////////////////////////////////////////////////////
-
-//! Cache of clients per cluster.
-class IClientsCache
- : public TRefCounted
-{
-public:
- virtual NApi::IClientPtr GetClient(TStringBuf clusterUrl) = 0;
-};
-
-DECLARE_REFCOUNTED_TYPE(IClientsCache)
-DEFINE_REFCOUNTED_TYPE(IClientsCache)
-
-////////////////////////////////////////////////////////////////////////////////
-
-//! Creates clients cache which explicitly given config. Server name is always overwritten with requested.
-IClientsCachePtr CreateClientsCache(const TClustersConfig& config, const NApi::TClientOptions& options);
-
-//! Creates clients cache which shares same config (except server name).
-IClientsCachePtr CreateClientsCache(const TConfig& config, const NApi::TClientOptions& options);
-
-//! Shortcut to use client options from env.
-IClientsCachePtr CreateClientsCache(const TConfig& config);
-
-//! Shortcut to create cache with custom options and proxy role.
-IClientsCachePtr CreateClientsCache(const NApi::TClientOptions& options);
-
-//! Shortcut to create cache with default config.
-IClientsCachePtr CreateClientsCache();
-
-
-//! Helper function to create one cluster config from cluster url and clusters config
-TConfig MakeClusterConfig(const TClustersConfig& config, TStringBuf clusterUrl);
-
-////////////////////////////////////////////////////////////////////////////////
+using NCache::TConfig;
+using NCache::TClustersConfig;
+using NCache::CreateClientsCache;
} // namespace NYT::NClient::NHedging::NRpc
diff --git a/yt/yt/client/hedging/hedging.h b/yt/yt/client/hedging/hedging.h
index 3c515ce8b9..02dbe84561 100644
--- a/yt/yt/client/hedging/hedging.h
+++ b/yt/yt/client/hedging/hedging.h
@@ -7,6 +7,8 @@
#include <yt/yt/client/api/client.h>
+#include <yt/yt/client/cache/public.h>
+
// @brief HedgingClient is a wrapper for several YT-clients with ability
// to retry asynchronously the same request with different underlying-clients.
// HedgingClient implements IClient interface and supports methods that do not change state of data on YT.
@@ -29,6 +31,8 @@ namespace NYT::NClient::NHedging::NRpc {
////////////////////////////////////////////////////////////////////////////////
+using NCache::IClientsCachePtr;
+
// from config.proto
class THedgingClientConfig;
diff --git a/yt/yt/client/hedging/public.h b/yt/yt/client/hedging/public.h
index ea6c577d56..a1e3250d1b 100644
--- a/yt/yt/client/hedging/public.h
+++ b/yt/yt/client/hedging/public.h
@@ -1,14 +1,17 @@
#pragma once
+#include <yt/yt/client/cache/public.h>
#include <yt/yt/client/api/public.h>
namespace NYT::NClient::NHedging::NRpc {
+using NCache::IClientsCache;
+using NCache::IClientsCachePtr;
+
////////////////////////////////////////////////////////////////////////////////
DECLARE_REFCOUNTED_STRUCT(TCounter)
DECLARE_REFCOUNTED_STRUCT(TLagPenaltyProviderCounters)
-DECLARE_REFCOUNTED_CLASS(IClientsCache)
DECLARE_REFCOUNTED_STRUCT(TClientConfig)
diff --git a/yt/yt/client/hedging/rpc.h b/yt/yt/client/hedging/rpc.h
index 9eda2c35a6..19f3541fe5 100644
--- a/yt/yt/client/hedging/rpc.h
+++ b/yt/yt/client/hedging/rpc.h
@@ -1,54 +1,15 @@
#pragma once
-#include <yt/yt/client/api/public.h>
-#include <yt/yt/client/api/rpc_proxy/config.h>
-
-#include <yt/yt_proto/yt/client/hedging/proto/config.pb.h>
-
-#include <util/generic/strbuf.h>
-
+#include <yt/yt/client/cache/rpc.h>
namespace NYT::NClient::NHedging::NRpc {
-using NYT::NClient::NCache::TConfig;
-using NYT::NClient::NCache::TClustersConfig;
-using NYT::NClient::NCache::ECompressionCodec;
-
-////////////////////////////////////////////////////////////////////////////////
-
-NApi::NRpcProxy::TConnectionConfigPtr GetConnectionConfig(const TConfig& config);
-
-////////////////////////////////////////////////////////////////////////////////
-
-//! Helper function to extract ClusterName and ProxyRole from clusterUrl.
-std::pair<TStringBuf, TStringBuf> ExtractClusterAndProxyRole(TStringBuf clusterUrl);
-
-//! Helper function to properly set ClusterName and ProxyRole from clusterUrl.
-// Expected that clusterUrl will be in format cluster[/proxyRole].
-void SetClusterUrl(const NApi::NRpcProxy::TConnectionConfigPtr& config, TStringBuf clusterUrl);
-void SetClusterUrl(TConfig& config, TStringBuf clusterUrl);
-
-NApi::IClientPtr CreateClient(const NApi::NRpcProxy::TConnectionConfigPtr& config, const NApi::TClientOptions& options);
-NApi::IClientPtr CreateClient(const TConfig& config, const NApi::TClientOptions& options);
-
-//! Shortcut to create rpc client with options from env variables
-NApi::IClientPtr CreateClient(const NApi::NRpcProxy::TConnectionConfigPtr& config);
-NApi::IClientPtr CreateClient(const TConfig& config);
-
-//! Shortcut to create client to specified cluster.
-// `clusterUrl` may have format cluster[/proxyRole],
-// where cluster may be short name of yt cluster (markov, hahn) or ip address + port.
-NApi::IClientPtr CreateClient(TStringBuf clusterUrl);
-
-//! Allows to specify proxyRole as dedicated option.
-NApi::IClientPtr CreateClient(TStringBuf cluster, TStringBuf proxyRole);
-
-//! Shortcut to create client with default config and options from env variables (use env:YT_PROXY as serverName).
-NApi::IClientPtr CreateClient();
-
-//! Shortcut to create client to cluster with custom options.
-NApi::IClientPtr CreateClient(TStringBuf clusterUrl, const NApi::TClientOptions& options);
-
-////////////////////////////////////////////////////////////////////////////////
+using NCache::TConfig;
+using NCache::TClustersConfig;
+using NCache::ECompressionCodec;
+using NCache::GetConnectionConfig;
+using NCache::ExtractClusterAndProxyRole;
+using NCache::SetClusterUrl;
+using NCache::CreateClient;
} // namespace NYT::NClient::NHedging::NRpc
diff --git a/yt/yt/client/hedging/unittests/cache_ut.cpp b/yt/yt/client/hedging/unittests/cache_ut.cpp
deleted file mode 100644
index 25f61e7a2d..0000000000
--- a/yt/yt/client/hedging/unittests/cache_ut.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-#include <yt/yt/client/hedging/cache.h>
-#include <yt/yt_proto/yt/client/hedging/proto/config.pb.h>
-
-#include <library/cpp/testing/gtest/gtest.h>
-
-#include <library/cpp/yt/string/format.h>
-
-#include <util/generic/vector.h>
-
-#include <util/system/env.h>
-
-#include <thread>
-
-namespace NYT::NClient::NHedging::NRpc {
-
-////////////////////////////////////////////////////////////////////////////////
-
-// YT does not create physical connection immediately, so try to use this fact to create connection to non existence server.
-TEST(TClientsCacheTest, GetSameClient)
-{
- SetEnv("YT_TOKEN", "AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
- auto cache = CreateClientsCache();
- auto client1 = cache->GetClient("localhost");
- auto client2 = cache->GetClient("localhost");
- EXPECT_TRUE(client1 == client2);
-}
-
-TEST(TClientsCacheTest, GetClientWithProxyRole)
-{
- SetEnv("YT_TOKEN", "AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
- auto cache = CreateClientsCache();
- auto client1 = cache->GetClient("bigb@localhost");
- auto client2 = cache->GetClient("localhost");
- EXPECT_TRUE(client1 != client2);
-}
-
-TEST(TClientsCacheTest, MultiThreads)
-{
- SetEnv("YT_TOKEN", "AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
- auto cache = CreateClientsCache();
- TVector<std::thread> threads(Reserve(10));
- TVector<NApi::IClientPtr> clients(threads.capacity());
- TVector<size_t> collisions(threads.capacity());
-
- for (size_t i = 0 ; i < threads.capacity(); ++i) {
- threads.emplace_back([=, &clients, &collisions] () {
- try {
- for (size_t j = 0; j < 1000; ++j) {
- auto client = cache->GetClient(Format("localhost:6000%v", i));
- if (client != clients[i]) {
- clients[i] = client;
- ++collisions[i];
- }
- }
- } catch (...) {
- collisions[i] = 100500; // exception marker
- }
- });
- }
-
- for (auto& t : threads) {
- t.join();
- }
- for (const auto& client : clients) {
- EXPECT_TRUE(client);
- }
- for (auto collision : collisions) {
- EXPECT_EQ(1u, collision);
- }
-}
-
-TEST(TClientsCacheTest, MakeClusterConfig) {
- TClustersConfig clustersCfg;
- clustersCfg.MutableDefaultConfig()->SetClusterName("seneca-nan"); // will be ignored
- clustersCfg.MutableDefaultConfig()->SetProxyRole("default_role"); // can be overwritten
- clustersCfg.MutableDefaultConfig()->SetChannelPoolSize(42u);
- auto& senecaVlaCfg = (*clustersCfg.MutableClusterConfigs())["seneca-vla"];
- senecaVlaCfg.SetClusterName(""); // will be ignored
- senecaVlaCfg.SetProxyRole("seneca_vla_role"); // can be overwritten
- senecaVlaCfg.SetChannelPoolSize(43u);
-
- {
- auto cfg = MakeClusterConfig(clustersCfg, "seneca-man");
- EXPECT_EQ(cfg.GetClusterName(), "seneca-man");
- EXPECT_EQ(cfg.GetProxyRole(), "default_role");
- EXPECT_EQ(cfg.GetChannelPoolSize(), 42u);
- }
- {
- auto cfg = MakeClusterConfig(clustersCfg, "seneca-man/overwriting_role");
- EXPECT_EQ(cfg.GetClusterName(), "seneca-man");
- EXPECT_EQ(cfg.GetProxyRole(), "overwriting_role");
- EXPECT_EQ(cfg.GetChannelPoolSize(), 42u);
- }
- {
- auto cfg = MakeClusterConfig(clustersCfg, "seneca-vla");
- EXPECT_EQ(cfg.GetClusterName(), "seneca-vla");
- EXPECT_EQ(cfg.GetProxyRole(), "seneca_vla_role");
- EXPECT_EQ(cfg.GetChannelPoolSize(), 43u);
- }
- {
- auto cfg = MakeClusterConfig(clustersCfg, "seneca-vla/overwriting_role");
- EXPECT_EQ(cfg.GetClusterName(), "seneca-vla");
- EXPECT_EQ(cfg.GetProxyRole(), "overwriting_role");
- EXPECT_EQ(cfg.GetChannelPoolSize(), 43u);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NClient::NHedging::NRpc
diff --git a/yt/yt/client/hedging/unittests/options_ut.cpp b/yt/yt/client/hedging/unittests/options_ut.cpp
deleted file mode 100644
index 3c9c11b322..0000000000
--- a/yt/yt/client/hedging/unittests/options_ut.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <yt/yt/client/hedging/options.h>
-
-#include <library/cpp/testing/common/scope.h>
-#include <library/cpp/testing/gtest/gtest.h>
-
-#include <util/folder/dirut.h>
-#include <util/folder/tempdir.h>
-
-#include <util/stream/file.h>
-
-#include <util/system/env.h>
-
-namespace NYT::NClient::NHedging {
-
-////////////////////////////////////////////////////////////////////////////////
-
-TEST(TClientOptionsTest, TokenFromFile)
-{
- TTempDir tmpDir;
- MakeDirIfNotExist(tmpDir.Name() + "/.yt");
- {
- TFileOutput token(tmpDir.Name() + "/.yt/token");
- token.Write(" AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \n");
- }
- NTesting::TScopedEnvironment envGuard{{
- {"HOME", tmpDir.Name()},
- {"YT_TOKEN", ""},
- {"YT_TOKEN_PATH", ""},
- }};
- const auto clientOptions = GetClientOpsFromEnv();
- EXPECT_TRUE(clientOptions.Token);
- EXPECT_EQ("AAAA-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", *clientOptions.Token);
-}
-
-TEST(TClientOptionsTest, TokenFromYtTokenPath)
-{
- TTempDir tmpDir;
- const TString tokenPath = tmpDir.Name() + "/token";
- {
- TFileOutput token(tokenPath);
- token.Write(" BBBB-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \n");
- }
- NTesting::TScopedEnvironment envGuard{{
- {"YT_TOKEN", ""},
- {"YT_TOKEN_PATH", tokenPath},
- }};
- const auto clientOptions = GetClientOpsFromEnv();
- EXPECT_TRUE(clientOptions.Token);
- EXPECT_EQ("BBBB-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", *clientOptions.Token);
-}
-
-TEST(TClientOptionsTest, TokenFromEnv)
-{
- NTesting::TScopedEnvironment tokenGuard("YT_TOKEN", "BBBB-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
- const auto& clientOptions = GetClientOpsFromEnv();
- EXPECT_TRUE(clientOptions.Token);
- EXPECT_EQ("BBBB-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", *clientOptions.Token);
-}
-
-TEST(TClientOptionsTest, UserFromEnv)
-{
- NTesting::TScopedEnvironment envGuard{{
- {"YT_TOKEN", "BBBB-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"},
- {"YT_USER", "yt_test_user"},
- }};
- const auto& clientOptions = GetClientOpsFromEnv();
- EXPECT_TRUE(clientOptions.User);
- EXPECT_EQ("yt_test_user", *clientOptions.User);
-}
-
-TEST(TClientOptionsTest, AllowEmptyUser)
-{
- NTesting::TScopedEnvironment envGuard{{
- {"YT_TOKEN", "BBBB-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"},
- {"YT_USER", ""},
- }};
- const auto& clientOptions = GetClientOpsFromEnv();
- EXPECT_TRUE(!clientOptions.User);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NClient::NHedging
diff --git a/yt/yt/client/hedging/unittests/rpc_ut.cpp b/yt/yt/client/hedging/unittests/rpc_ut.cpp
deleted file mode 100644
index 09b7c4e820..0000000000
--- a/yt/yt/client/hedging/unittests/rpc_ut.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <yt/yt/client/hedging/rpc.h>
-#include <yt/yt_proto/yt/client/hedging/proto/config.pb.h>
-
-#include <library/cpp/testing/gtest/gtest.h>
-
-namespace NYT::NClient::NHedging::NRpc {
-
-////////////////////////////////////////////////////////////////////////////////
-
-TEST(RpcClientTest, SetClusterUrlWithoutProxy)
-{
- TConfig config;
- SetClusterUrl(config, "markov");
- EXPECT_EQ("markov", config.GetClusterName());
- EXPECT_EQ("", config.GetProxyRole());
-}
-
-TEST(RpcClientTest, SetClusterUrlWithProxy)
-{
- TConfig config;
- SetClusterUrl(config, "markov/bigb");
- EXPECT_EQ("markov", config.GetClusterName());
- EXPECT_EQ("bigb", config.GetProxyRole());
-}
-
-TEST(RpcClientTest, ProxyRoleOverride)
-{
- TConfig config;
- config.SetProxyRole("role");
- EXPECT_THROW(SetClusterUrl(config, "markov/bigb"), std::exception);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NClient::NHedging::NRpc
diff --git a/yt/yt/client/hedging/unittests/ya.make b/yt/yt/client/hedging/unittests/ya.make
index 4ab3e1abbb..6fb24ba2b4 100644
--- a/yt/yt/client/hedging/unittests/ya.make
+++ b/yt/yt/client/hedging/unittests/ya.make
@@ -5,12 +5,9 @@ INCLUDE(${ARCADIA_ROOT}/yt/ya_cpp.make.inc)
EXPLICIT_DATA()
SRCS(
- cache_ut.cpp
counters_ut.cpp
hedging_ut.cpp
- options_ut.cpp
penalty_provider_ut.cpp
- rpc_ut.cpp
GLOBAL hook.cpp
)
diff --git a/yt/yt/client/hedging/ya.make b/yt/yt/client/hedging/ya.make
index acee58f50a..3dbe8af3d5 100644
--- a/yt/yt/client/hedging/ya.make
+++ b/yt/yt/client/hedging/ya.make
@@ -3,20 +3,18 @@ LIBRARY()
INCLUDE(${ARCADIA_ROOT}/yt/ya_cpp.make.inc)
SRCS(
- cache.cpp
config.cpp
counter.cpp
hedging.cpp
hedging_executor.cpp
logger.cpp
- options.cpp
penalty_provider.cpp
- rpc.cpp
)
PEERDIR(
yt/yt/core
yt/yt/client
+ yt/yt/client/cache
yt/yt/library/profiling
yt/yt_proto/yt/client/hedging