Skip to content

Commit 6af292f

Browse files
committed
[refactor]
1 parent 9ef5dc7 commit 6af292f

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

ydb/core/fq/libs/actors/database_resolver.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -468,43 +468,43 @@ class TDatabaseResolver: public TActor<TDatabaseResolver>
468468
NYql::IMdbEndpointGenerator::TEndpoint endpoint;
469469
TVector<TString> aliveHosts;
470470

471-
for (const auto& host : databaseInfo.GetMap().at("hosts").GetArraySafe()) {
472-
const auto& hostMap = host.GetMap();
473471

474-
if (!hostMap.contains("services")) {
475-
// indicates that cluster is down
476-
continue;
477-
}
478-
479-
// all services of a particular host must be alive
480-
bool alive = true;
472+
for (const auto& host : databaseInfo.GetMap().at("hosts").GetArraySafe()) {
473+
const auto& hostMap = host.GetMap();
481474

482-
for (const auto& service: hostMap.at("services").GetArraySafe()) {
483-
if (service["health"].GetString() != "ALIVE") {
484-
alive = false;
485-
break;
486-
}
487-
}
475+
if (!hostMap.contains("services")) {
476+
// indicates that cluster is down
477+
continue;
478+
}
488479

489-
if (alive) {
490-
aliveHosts.push_back(host["name"].GetString());
491-
}
480+
// check if all services of a particular host are alive
481+
bool alive = std::all_of(
482+
hostMap.at("services").GetArraySafe().begin(),
483+
hostMap.at("services").GetArraySafe().end(),
484+
[](const auto& service) {
485+
return service["health"].GetString() == "ALIVE";
492486
}
493-
494-
if (aliveHosts.empty()) {
495-
ythrow TCodeLineException(TIssuesIds::INTERNAL_ERROR) << "No ALIVE MySQL hosts found";
487+
);
488+
489+
if (alive) {
490+
aliveHosts.push_back(host["name"].GetString());
496491
}
492+
}
497493

498-
NYql::IMdbEndpointGenerator::TParams params = {
499-
.DatabaseType = NYql::EDatabaseType::MySQL,
500-
.MdbHost = aliveHosts[std::rand() % static_cast<int>(aliveHosts.size())],
501-
.UseTls = useTls,
502-
.Protocol = protocol,
503-
};
494+
if (aliveHosts.empty()) {
495+
ythrow TCodeLineException(TIssuesIds::INTERNAL_ERROR) << "No ALIVE MySQL hosts found";
496+
}
504497

505-
endpoint = mdbEndpointGenerator->ToEndpoint(params);
498+
NYql::IMdbEndpointGenerator::TParams params = {
499+
.DatabaseType = NYql::EDatabaseType::MySQL,
500+
.MdbHost = aliveHosts[std::rand() % static_cast<int>(aliveHosts.size())],
501+
.UseTls = useTls,
502+
.Protocol = protocol,
503+
};
506504

507-
return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls};
505+
endpoint = mdbEndpointGenerator->ToEndpoint(params);
506+
507+
return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls};
508508
};
509509
}
510510

ydb/core/fq/libs/actors/ut/database_resolver_ut.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Y_UNIT_TEST_SUITE(TDatabaseResolverTests) {
567567
NYql::TDatabaseResolverResponse::TDatabaseDescription{
568568
TString{""},
569569
TString{"rc1b-eyt6dtobu96rwydq.db.yandex.net"},
570-
6432,
570+
3306,
571571
TString(""),
572572
true
573573
},
@@ -583,7 +583,7 @@ Y_UNIT_TEST_SUITE(TDatabaseResolverTests) {
583583
"/managed-mysql/v1/clusters/etn021us5r9rhld1vgbh/hosts",
584584
"etn021us5r9rhld1vgbh",
585585
NYql::EDatabaseType::MySQL
586-
) << NoPermissionStr << " Please check that your service account has role `managed-mysql.viewer`."
586+
) << NoPermissionStr
587587
)
588588
};
589589

0 commit comments

Comments
 (0)