0

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.

calvin
  • 2,125
  • 2
  • 21
  • 38

1 Answers1

1

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.

for_stack
  • 21,012
  • 4
  • 35
  • 48
  • Do you mean for a master instance, it establish both pc and cc links to the master node it is monitoring, so there will be 2 links in total. For a slave node, there are also 2. However for a sentinel instance, it will establish `countOfAllOtherNoSentinels` pc links to all other master/slave nodes, and `countOfAllOtherInstances` cc links to all other nodes? – calvin Oct 23 '20 at 05:57
  • Yes, it establishes 2 links for each master and replica – for_stack Oct 23 '20 at 11:26
  • If I am correct here, I am confused with another issue. Because in redis's source code it says if 5 Sentinels are monitoring 100 masters, there will be only 5 connections rather than 500. However I think for each Sentinel, it will establish 1 `cc` and 1 `pc` to each master, so there should be 2 * 100 * 5 connections in total – calvin Oct 23 '20 at 11:48
  • I think the comment is describing connections between sentinels, not connection to master/slave. – for_stack Oct 24 '20 at 08:19
  • I still can't figure out how to establish 5 connections among 5 sentinels, I think if there are one cc connection between each of them, there should be `5*4/2=10` connections, rather than 5 conenctions – calvin Oct 24 '20 at 15:30
  • Hi, I read code from `sentinelTryConnectionSharing`, and have some understanding here, but I don't know whether I am right. I think the 5 connections means 5 sentinels other than me, and I have to establish 5 links to them. Then I can create 5 `redisSentinelInstance` object for each of the sentinels. Each of the `redisSentinelInstance` object will reuse link my links in `sentinelState.masters.link`? So for every sentinel process, there will be only one cc and one pc link to one master? – calvin Oct 29 '20 at 12:34