in aws_advanced_python_wrapper/failover_plugin.py [0:0]
def _failover_writer(self):
telemetry_factory = self._plugin_service.get_telemetry_factory()
context = telemetry_factory.open_telemetry_context("failover to writer host", TelemetryTraceLevel.NESTED)
self._failover_writer_triggered_counter.inc()
try:
logger.info("FailoverPlugin.StartWriterFailover")
result: WriterFailoverResult = self._writer_failover_handler.failover(self._plugin_service.all_hosts)
if result is not None and result.exception is not None:
raise result.exception
elif result is None or not result.is_connected:
raise FailoverFailedError(Messages.get("FailoverPlugin.UnableToConnectToWriter"))
writer_host = self._get_writer(result.topology)
allowed_hosts = self._plugin_service.hosts
allowed_hostnames = [host.host for host in allowed_hosts]
if writer_host.host not in allowed_hostnames:
raise FailoverFailedError(
Messages.get_formatted(
"FailoverPlugin.NewWriterNotAllowed",
"<null>" if writer_host is None else writer_host.host,
LogUtils.log_topology(allowed_hosts)))
self._plugin_service.set_current_connection(result.new_connection, writer_host)
logger.info("FailoverPlugin.EstablishedConnection", self._plugin_service.current_host_info)
self._plugin_service.refresh_host_list()
self._failover_writer_success_counter.inc()
except FailoverSuccessError as fse:
context.set_success(True)
context.set_exception(fse)
self._failover_writer_success_counter.inc()
raise fse
except Exception as ex:
context.set_success(False)
context.set_exception(ex)
self._failover_writer_failed_counter.inc()
raise ex
finally:
context.close_context()
if self._telemetry_failover_additional_top_trace_setting:
telemetry_factory.post_copy(context, TelemetryTraceLevel.FORCE_TOP_LEVEL)