Send periodic PING, INFO, and PUBLISH to the Hello channel to * the specified master or slave instance. */
| 3099 | /* Send periodic PING, INFO, and PUBLISH to the Hello channel to |
| 3100 | * the specified master or slave instance. */ |
| 3101 | void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) { |
| 3102 | mstime_t now = mstime(); |
| 3103 | mstime_t info_period, ping_period; |
| 3104 | int retval; |
| 3105 | |
| 3106 | /* Return ASAP if we have already a PING or INFO already pending, or |
| 3107 | * in the case the instance is not properly connected. */ |
| 3108 | if (ri->link->disconnected) return; |
| 3109 | |
| 3110 | /* For INFO, PING, PUBLISH that are not critical commands to send we |
| 3111 | * also have a limit of SENTINEL_MAX_PENDING_COMMANDS. We don't |
| 3112 | * want to use a lot of memory just because a link is not working |
| 3113 | * properly (note that anyway there is a redundant protection about this, |
| 3114 | * that is, the link will be disconnected and reconnected if a long |
| 3115 | * timeout condition is detected. */ |
| 3116 | if (ri->link->pending_commands >= |
| 3117 | SENTINEL_MAX_PENDING_COMMANDS * ri->link->refcount) return; |
| 3118 | |
| 3119 | /* If this is a slave of a master in O_DOWN condition we start sending |
| 3120 | * it INFO every second, instead of the usual SENTINEL_INFO_PERIOD |
| 3121 | * period. In this state we want to closely monitor slaves in case they |
| 3122 | * are turned into masters by another Sentinel, or by the sysadmin. |
| 3123 | * |
| 3124 | * Similarly we monitor the INFO output more often if the slave reports |
| 3125 | * to be disconnected from the master, so that we can have a fresh |
| 3126 | * disconnection time figure. */ |
| 3127 | if ((ri->flags & SRI_SLAVE) && |
| 3128 | ((ri->master->flags & (SRI_O_DOWN|SRI_FAILOVER_IN_PROGRESS)) || |
| 3129 | (ri->master_link_down_time != 0))) |
| 3130 | { |
| 3131 | info_period = 1000; |
| 3132 | } else { |
| 3133 | info_period = SENTINEL_INFO_PERIOD; |
| 3134 | } |
| 3135 | |
| 3136 | /* We ping instances every time the last received pong is older than |
| 3137 | * the configured 'down-after-milliseconds' time, but every second |
| 3138 | * anyway if 'down-after-milliseconds' is greater than 1 second. */ |
| 3139 | ping_period = ri->down_after_period; |
| 3140 | if (ping_period > SENTINEL_PING_PERIOD) ping_period = SENTINEL_PING_PERIOD; |
| 3141 | |
| 3142 | /* Send INFO to masters and slaves, not sentinels. */ |
| 3143 | if ((ri->flags & SRI_SENTINEL) == 0 && |
| 3144 | (ri->info_refresh == 0 || |
| 3145 | (now - ri->info_refresh) > info_period)) |
| 3146 | { |
| 3147 | retval = redisAsyncCommand(ri->link->cc, |
| 3148 | sentinelInfoReplyCallback, ri, "%s", |
| 3149 | sentinelInstanceMapCommand(ri,"INFO")); |
| 3150 | if (retval == C_OK) ri->link->pending_commands++; |
| 3151 | } |
| 3152 | |
| 3153 | /* Send PING to all the three kinds of instances. */ |
| 3154 | if ((now - ri->link->last_pong_time) > ping_period && |
| 3155 | (now - ri->link->last_ping_time) > ping_period/2) { |
| 3156 | sentinelSendPing(ri); |
| 3157 | } |
| 3158 |
no test coverage detected