-
Notifications
You must be signed in to change notification settings - Fork 975
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
StatefulRedisClusterConnectionImpl getConnection always calls connection provider with Intent.WRITE #2095
Comments
Sounds good. We can easily introduce |
…ConnectionProvider Refactored Intent to be a top level public enum. Refactored usages & comments. redis#2095
PR created: #2096 |
Checking in here, is there a normal cadence to get PRs merged? |
No, the project is run in spare time. I've been busy with daywork more than usual so I don't have much bandwidth left. |
Ok, no problem at all. Just wanted to get an idea if there was a fixed cadence. I totally get the spare time nature of OSS. Thank you for all that you do for the open source community. |
Feature Request
I want to be able to get a connection to a specific node from the pool of cluster connections that has the READONLY flag preset for that connection (so I don't have to check the status every time before the connection is used).
My use-case: I have a redis cluster (aws elasticache) in cluster on configuration. I want to randomly select a set of replica nodes to subscribe keyspace notifications to to watch for changes to a given key prefix. On the receipt of an event on one of theses nodes, I want to call GET on that specific node to fetch the new value of the key. This allows me to spread the read load around my replicas near uniformly.
Is your feature request related to a problem? Please describe
Based on my read of the code, that would be connections that have Intent.READ in their connection key. However, the getConnection method on the StatefulRedisClusterConnectionImpl class always calls to the connection provider with Intent.Write
https://github.com/lettuce-io/lettuce-core/blob/main/src/main/java/io/lettuce/core/cluster/StatefulRedisClusterConnectionImpl.java#L168
All of the classes used by that method are package private, so I can't bypass it to get a connection with Intent.READ. Also based on my read of that code path, it does not take into account the setting of ReadFrom.REPLICA on the cluster connection object configuration.
Is my read of the code correct?
Describe the solution you'd like
I would like a variant of the getConnection(nodeId) method that also takes an intent so I can fetch a read connection directly without fetching an Intent.WRITE connection, calling readonly API, and then dispatching the get command, thereby "breaking" what the write connection is supposed to be (for writing).
I am more than happy to submit a pull request for the change if my read of the code is correct. If the read is not correct, can you let me know how to get a read-only connection to a specific replica node in the cluster?
Describe alternatives you've considered
I have considered using getConnection(nodeid) and then checking the "isReadOnly" flag, if it's false, send a "readonly" command on the connection, followed by the command I intend to execute.
Teachability, Documentation, Adoption, Migration Strategy
Would add a new method with javadoc to explain the intent of the method and an example use-case as outlined above.
The text was updated successfully, but these errors were encountered: