void ClusterTopologyMonitor::NodeMonitoringThread::reader_thread_fetch_topology()

in src/failover/cluster_topology_monitor.cc [553:583]


void ClusterTopologyMonitor::NodeMonitoringThread::reader_thread_fetch_topology() {
    auto* local_hdbc = reinterpret_cast<SQLHDBC>(*main_monitor_->node_threads_reader_hdbc_.get());
    // Check connection
    if (!main_monitor_->odbc_helper_->CheckConnection(local_hdbc)) {
        return;
    };
    // Query for hosts
    std::vector<HostInfo> hosts;
    hosts = main_monitor_->query_helper_->QueryTopology(local_hdbc);

    // Share / update topology to main monitor
    {
        std::lock_guard<std::mutex> lock(main_monitor_->node_threads_latest_topology_mutex_);
        main_monitor_->node_threads_latest_topology_ = std::make_shared<std::vector<HostInfo>>(hosts);
    }

    // Update cache if writer changed
    if (writer_changed_) {
        LOG(INFO) << "Writer has changed, updating cache";
        main_monitor_->UpdateTopologyCache(hosts);
    }

    // Check if writer changed
    for (const HostInfo& hi : hosts) {
        if (hi.IsHostWriter() && (!writer_host_info_ || hi.GetHostPortPair() == writer_host_info_->GetHostPortPair())) {
            writer_changed_ = true;
            main_monitor_->UpdateTopologyCache(hosts);
            break;
        }
    }
}