-
Notifications
You must be signed in to change notification settings - Fork 16
fix: read/write splitting switch to writer #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
9217b12 to
f3c0000
Compare
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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 |
There was a problem hiding this comment.
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?
| # 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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. |
Description
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.