in common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts [198:244]
private async openAnyClientAndUpdateTopology(): Promise<HostInfo[] | null> {
let writerVerifiedByThisTask = false;
if (!this.monitoringClient) {
let client: ClientWrapper;
try {
client = await this._pluginService.forceConnect(this.initialHostInfo, this._monitoringProperties);
} catch {
// Unable to connect to host;
return null;
}
if (client && this.monitoringClient === null) {
this.monitoringClient = client;
logger.debug(Messages.get("ClusterTopologyMonitor.openedMonitoringConnection", this.initialHostInfo.host));
try {
const writerId = await this.getWriterHostIdIfConnected(this.monitoringClient, this.initialHostInfo.hostId);
if (writerId) {
this.isVerifiedWriterConnection = true;
this.writerHostInfo = this.initialHostInfo;
logger.info(Messages.get("ClusterTopologyMonitor.writerMonitoringConnection", this.initialHostInfo.host));
writerVerifiedByThisTask = true;
}
} catch (error) {
// Do nothing.
logger.error(Messages.get("ClusterTopologyMonitor.invalidWriterQuery", error?.message));
}
} else {
// Monitoring connection already set by another task, close the new connection.
await this.closeConnection(client);
}
}
const hosts: HostInfo[] = await this.fetchTopologyAndUpdateCache(this.monitoringClient);
if (writerVerifiedByThisTask) {
if (this.ignoreNewTopologyRequestsEndTimeMs === -1) {
this.ignoreNewTopologyRequestsEndTimeMs = 0;
} else {
this.ignoreNewTopologyRequestsEndTimeMs = Date.now() + this.ignoreTopologyRequestMs;
}
}
if (hosts === null) {
this.isVerifiedWriterConnection = false;
await this.updateMonitoringClient(null);
}
return hosts;
}