Skip to content

About ping command routing in validateConnection with Redis Cluster #3081

@zchazc

Description

@zchazc

Environments:

  • spring-data-redis 2.2.0.RELEASE
  • lettuce 5.2.0.RELEASE (with validateConnection and autoTopologyRefresh enabled - periodic and all triggers)
  • redis 4.0.14 (3 masters, 3 slaves)

Issue:

When using RedisTemplate.execute(conn->conn.incrBy(key,delt)), I observed that some microservices PING a slave node before sending the INCR command to the correct master node.

Through debugging, I found the following logic: The PING command uses the defaultWriter because it has no parameters, unlike the INCR command which is routed to a specific master node.

    return dispatch(commandBuilder.ping());

https://github.com/redis/lettuce/blob/55ebef8b5c095869aecf8cea8eb9eb5da585badf/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L999

// exclude CLIENT commands from cluster routing
        if (args != null && !CommandType.CLIENT.equals(commandToSend.getType())) {

https://github.com/redis/lettuce/blob/55ebef8b5c095869aecf8cea8eb9eb5da585badf/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java#L114-L115

  • 6.5.1.RELEASE
    return dispatch(commandBuilder.ping());

https://github.com/redis/lettuce/blob/b396f621cbc6e88cd50e9e117addcaecf040abca/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java#L1902

// exclude CLIENT commands from cluster routing
        if (args != null && !CommandType.CLIENT.equals(commandToSend.getType())) {

https://github.com/redis/lettuce/blob/b396f621cbc6e88cd50e9e117addcaecf040abca/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java#L172-L173

I suspect this behavior is due to the routing logic shown above.
I've been searched Google for "spring-data-redis validateConnection ping" and "spring-data-redis validateConnection ping slave", and also searched for "validateConnection" in the issues, but found no relevant information.

Questions

  • Is my analysis of the routing mechanism correct?
  • Is it intended that validateConnection sends PING command through defaultWriter instead of using the same connection as the subsequent command?

I'm currently diving deeper into the source code. Any insights or confirmation would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions