MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sentinelCheckSubjectivelyDown

Function sentinelCheckSubjectivelyDown

app/redis-6.2.6/src/sentinel.c:4168–4232  ·  view source on GitHub ↗

Is this instance down from our point of view? */

Source from the content-addressed store, hash-verified

4166
4167/* Is this instance down from our point of view? */
4168void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
4169 mstime_t elapsed = 0;
4170
4171 if (ri->link->act_ping_time)
4172 elapsed = mstime() - ri->link->act_ping_time;
4173 else if (ri->link->disconnected)
4174 elapsed = mstime() - ri->link->last_avail_time;
4175
4176 /* Check if we are in need for a reconnection of one of the
4177 * links, because we are detecting low activity.
4178 *
4179 * 1) Check if the command link seems connected, was connected not less
4180 * than SENTINEL_MIN_LINK_RECONNECT_PERIOD, but still we have a
4181 * pending ping for more than half the timeout. */
4182 if (ri->link->cc &&
4183 (mstime() - ri->link->cc_conn_time) >
4184 SENTINEL_MIN_LINK_RECONNECT_PERIOD &&
4185 ri->link->act_ping_time != 0 && /* There is a pending ping... */
4186 /* The pending ping is delayed, and we did not receive
4187 * error replies as well. */
4188 (mstime() - ri->link->act_ping_time) > (ri->down_after_period/2) &&
4189 (mstime() - ri->link->last_pong_time) > (ri->down_after_period/2))
4190 {
4191 instanceLinkCloseConnection(ri->link,ri->link->cc);
4192 }
4193
4194 /* 2) Check if the pubsub link seems connected, was connected not less
4195 * than SENTINEL_MIN_LINK_RECONNECT_PERIOD, but still we have no
4196 * activity in the Pub/Sub channel for more than
4197 * SENTINEL_PUBLISH_PERIOD * 3.
4198 */
4199 if (ri->link->pc &&
4200 (mstime() - ri->link->pc_conn_time) >
4201 SENTINEL_MIN_LINK_RECONNECT_PERIOD &&
4202 (mstime() - ri->link->pc_last_activity) > (SENTINEL_PUBLISH_PERIOD*3))
4203 {
4204 instanceLinkCloseConnection(ri->link,ri->link->pc);
4205 }
4206
4207 /* Update the SDOWN flag. We believe the instance is SDOWN if:
4208 *
4209 * 1) It is not replying.
4210 * 2) We believe it is a master, it reports to be a slave for enough time
4211 * to meet the down_after_period, plus enough time to get two times
4212 * INFO report from the instance. */
4213 if (elapsed > ri->down_after_period ||
4214 (ri->flags & SRI_MASTER &&
4215 ri->role_reported == SRI_SLAVE &&
4216 mstime() - ri->role_reported_time >
4217 (ri->down_after_period+SENTINEL_INFO_PERIOD*2)))
4218 {
4219 /* Is subjectively down */
4220 if ((ri->flags & SRI_S_DOWN) == 0) {
4221 sentinelEvent(LL_WARNING,"+sdown",ri,"%@");
4222 ri->s_down_since_time = mstime();
4223 ri->flags |= SRI_S_DOWN;
4224 }
4225 } else {

Callers 1

Calls 3

sentinelEventFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected