-
Notifications
You must be signed in to change notification settings - Fork 137
chore: route multi-use read-only txn reads via location-aware cache #4340
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
Summary of ChangesHello @rahul2393, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the routing capabilities for read-only transactions by allowing them to leverage location-aware caching. Instead of being pinned to a single endpoint due to transaction affinity, read-only operations can now be routed independently based on key ranges and explicit leader preferences. This change aims to improve performance and resource utilization for multi-use read-only transactions by distributing their reads more efficiently across available servers. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request effectively implements location-aware routing for multi-use read-only transactions, which should improve performance by allowing individual reads and queries to be routed based on key ranges instead of being pinned by transaction affinity. The changes are well-structured, with clear separation of concerns between ChannelFinder and KeyAwareChannel. The addition of tracking for read-only transactions and the logic to bypass affinity are implemented correctly. The new unit tests cover the main scenarios well. I've only found one minor issue in a test case, which is missing assertions to fully verify the cleanup logic.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/KeyAwareChannelTest.java
Outdated
Show resolved
Hide resolved
93ca22e to
540f387
Compare
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/ChannelFinder.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyAwareChannel.java
Outdated
Show resolved
Hide resolved
| endpoint = finder.findServer(reqBuilder); | ||
| } | ||
| allowDefaultAffinity = true; | ||
| if (reqBuilder.hasOptions() && reqBuilder.getOptions().hasReadOnly()) { |
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.
I think that we should add similar logic for ExecuteSqlRequest and ReadRequest, as those can also include an inlined BeginTransactionOption. That might not be something that we use today for read-only transactions, but it is likely to change in the future. (Alternatively, we should have a test that fails if we see an ExecuteSqlRequest with an inlined begin. That way we get a signal if this part of the implementation changes in the future, and are forced to fix it here then)
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.
added support for both explicit begin and inline begin with ExecuteSqlRequest and ReadRequest
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyAwareChannel.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyAwareChannel.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/KeyAwareChannel.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| public void readOnlyTransactionRoutesEachReadIndependently() throws 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.
One limitation with this type of test is that they assume a given client behavior. That is: they assume that the client will call BeginTransaction for read-only transactions. If we change that in the future to use inlined-begin, then these tests will continue to pass, even though the actual feature will not work correctly. So I think that we also need something of an end-to-end test that really verifies that the feature works with client (and continues to work with the client, even if we make internal changes).
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.
end-to-end test won't be possible here currently.
on routing hints/key ranges) instead of being pinned by transaction affinity/default endpoint.