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

Automatically refresh connections to redis cluster on shard/replica addition/deletion #320

Open
akshaypatidar1999 opened this issue Jan 20, 2022 · 5 comments
Milestone

Comments

@akshaypatidar1999
Copy link

akshaypatidar1999 commented Jan 20, 2022

Describe the feature

Refresh connections to redis cluster whenever there is a change in cluster

Current redis client implementation creates connections to redis cluster and uses them to send requests to redis cluster. However if redis cluster is changed (new shards/replicas are added/deleted) then it does not automatically refreshes the connection, due to which we see errors like MOVED 7652 10.0.4.210:6379 and we have to redeploy our service.

If we could somehow detect changes in the cluster and refresh connections then we can get rid of deploying whenver we scale/downscale redis cluster

One simple solution I can think of is to save the cluster information when connecting to cluster for the first time using CLUSTER INFO/CLUSTER SLOTS command. Then periodically run this command and if there is any change in the cluster we can refresh the connections.

Use cases

  • In today's world we upscale/downscale our data stores on the fly so it becomes cumbersome to redeploy micro-services after each scaling activity. This feature will remove the need to redeploy micro-services when scaling a redis cluster

Contribution

I am willing to contribute to this feature.

@pmlopes
Copy link
Member

pmlopes commented Jan 21, 2022

Hi @akshaypatidar1999 thanks for your issue. This is indeed a highly requested feature. We can break the task into 2 areas:

  • have the cluster discovery code run as a "singleton" per redis client instance
  • close the client should become an asynchronous call to ensure that any discovery task is close properly

The same, similar logic should also apply to sentinel mode.

This also means that the static factories createClient() : Redis should become asynchronous too, as we may need to perform discovery for cluster/sentinel.

So, we either deprecate the old blocking API or leave it with a warning on the javadoc that that mode will only work for single node or replication mode.

@pmlopes pmlopes added this to the 4.3.0 milestone Jan 21, 2022
@vietj vietj modified the milestones: 4.3.0, 4.3.1 May 12, 2022
@vietj vietj modified the milestones: 4.3.1, 4.3.2 May 25, 2022
@vietj vietj modified the milestones: 4.3.4, 4.3.5 Oct 1, 2022
@vietj vietj modified the milestones: 4.3.5, 4.4.0 Nov 18, 2022
@vietj vietj modified the milestones: 4.4.0, 4.4.1 Mar 2, 2023
@vietj vietj modified the milestones: 4.4.1, 4.4.2 Mar 31, 2023
@vietj vietj modified the milestones: 4.4.2, 4.4.3 May 12, 2023
@vietj vietj modified the milestones: 4.4.3, 4.4.4-SNAPSHOT, 4.4.4 Jun 7, 2023
@vietj vietj modified the milestones: 4.4.4, 4.4.5 Jun 22, 2023
@vietj vietj modified the milestones: 4.4.5, 4.4.6 Aug 30, 2023
@vietj vietj modified the milestones: 4.4.6, 4.5.0 Sep 12, 2023
@vietj vietj modified the milestones: 4.5.0, 4.5.1 Nov 15, 2023
@akshaypatidar1999
Copy link
Author

Is there any plan to pick this feature?
I am willing to contribute to this feature.

@vietj vietj modified the milestones: 4.5.1, 4.5.2 Dec 13, 2023
@vietj vietj modified the milestones: 4.5.2, 4.5.3 Jan 30, 2024
@vietj vietj modified the milestones: 4.5.3, 4.5.4 Feb 6, 2024
@vietj vietj modified the milestones: 4.5.4, 4.5.5 Feb 22, 2024
@vietj vietj modified the milestones: 4.5.5, 4.5.6 Mar 14, 2024
@vietj vietj modified the milestones: 4.5.6, 4.5.7, 4.5.8 Mar 21, 2024
@ivivanov-bg
Copy link

Are there any plans for implementing this ?
We are facing similar issue in quarkus when the bitnami redis running in sentinel mode switches the master node.

I assume the root cause is the same as described here

@akshaypatidar1999
Copy link
Author

akshaypatidar1999 commented Apr 19, 2024

@pmlopes @vietj I will happy to contribute to this feature. We have internally created a wrapper over vertx redis client in which we periodically fetch the cluster state using CLUSTER SLOTS and CLUSTER INFO command and store the state in memory. Whenever we detect any change in the state we create new connections to the redis cluster and close existing connections gracefully. Similar approach can be used here. What do you gus think?

@ivivanov-bg
Copy link

@akshaypatidar1999
If you have any ideas - I guess you can fork the repo and create a PR

@vietj vietj modified the milestones: 4.5.8, 4.5.9 May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants