MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sentinelCheckSubjectivelyDown

Function sentinelCheckSubjectivelyDown

src/sentinel.cpp:4180–4244  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 3

sentinelEventFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected