Skip to content

Conversation

@sophia-bq
Copy link

Description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

...

def is_reader_host(self, current_host: HostInfo) -> bool:
"""Return true if the current host fits the criteria of a writer host."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Return true if the current host fits the criteria of a writer host."""
"""Return true if the current host fits the criteria of a reader host."""

Comment on lines +497 to +498
def old_reader_can_be_used(self, reader_host_info: HostInfo) -> bool:
"""Return true if the current host can be used to switch connection to."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we only pass a reader host into this method but there's no logic specific to readers. I don't think this method needs to know whether the host info is new or old, writer or reader.

Suggested change
def old_reader_can_be_used(self, reader_host_info: HostInfo) -> bool:
"""Return true if the current host can be used to switch connection to."""
def can_host_be_used(self, host_info: HostInfo) -> bool:
"""Returns true if connections can be switched to the given host"""

Comment on lines +501 to +502
def need_connect_to_writer(self) -> bool:
"""Return true if switching to reader should instead connect to writer."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would make things a bit clearer

Suggested change
def need_connect_to_writer(self) -> bool:
"""Return true if switching to reader should instead connect to writer."""
def has_no_readers(self) -> bool:
"""Return true if there are no readers in the host list"""

WrapperProperties.SRW_CONNECT_RETRY_INTERVAL_MS, props, int, lambda x: x > 0
)

self._verify_opened_connection_type: Optional[HostRole] = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will make it clearer that this is for initial connections, not subsequent connection switches

Suggested change
self._verify_opened_connection_type: Optional[HostRole] = (
self._verify_initial_connection_type: Optional[HostRole] = (

try:
if connect_func is not None:
candidate_conn = connect_func()
elif host_info is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this check necessary if host_info is not Optional? Or should host_info be of type Optional[HostInfo]?

sleep(self._connect_retry_interval_ms / 1000)

@staticmethod
def _parse_connection_type(phase_str: Optional[str]) -> HostRole:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use the word "phase"? would "expected_role" work?

Suggested change
def _parse_connection_type(phase_str: Optional[str]) -> HostRole:
def _parse_role(role_str: Optional[str]) -> HostRole:

if not phase_str:
return HostRole.UNKNOWN

phase_upper = phase_str.lower()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
phase_upper = phase_str.lower()
phase_lower = phase_str.lower()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants