Skip to content

Commit

Permalink
TCredentialsKey -> TConnectionParams (#7062)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberROFL authored Jul 24, 2024
1 parent 6f10c09 commit 0475ae0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ydb/core/tx/replication/service/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class TSessionInfo {

}; // TSessionInfo

struct TCredentialsKey: std::tuple<TString, TString, bool, TString> {
explicit TCredentialsKey(const TString& endpoint, const TString& database, bool ssl, const TString& user)
struct TConnectionParams: std::tuple<TString, TString, bool, TString> {
explicit TConnectionParams(const TString& endpoint, const TString& database, bool ssl, const TString& user)
: std::tuple<TString, TString, bool, TString>(endpoint, database, ssl, user)
{
}
Expand All @@ -143,27 +143,27 @@ struct TCredentialsKey: std::tuple<TString, TString, bool, TString> {
return std::get<2>(*this);
}

static TCredentialsKey FromParams(const NKikimrReplication::TConnectionParams& params) {
static TConnectionParams FromProto(const NKikimrReplication::TConnectionParams& params) {
const auto& endpoint = params.GetEndpoint();
const auto& database = params.GetDatabase();
const bool ssl = params.GetEnableSsl();

switch (params.GetCredentialsCase()) {
case NKikimrReplication::TConnectionParams::kStaticCredentials:
return TCredentialsKey(endpoint, database, ssl, params.GetStaticCredentials().GetUser());
return TConnectionParams(endpoint, database, ssl, params.GetStaticCredentials().GetUser());
case NKikimrReplication::TConnectionParams::kOAuthToken:
return TCredentialsKey(endpoint, database, ssl, params.GetOAuthToken().GetToken());
return TConnectionParams(endpoint, database, ssl, params.GetOAuthToken().GetToken());
default:
Y_ABORT("Unexpected credentials");
}
}

}; // TCredentialsKey
}; // TConnectionParams

} // NKikimr::NReplication::NService

template <>
struct THash<NKikimr::NReplication::NService::TCredentialsKey> : THash<std::tuple<TString, TString, bool, TString>> {};
struct THash<NKikimr::NReplication::NService::TConnectionParams> : THash<std::tuple<TString, TString, bool, TString>> {};

namespace NKikimr::NReplication {

Expand Down Expand Up @@ -217,11 +217,11 @@ class TReplicationService: public TActorBootstrapped<TReplicationService> {
}

template <typename... Args>
const TActorId& GetOrCreateYdbProxy(TCredentialsKey&& key, Args&&... args) {
auto it = YdbProxies.find(key);
const TActorId& GetOrCreateYdbProxy(TConnectionParams&& params, Args&&... args) {
auto it = YdbProxies.find(params);
if (it == YdbProxies.end()) {
auto ydbProxy = Register(CreateYdbProxy(key.Endpoint(), key.Database(), key.EnableSsl(), std::forward<Args>(args)...));
auto res = YdbProxies.emplace(std::move(key), std::move(ydbProxy));
auto ydbProxy = Register(CreateYdbProxy(params.Endpoint(), params.Database(), params.EnableSsl(), std::forward<Args>(args)...));
auto res = YdbProxies.emplace(std::move(params), std::move(ydbProxy));
Y_ABORT_UNLESS(res.second);
it = res.first;
}
Expand All @@ -234,10 +234,10 @@ class TReplicationService: public TActorBootstrapped<TReplicationService> {
const auto& params = settings.GetConnectionParams();
switch (params.GetCredentialsCase()) {
case NKikimrReplication::TConnectionParams::kStaticCredentials:
ydbProxy = GetOrCreateYdbProxy(TCredentialsKey::FromParams(params), params.GetStaticCredentials());
ydbProxy = GetOrCreateYdbProxy(TConnectionParams::FromProto(params), params.GetStaticCredentials());
break;
case NKikimrReplication::TConnectionParams::kOAuthToken:
ydbProxy = GetOrCreateYdbProxy(TCredentialsKey::FromParams(params), params.GetOAuthToken().GetToken());
ydbProxy = GetOrCreateYdbProxy(TConnectionParams::FromProto(params), params.GetOAuthToken().GetToken());
break;
default:
Y_ABORT("Unexpected credentials");
Expand Down Expand Up @@ -438,7 +438,7 @@ class TReplicationService: public TActorBootstrapped<TReplicationService> {
mutable TMaybe<TString> LogPrefix;
TActorId BoardPublisher;
THashMap<ui64, TSessionInfo> Sessions;
THashMap<TCredentialsKey, TActorId> YdbProxies;
THashMap<TConnectionParams, TActorId> YdbProxies;
THashMap<TActorId, ui64> WorkerActorIdToSession;

}; // TReplicationService
Expand Down

0 comments on commit 0475ae0

Please sign in to comment.