in common/lib/plugins/read_write_splitting_plugin.ts [281:311]
async getNewReaderClient() {
let targetClient = undefined;
let readerHost: HostInfo | undefined = undefined;
const connectAttempts = this.pluginService.getHosts().length;
for (let i = 0; i < connectAttempts; i++) {
const host = this.pluginService.getHostInfoByStrategy(HostRole.READER, this.readerSelectorStrategy);
if (host) {
const props = new Map(this._properties);
props.set(WrapperProperties.HOST.name, host.host);
try {
const copyProps = new Map<string, any>(props);
WrapperProperties.ENABLE_CLUSTER_AWARE_FAILOVER.set(copyProps, false);
targetClient = await this.pluginService.connect(host, copyProps);
this.isReaderClientFromInternalPool = targetClient instanceof PoolClientWrapper;
readerHost = host;
break;
} catch (any) {
logger.warn(Messages.get("ReadWriteSplittingPlugin.failedToConnectToReader", host.url));
}
}
}
if (targetClient == undefined || readerHost === undefined) {
logAndThrowError(Messages.get("ReadWriteSplittingPlugin.noReadersAvailable"));
return;
}
logger.debug(Messages.get("ReadWriteSplittingPlugin.successfullyConnectedToReader", readerHost.url));
this.setReaderClient(targetClient, readerHost);
await this.switchCurrentTargetClientTo(this.readerTargetClient, this._readerHostInfo);
}