Skip to content
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

Closed
mikeamzn opened this issue May 15, 2022 · 5 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@mikeamzn
Copy link
Contributor

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.

@mp911de
Copy link
Collaborator

mp911de commented May 16, 2022

Sounds good. We can easily introduce getConnection(…) overloads accepting ClusterConnectionProvider.Intent. However, ClusterConnectionProvider is package-private and it should stay that way, so we need to refactor Intent to a public top-level type and probably rename it to ConnectionIntent.

@mp911de mp911de added type: enhancement A general enhancement status: help-wanted An issue that a contributor can help us with labels May 16, 2022
mikeamzn added a commit to mikeamzn/lettuce-core that referenced this issue May 16, 2022
…ConnectionProvider

Refactored Intent to be a top level public enum.
Refactored usages & comments.

redis#2095
@mikeamzn
Copy link
Contributor Author

PR created: #2096

@mp911de mp911de removed the status: help-wanted An issue that a contributor can help us with label May 17, 2022
@mikeamzn
Copy link
Contributor Author

Checking in here, is there a normal cadence to get PRs merged?

@mp911de
Copy link
Collaborator

mp911de commented Jun 17, 2022

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.

@mikeamzn
Copy link
Contributor Author

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.

mp911de pushed a commit that referenced this issue Jul 7, 2022
…ConnectionProvider #2095

Refactored Intent to be a top level public enum.
Refactored usages & comments.

Original pull request: #2096.
mp911de added a commit that referenced this issue Jul 7, 2022
Move ConnectionIntent to protocol package. Refactor Master/Replica code to use shared ConnectionIntent type. Add since tags, license headers and update Javadoc.

Original pull request: #2096.
@mp911de mp911de added this to the 6.2.0 milestone Jul 7, 2022
@mp911de mp911de closed this as completed Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants