Working with sentinels: the master changes to another server
Hi,
I'm using the ConnectionMultiplexer.SentinelConnect and this works as expected (given any sentinel server order in the connection string, I can retrieve a sentinel connection and then a master connection with GetSentinelMasterConnection.
I am storing this last connection multiplexer as documented (the multiplexer is designed to be reused). The problem I'm currently experimenting is as follows: I have 3 sentinels (host1, host2, host3), host1 is the master. Everything works fine now (any combination of hosts in my connection string will work as the multiplexer always retrieves the right master) When the master changes (for example, in a Kubernetes environment using redis-ha a pod is deleted, the another pod is chosen as master) Then my multiplexer is not valid anymore.
Is there a way to check if the connection multiplexer for the master is still the master?
Hi,
I'm using the ConnectionMultiplexer.SentinelConnect and this works as expected (given any sentinel server order in the connection string, I can retrieve a sentinel connection and then a master connection with GetSentinelMasterConnection.
I am storing this last connection multiplexer as documented (the multiplexer is designed to be reused). The problem I'm currently experimenting is as follows: I have 3 sentinels (host1, host2, host3), host1 is the master. Everything works fine now (any combination of hosts in my connection string will work as the multiplexer always retrieves the right master) When the master changes (for example, in a Kubernetes environment using redis-ha a pod is deleted, the another pod is chosen as master) Then my multiplexer is not valid anymore.
Is there a way to check if the connection multiplexer for the master is still the master?
Couldn't find a nice way to do this but we can subscribe to an event instead of polling to check the connection. see https://github.com/StackExchange/StackExchange.Redis/issues/1582#issuecomment-707614401
this approach still doesn't work.
@emi662002: Did you have any success? I am in a similiar situation and the "configure" through "ConnectionFailed" does not help. He still works with an old IP.
@emi662002: Did you have any success? I am in a similiar situation and the "configure" through "ConnectionFailed" does not help. He still works with an old IP.
Well, i don't know if it works. I have the code there just in case. What I do to force it is on the healthcheck fail on K8s, just initialise the Redis connection again: basically:
Healthcheck:
try
{
var redisConnection = await cacheFactory.GetRedisConnection();
await redisConnection.GetDatabase().PingAsync();
return new HealthCheckResult(HealthStatus.Healthy);
}
catch (Exception ex)
{
await TryRestore(cacheFactory);
return Unhealthy(ex);
}
Kill connection on healthcheck failed (TryRestore calls this on another class but for simplification):
await this.connection.CloseAsync(false);
this.connection.Dispose();
this.connection = null;
We listen for the Sentinel pub/sub messages to proactively reconnect to any changes in the usual case here, so I'd like to understand better. Can you share how you're connecting? e.g. "Sentinel A and B, servers F, G, H" and let us know how you're connecting, e.g. connecting string especially?
We listen for the Sentinel pub/sub messages to proactively reconnect to any changes in the usual case here, so I'd like to understand better. Can you share how you're connecting? e.g. "Sentinel A and B, servers F, G, H" and let us know how you're connecting, e.g. connecting string especially?
please see: https://github.com/StackExchange/StackExchange.Redis/issues/1582#issuecomment-866628163
@emi662002 Several Sentinel fixes went in since that issue was filed and comment you linked to - which version of the library are you on? Are you still having trouble in the latest version?
If anyone's still hitting issues here, please try and latest release - it has a great number of Sentinel fixes along the way. Closing this issue out to tidy up.
Hi @NickCraver
I can reproduce this exactly behavior using version 2.5.43.
Do you prefer that I open other issue?