in common/lib/plugins/read_write_splitting_plugin.ts [313:334]
async switchToWriterTargetClient(hosts: HostInfo[]) {
const currentHost = this.pluginService.getCurrentHostInfo();
const currentClient = this.pluginService.getCurrentClient();
if (currentHost !== null && currentHost?.role === HostRole.WRITER && (await currentClient.isValid())) {
return;
}
this._inReadWriteSplit = true;
const writerHost = getWriter(hosts, Messages.get("ReadWriteSplittingPlugin.noWriterFound"));
if (!writerHost) {
return;
}
if (!(await this.isTargetClientUsable(this.writerTargetClient))) {
await this.getNewWriterClient(writerHost);
} else if (this.writerTargetClient) {
await this.switchCurrentTargetClientTo(this.writerTargetClient, writerHost);
}
logger.debug(Messages.get("ReadWriteSplittingPlugin.switchedFromReaderToWriter", writerHost.url));
if (this.isReaderClientFromInternalPool) {
await this.closeTargetClientIfIdle(this.readerTargetClient);
}
}