redisredis-sentinel

Why don't sentinels subscribe channel "__sentinel__:hello" in sentinelReconnectInstance


When looking into Redis's source code, I find when sentinelRedisInstance is SRI_SENTINEL, sentinelReconnectInstance will not initialize its link->pc and will not subscribe channel "__sentinel__:hello", as the following code shows.

void sentinelReconnectInstance(sentinelRedisInstance *ri) {
    ...

    if ((ri->flags & (SRI_MASTER|SRI_SLAVE)) && link->pc == NULL) {
    ...
            retval = redisAsyncCommand(link->pc,
                sentinelReceiveHelloMessages, ri, "%s %s",
                sentinelInstanceMapCommand(ri,"SUBSCRIBE"),
                SENTINEL_HELLO_CHANNEL);
    ...


As a result, I think sentinels can't get any message from channel "__sentinel__:hello".

However, in redis's doc, it says

Every Sentinel is subscribed to the Pub/Sub channel sentinel:hello of every master and replica, looking for unknown sentinels. When new sentinels are detected, they are added as sentinels of this master.

I think it means that all sentinels actually subscribe to channel "__sentinel__:hello", but I can't see any corresponding implementation in redis's source code.


Solution

  • Correct me if I'm wrong.

    sentinelRedisInstance of type SRI_MASTER connects to master node that this sentinel is monitoring, sentinelRedisInstance of type SRI_SLAVE connects to slave node, and sentinelRedisInstance of type SRI_SENTINEL connects to other sentinels.

    There's no need to subscribe to sentinel's channel, instead, sentinels only need to subscribe to channels of master and slave nodes. If there's a new sentinel, it will publish hello message to master and slave's channel. So that other sentinels will discover them.