Skip to content

Conversation

@faviansamatha
Copy link
Contributor

Description

  • Fixed bug when switching to writer or reader in read/write splitting after host is not in allowed list of hosts in custom endpoint
  • Split custom endpoint test with read write splitting into 2 in order to ensure that we always test both paths.

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

@faviansamatha faviansamatha force-pushed the fix/read-write-splitting-no-writer branch from 9217b12 to f3c0000 Compare January 20, 2026 20:07
props["custom_endpoint_idle_monitor_expiration_ms"] = 30_000
props["wait_for_custom_endpoint_info_timeout_ms"] = 30_000

# Ensure that we are starting with a reader connection
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
# Ensure that we are starting with a reader connection
# Ensure that we are starting with a writer connection

try:
self.wait_until_endpoint_has_members(rds_client, {original_instance_id, new_member})

# We should now be able to switch to reader.
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
# We should now be able to switch to reader.
# We should now be able to switch to writer.

conn.read_only = False

writer_id = rds_utils.get_cluster_writer_instance_id()
new_member = writer_id
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 assign writer_id to new_member? the following lines are actually clearer if you keep the name writer_id?

Comment on lines +284 to +285
# We should not be able to switch again because new_member was removed from the custom endpoint.
# We are connected to the reader. Attempting to switch to the writer will throw an exception.
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify:

  • reconnected back to the original reader instance on line 277
  • removed the original reader instance from the custom endpoint
  • now switching to the writer instance (a valid member of the endpoint) errors out

This is because the current reader connection is invalid? Wouldn't any operation fail?

assert new_instance_id == new_member

# Switch back to original instance
conn.read_only = True
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
conn.read_only = True
conn.read_only = True
new_instance_id = rds_utils.query_instance_id(conn)
assert new_instance_id == original_instance_id

with pytest.raises(ReadWriteSplittingError):
conn.read_only = new_read_only_value
# We are connected to the writer. Attempting to switch to the reader will not work but will intentionally
# not throw an exception. In this scenario we log a warning and purposefully stick with the writer.
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
# not throw an exception. In this scenario we log a warning and purposefully stick with the writer.
# not throw an exception. In this scenario we log a warning and fallback to the writer.

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.

2 participants