-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
App remains connected to wrong Redis node after failover which leads to writing against read-only replica #2668
Comments
Thanks for reaching out. I'm not exactly sure how well the timestamps line up. However, I see that at The simple mode detects reconfiguration from disconnects. You could switch to the advanced Master/Replica mode that subscribes to Sentinels via Pub/Sub but that will add more complexity to the setup and additional Redis connections. You can achieve this by configuring a |
Ok, I will try that, thanks. |
Ok, this seems to be working as suggested, however I'm curious how to switch to master/replica mode with sentinels subscription ? Many thanks. |
Hi @mariusstaicu -
After reviewing your earlier/initial issue(s) and reading Mark's comments, this is what I take from the conversation. Regarding...
With Spring Data Redis in the context of Spring Boot (in your case, Under-the-hood, this is going to use the Spring Data (SD) Redis,
If you need programmatical control of the @SpringBootConfiguration
class ApplicationRedisConfiguration {
@Bean
RedisSentinelConfiguration redisSentinelConfiguration(..) {
// ...
}
} That is the fundamental premise of the logic behind this along with this. Otherwise, Spring Boot simply creates a new
As you know, Redis Sentinel is in charge of the master and replicas making up your topology (as determined (in part) by the In addition, Lettuce automatically subscribes to Sentinels on your behalf, as documented. Also see here along with this. Therefore, after reading this, and TMK, there is no additional configuration required using SD Redis to "subscribe" to Sentinels when using Lettuce. Finally, it is the Lettuce's Mark referred to setting the However, when using Spring Boot, you would simply declare a @SpringBootConfiguration
class ApplicationRedisConfiguration {
@Bean
LettuceClientConfigurationBuilderCustomizer lettuceClientConfigurationBuilderCustomizer(..) {
return lettuceClientConfigurationBuilder ->
lettuceClientConfigurationBuilder.readFrom(ReadFrom.MASTER);
}
} Clearly, you can customize the Please refer to the Lettuce
I hope this helps. For the time being, I am going to close this ticket as complete. For any additional questions, please continue the conversation StackOverflow for all users to benefit. Things can easily get lost in SD Redis Issue tickets and PRs. If you have additional issues, please re-open this ticket, or better yet, open a new ticket, as necessary. Thank you |
Wow, @jxblum thanks for the very detailed and elaborate response, I very much appreciate it. I didn't have time to get in all the links you posted but I soon will. What I did not get the first time is that, by using ReadFrom.MASTER, it will actually use the Master/Replica mode that will subscribe to events from sentinel and be updated in real time of any Redis master/replica changes. This is what I needed and it works perfectly now. Thank you again for your elaborate answer and for taking the time to explain. :) |
Hi @mariusstaicu - Glad to hear that everything is working correctly for you now! Also glad to help. I gather that Redis always makes writes to the Master node, unless configured otherwise. So, by using a setting of In any case, I am glad you are on the right track now. Cheers! |
We're using spring boot app with redis support via lettuce to connect to a redis sentinel deployment in kubernetes. The spring-boot version is 2.7.12.
There are 3 sentinel nodes with 3 redis nodes in different pods.
There is a very specific scenario with a 30-40% reproduction rate in which the spring app remains connected to the former master node after a failover which leads to being unable to write to readonly replica.
The scenario is as follows:
The implementation of the spring app is standard and it connects to a k8s service pointing to the sentinel nodes.
There is a little customization for spring redis that overrides default serializer used by RedisTemplate and replaces it with Jackson and another one that sets up a message listener for some redis keys expiration events, however I don't think this is relevant here.
Logs:
1. sentinel logs
2. spring app logs
The text was updated successfully, but these errors were encountered: