@@ -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
0 commit comments