Skip to content

Commit

Permalink
Sentinel: limit reconnection frequency to the ping period
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed May 13, 2015
1 parent 0eb0b55 commit 3ab4989
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ typedef struct instanceLink {
mstime_t last_pong_time; /* Last time the instance replied to ping,
whatever the reply was. That's used to check
if the link is idle and must be reconnected. */
mstime_t last_reconn_time; /* Last reconnection attempt performed when
the link was down. */
} instanceLink;

typedef struct sentinelRedisInstance {
Expand Down Expand Up @@ -921,6 +923,7 @@ instanceLink *createInstanceLink(void) {
link->pc = NULL;
link->cc_conn_time = 0;
link->pc_conn_time = 0;
link->last_reconn_time = 0;
link->pc_last_activity = 0;
/* We set the last_ping_time to "now" even if we actually don't have yet
* a connection with the node, nor we sent a ping.
Expand Down Expand Up @@ -1826,6 +1829,10 @@ void sentinelSetClientName(sentinelRedisInstance *ri, redisAsyncContext *c, char
void sentinelReconnectInstance(sentinelRedisInstance *ri) {
if (ri->link->disconnected == 0) return;
instanceLink *link = ri->link;
mstime_t now = mstime();

if (now - ri->link->last_reconn_time < SENTINEL_PING_PERIOD) return;
ri->link->last_reconn_time = now;

/* Commands connection. */
if (link->cc == NULL) {
Expand Down

0 comments on commit 3ab4989

Please sign in to comment.