in aws_advanced_python_wrapper/reader_failover_handler.py [0:0]
def _internal_failover_task(
self, topology: Tuple[HostInfo, ...], current_host: Optional[HostInfo]) -> ReaderFailoverResult:
try:
while not self._timeout_event.is_set():
result = self._failover_internal(topology, current_host)
if result is not None and result.is_connected:
if not self._strict_reader_failover:
return result # any host is fine
# need to ensure that the new connection is to a reader host
self._plugin_service.force_refresh_host_list(result.connection)
if result.new_host is not None:
topology = self._plugin_service.all_hosts
for host in topology:
# found new connection host in the latest topology
if host.url == result.new_host.url and host.role == HostRole.READER:
return result
# New host is not found in the latest topology. There are few possible reasons for that.
# - Host is not yet presented in the topology due to failover process in progress
# - Host is in the topology but its role isn't a READER (that is not acceptable option due to this.strictReader setting)
# Need to continue this loop and to make another try to connect to a reader.
if result.connection is not None:
result.connection.close()
sleep(1) # Sleep for 1 second
except Exception as err:
return ReaderFailoverResult(None, False, None, err)
return ReaderFailoverHandlerImpl.failed_reader_failover_result