in src/failover/failover_service.cc [310:344]
bool FailoverService::failover_writer(SQLHDBC hdbc) {
topology_monitor_->ForceRefresh(true, failover_timeout_);
// Try connecting to a writer
std::vector<HostInfo> hosts = topology_map_->Get(cluster_id_);
std::unordered_map<std::string, std::string> properties;
RoundRobinHostSelector::SetRoundRobinWeight(hosts, properties);
HostInfo host;
try {
host = host_selector_->GetHost(hosts, true, properties);
} catch (const std::exception& e) {
LOG(INFO) << "[Failover Service] no hosts in topology for: " << cluster_id_;
return false;
}
std::string host_string = host.GetHost();
LOG(INFO) << "[Failover Service] writer failover connection to a new writer: " << host_string;
bool is_connected = connect_to_host(hdbc, host_string);
if (!is_connected) {
LOG(INFO) << "[Failover Service] writer failover unable to connect to any instance for: " << cluster_id_;
return false;
}
if (odbc_helper_->CheckConnection(hdbc)) {
if (!is_connected_to_reader(hdbc)) {
LOG(INFO) << "[Failover Service] writer failover connected to a new writer for: " << host_string;
curr_host_ = host;
return true;
}
LOG(ERROR) << "The new writer was identified to be " << host_string << ", but querying the instance for its role returned a reader.";
return false;
}
LOG(INFO) << "[Failover Service] writer failover unable to connect to any instance for: " << cluster_id_;
SQLDisconnect(hdbc);
return false;
}