Search code examples
javaredislettuce

Lettuce fail over in cluster


I am trying to get Lettuce to connect to the newly promoted master (former slave) after the old one failed. But all writes stop. The writes continue after the failed host reconnects, now as a slave. And it continues to write to the new master (former slave).

I tried setting periodic topology refreshes, as well as adaptive ones on all events but it didn't help. Is there another setting I have to use?

This is how I configured the client:

final List<RedisURI> redisURIs = buildRedisURIs(redisServerSettings.getNodes());
final RedisClusterClient client = RedisClusterClient.create(clientResources, redisURIs);
final ClusterTopologyRefreshOptions refreshOptions =
        ClusterTopologyRefreshOptions.builder()
                                     .enableAllAdaptiveRefreshTriggers()
                                     .adaptiveRefreshTriggersTimeout(Duration.ofMinutes(2))
                                     .refreshTriggersReconnectAttempts(2)
                                     .enablePeriodicRefresh(Duration.ofMinutes(10))
                                     .build();
client.setOptions(ClusterClientOptions.builder().topologyRefreshOptions(refreshOptions).build());

Solution

  • I solved the problem.

    Because lettuce doesn't have a timeout normally, it waited forever for the response from the server. Setting the timeout caused some transactions to fail but after the failed transactions, the reads and writes continued.