Unverified Commit 63e2a6d2 authored by Wen Hui's avatar Wen Hui Committed by GitHub
Browse files

Add sentinel debug option command (#9291)



This makes it possible to tune many parameters that were previously hard coded.
We don't intend these to be user configurable, but only used by tests to accelerate certain conditions which would otherwise take a long time and slow down the test suite.
Co-authored-by: default avatarLucas Guang Yang <l84193800@china.huawei.com>
parent ca559819
...@@ -78,21 +78,27 @@ typedef struct sentinelAddr { ...@@ -78,21 +78,27 @@ typedef struct sentinelAddr {
#define SRI_SCRIPT_KILL_SENT (1<<12) /* SCRIPT KILL already sent on -BUSY */ #define SRI_SCRIPT_KILL_SENT (1<<12) /* SCRIPT KILL already sent on -BUSY */
/* Note: times are in milliseconds. */ /* Note: times are in milliseconds. */
#define SENTINEL_INFO_PERIOD 10000
#define SENTINEL_PING_PERIOD 1000 #define SENTINEL_PING_PERIOD 1000
#define SENTINEL_ASK_PERIOD 1000
#define SENTINEL_PUBLISH_PERIOD 2000 static mstime_t sentinel_info_period = 10000;
#define SENTINEL_DEFAULT_DOWN_AFTER 30000 static mstime_t sentinel_ping_period = SENTINEL_PING_PERIOD;
static mstime_t sentinel_ask_period = 1000;
static mstime_t sentinel_publish_period = 2000;
static mstime_t sentinel_default_down_after = 30000;
static mstime_t sentinel_tilt_trigger = 2000;
static mstime_t sentinel_tilt_period = SENTINEL_PING_PERIOD * 30;
static mstime_t sentinel_slave_reconf_timeout = 10000;
static mstime_t sentinel_min_link_reconnect_period = 15000;
static mstime_t sentinel_election_timeout = 10000;
static mstime_t sentinel_script_max_runtime = 60000; /* 60 seconds max exec time. */
static mstime_t sentinel_script_retry_delay = 30000; /* 30 seconds between retries. */
static mstime_t sentinel_default_failover_timeout = 60*3*1000;
#define SENTINEL_HELLO_CHANNEL "__sentinel__:hello" #define SENTINEL_HELLO_CHANNEL "__sentinel__:hello"
#define SENTINEL_TILT_TRIGGER 2000
#define SENTINEL_TILT_PERIOD (SENTINEL_PING_PERIOD*30)
#define SENTINEL_DEFAULT_SLAVE_PRIORITY 100 #define SENTINEL_DEFAULT_SLAVE_PRIORITY 100
#define SENTINEL_SLAVE_RECONF_TIMEOUT 10000
#define SENTINEL_DEFAULT_PARALLEL_SYNCS 1 #define SENTINEL_DEFAULT_PARALLEL_SYNCS 1
#define SENTINEL_MIN_LINK_RECONNECT_PERIOD 15000
#define SENTINEL_DEFAULT_FAILOVER_TIMEOUT (60*3*1000)
#define SENTINEL_MAX_PENDING_COMMANDS 100 #define SENTINEL_MAX_PENDING_COMMANDS 100
#define SENTINEL_ELECTION_TIMEOUT 10000
#define SENTINEL_MAX_DESYNC 1000 #define SENTINEL_MAX_DESYNC 1000
#define SENTINEL_DEFAULT_DENY_SCRIPTS_RECONFIG 1 #define SENTINEL_DEFAULT_DENY_SCRIPTS_RECONFIG 1
#define SENTINEL_DEFAULT_RESOLVE_HOSTNAMES 0 #define SENTINEL_DEFAULT_RESOLVE_HOSTNAMES 0
...@@ -123,9 +129,7 @@ typedef struct sentinelAddr { ...@@ -123,9 +129,7 @@ typedef struct sentinelAddr {
#define SENTINEL_SCRIPT_RUNNING 1 #define SENTINEL_SCRIPT_RUNNING 1
#define SENTINEL_SCRIPT_MAX_QUEUE 256 #define SENTINEL_SCRIPT_MAX_QUEUE 256
#define SENTINEL_SCRIPT_MAX_RUNNING 16 #define SENTINEL_SCRIPT_MAX_RUNNING 16
#define SENTINEL_SCRIPT_MAX_RUNTIME 60000 /* 60 seconds max exec time. */
#define SENTINEL_SCRIPT_MAX_RETRY 10 #define SENTINEL_SCRIPT_MAX_RETRY 10
#define SENTINEL_SCRIPT_RETRY_DELAY 30000 /* 30 seconds between retries. */
/* SENTINEL SIMULATE-FAILURE command flags. */ /* SENTINEL SIMULATE-FAILURE command flags. */
#define SENTINEL_SIMFAILURE_NONE 0 #define SENTINEL_SIMFAILURE_NONE 0
...@@ -891,7 +895,7 @@ void sentinelRunPendingScripts(void) { ...@@ -891,7 +895,7 @@ void sentinelRunPendingScripts(void) {
* starting from the second attempt to execute the script the delays are: * starting from the second attempt to execute the script the delays are:
* 30 sec, 60 sec, 2 min, 4 min, 8 min, 16 min, 32 min, 64 min, 128 min. */ * 30 sec, 60 sec, 2 min, 4 min, 8 min, 16 min, 32 min, 64 min, 128 min. */
mstime_t sentinelScriptRetryDelay(int retry_num) { mstime_t sentinelScriptRetryDelay(int retry_num) {
mstime_t delay = SENTINEL_SCRIPT_RETRY_DELAY; mstime_t delay = sentinel_script_retry_delay;
while (retry_num-- > 1) delay *= 2; while (retry_num-- > 1) delay *= 2;
return delay; return delay;
...@@ -958,7 +962,7 @@ void sentinelKillTimedoutScripts(void) { ...@@ -958,7 +962,7 @@ void sentinelKillTimedoutScripts(void) {
sentinelScriptJob *sj = ln->value; sentinelScriptJob *sj = ln->value;
if (sj->flags & SENTINEL_SCRIPT_RUNNING && if (sj->flags & SENTINEL_SCRIPT_RUNNING &&
(now - sj->start_time) > SENTINEL_SCRIPT_MAX_RUNTIME) (now - sj->start_time) > sentinel_script_max_runtime)
{ {
sentinelEvent(LL_WARNING,"-script-timeout",NULL,"%s %ld", sentinelEvent(LL_WARNING,"-script-timeout",NULL,"%s %ld",
sj->argv[0], (long)sj->pid); sj->argv[0], (long)sj->pid);
...@@ -1335,7 +1339,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char * ...@@ -1335,7 +1339,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
ri->s_down_since_time = 0; ri->s_down_since_time = 0;
ri->o_down_since_time = 0; ri->o_down_since_time = 0;
ri->down_after_period = master ? master->down_after_period : ri->down_after_period = master ? master->down_after_period :
SENTINEL_DEFAULT_DOWN_AFTER; sentinel_default_down_after;
ri->master_link_down_time = 0; ri->master_link_down_time = 0;
ri->auth_pass = NULL; ri->auth_pass = NULL;
ri->auth_user = NULL; ri->auth_user = NULL;
...@@ -1361,7 +1365,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char * ...@@ -1361,7 +1365,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
ri->failover_state = SENTINEL_FAILOVER_STATE_NONE; ri->failover_state = SENTINEL_FAILOVER_STATE_NONE;
ri->failover_state_change_time = 0; ri->failover_state_change_time = 0;
ri->failover_start_time = 0; ri->failover_start_time = 0;
ri->failover_timeout = SENTINEL_DEFAULT_FAILOVER_TIMEOUT; ri->failover_timeout = sentinel_default_failover_timeout;
ri->failover_delay_logged = 0; ri->failover_delay_logged = 0;
ri->promoted_slave = NULL; ri->promoted_slave = NULL;
ri->notification_script = NULL; ri->notification_script = NULL;
...@@ -2095,7 +2099,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) { ...@@ -2095,7 +2099,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
/* rewriteConfigMarkAsProcessed is handled after the loop */ /* rewriteConfigMarkAsProcessed is handled after the loop */
/* sentinel down-after-milliseconds */ /* sentinel down-after-milliseconds */
if (master->down_after_period != SENTINEL_DEFAULT_DOWN_AFTER) { if (master->down_after_period != sentinel_default_down_after) {
line = sdscatprintf(sdsempty(), line = sdscatprintf(sdsempty(),
"sentinel down-after-milliseconds %s %ld", "sentinel down-after-milliseconds %s %ld",
master->name, (long) master->down_after_period); master->name, (long) master->down_after_period);
...@@ -2104,7 +2108,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) { ...@@ -2104,7 +2108,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
} }
/* sentinel failover-timeout */ /* sentinel failover-timeout */
if (master->failover_timeout != SENTINEL_DEFAULT_FAILOVER_TIMEOUT) { if (master->failover_timeout != sentinel_default_failover_timeout) {
line = sdscatprintf(sdsempty(), line = sdscatprintf(sdsempty(),
"sentinel failover-timeout %s %ld", "sentinel failover-timeout %s %ld",
master->name, (long) master->failover_timeout); master->name, (long) master->failover_timeout);
...@@ -2402,7 +2406,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { ...@@ -2402,7 +2406,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
instanceLink *link = ri->link; instanceLink *link = ri->link;
mstime_t now = mstime(); mstime_t now = mstime();
if (now - ri->link->last_reconn_time < SENTINEL_PING_PERIOD) return; if (now - ri->link->last_reconn_time < sentinel_ping_period) return;
ri->link->last_reconn_time = now; ri->link->last_reconn_time = now;
/* Commands connection. */ /* Commands connection. */
...@@ -2490,7 +2494,7 @@ int sentinelMasterLooksSane(sentinelRedisInstance *master) { ...@@ -2490,7 +2494,7 @@ int sentinelMasterLooksSane(sentinelRedisInstance *master) {
master->flags & SRI_MASTER && master->flags & SRI_MASTER &&
master->role_reported == SRI_MASTER && master->role_reported == SRI_MASTER &&
(master->flags & (SRI_S_DOWN|SRI_O_DOWN)) == 0 && (master->flags & (SRI_S_DOWN|SRI_O_DOWN)) == 0 &&
(mstime() - master->info_refresh) < SENTINEL_INFO_PERIOD*2; (mstime() - master->info_refresh) < sentinel_info_period*2;
} }
/* Process the INFO output from masters. */ /* Process the INFO output from masters. */
...@@ -2683,7 +2687,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { ...@@ -2683,7 +2687,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
/* A slave turned into a master. We want to force our view and /* A slave turned into a master. We want to force our view and
* reconfigure as slave. Wait some time after the change before * reconfigure as slave. Wait some time after the change before
* going forward, to receive new configs if any. */ * going forward, to receive new configs if any. */
mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4; mstime_t wait_time = sentinel_publish_period*4;
if (!(ri->flags & SRI_PROMOTED) && if (!(ri->flags & SRI_PROMOTED) &&
sentinelMasterLooksSane(ri->master) && sentinelMasterLooksSane(ri->master) &&
...@@ -3024,8 +3028,8 @@ void sentinelForceHelloUpdateDictOfRedisInstances(dict *instances) { ...@@ -3024,8 +3028,8 @@ void sentinelForceHelloUpdateDictOfRedisInstances(dict *instances) {
di = dictGetSafeIterator(instances); di = dictGetSafeIterator(instances);
while((de = dictNext(di)) != NULL) { while((de = dictNext(di)) != NULL) {
sentinelRedisInstance *ri = dictGetVal(de); sentinelRedisInstance *ri = dictGetVal(de);
if (ri->last_pub_time >= (SENTINEL_PUBLISH_PERIOD+1)) if (ri->last_pub_time >= (sentinel_publish_period+1))
ri->last_pub_time -= (SENTINEL_PUBLISH_PERIOD+1); ri->last_pub_time -= (sentinel_publish_period+1);
} }
dictReleaseIterator(di); dictReleaseIterator(di);
} }
...@@ -3040,8 +3044,8 @@ void sentinelForceHelloUpdateDictOfRedisInstances(dict *instances) { ...@@ -3040,8 +3044,8 @@ void sentinelForceHelloUpdateDictOfRedisInstances(dict *instances) {
* to the other Sentinels ASAP. */ * to the other Sentinels ASAP. */
int sentinelForceHelloUpdateForMaster(sentinelRedisInstance *master) { int sentinelForceHelloUpdateForMaster(sentinelRedisInstance *master) {
if (!(master->flags & SRI_MASTER)) return C_ERR; if (!(master->flags & SRI_MASTER)) return C_ERR;
if (master->last_pub_time >= (SENTINEL_PUBLISH_PERIOD+1)) if (master->last_pub_time >= (sentinel_publish_period+1))
master->last_pub_time -= (SENTINEL_PUBLISH_PERIOD+1); master->last_pub_time -= (sentinel_publish_period+1);
sentinelForceHelloUpdateDictOfRedisInstances(master->sentinels); sentinelForceHelloUpdateDictOfRedisInstances(master->sentinels);
sentinelForceHelloUpdateDictOfRedisInstances(master->slaves); sentinelForceHelloUpdateDictOfRedisInstances(master->slaves);
return C_OK; return C_OK;
...@@ -3104,14 +3108,14 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) { ...@@ -3104,14 +3108,14 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
{ {
info_period = 1000; info_period = 1000;
} else { } else {
info_period = SENTINEL_INFO_PERIOD; info_period = sentinel_info_period;
} }
/* We ping instances every time the last received pong is older than /* We ping instances every time the last received pong is older than
* the configured 'down-after-milliseconds' time, but every second * the configured 'down-after-milliseconds' time, but every second
* anyway if 'down-after-milliseconds' is greater than 1 second. */ * anyway if 'down-after-milliseconds' is greater than 1 second. */
ping_period = ri->down_after_period; ping_period = ri->down_after_period;
if (ping_period > SENTINEL_PING_PERIOD) ping_period = SENTINEL_PING_PERIOD; if (ping_period > sentinel_ping_period) ping_period = sentinel_ping_period;
/* Send INFO to masters and slaves, not sentinels. */ /* Send INFO to masters and slaves, not sentinels. */
if ((ri->flags & SRI_SENTINEL) == 0 && if ((ri->flags & SRI_SENTINEL) == 0 &&
...@@ -3131,7 +3135,7 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) { ...@@ -3131,7 +3135,7 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
} }
/* PUBLISH hello messages to all the three kinds of instances. */ /* PUBLISH hello messages to all the three kinds of instances. */
if ((now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD) { if ((now - ri->last_pub_time) > sentinel_publish_period) {
sentinelSendHello(ri); sentinelSendHello(ri);
} }
} }
...@@ -3445,6 +3449,215 @@ void addReplySentinelRedisInstance(client *c, sentinelRedisInstance *ri) { ...@@ -3445,6 +3449,215 @@ void addReplySentinelRedisInstance(client *c, sentinelRedisInstance *ri) {
setDeferredMapLen(c,mbl,fields); setDeferredMapLen(c,mbl,fields);
} }
void sentinelSetDebugConfigParameters(client *c){
int j;
int badarg = 0; /* Bad argument position for error reporting. */
char *option;
/* Process option - value pairs. */
for (j = 2; j < c->argc; j++) {
int moreargs = (c->argc-1) - j;
option = c->argv[j]->ptr;
long long ll;
if (!strcasecmp(option,"info-period") && moreargs > 0) {
/* info-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_info_period = ll;
} else if (!strcasecmp(option,"ping-period") && moreargs > 0) {
/* ping-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_ping_period = ll;
} else if (!strcasecmp(option,"ask-period") && moreargs > 0) {
/* ask-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_ask_period = ll;
} else if (!strcasecmp(option,"publish-period") && moreargs > 0) {
/* publish-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_publish_period = ll;
}else if (!strcasecmp(option,"default-down-after") && moreargs > 0) {
/* default-down-after <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_default_down_after = ll;
} else if (!strcasecmp(option,"tilt-trigger") && moreargs > 0) {
/* tilt-trigger <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_tilt_trigger = ll;
} else if (!strcasecmp(option,"tilt-period") && moreargs > 0) {
/* tilt-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_tilt_period = ll;
} else if (!strcasecmp(option,"slave-reconf-timeout") && moreargs > 0) {
/* slave-reconf-timeout <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_slave_reconf_timeout = ll;
} else if (!strcasecmp(option,"min-link-reconnect-period") && moreargs > 0) {
/* min-link-reconnect-period <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_min_link_reconnect_period = ll;
} else if (!strcasecmp(option,"default-failover-timeout") && moreargs > 0) {
/* default-failover-timeout <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_default_failover_timeout = ll;
} else if (!strcasecmp(option,"election-timeout") && moreargs > 0) {
/* election-timeout <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_election_timeout = ll;
} else if (!strcasecmp(option,"script-max-runtime") && moreargs > 0) {
/* script-max-runtime <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_script_max_runtime = ll;
} else if (!strcasecmp(option,"script-retry-delay") && moreargs > 0) {
/* script-retry-delay <milliseconds> */
robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
badarg = j;
goto badfmt;
}
sentinel_script_retry_delay = ll;
} else {
addReplyErrorFormat(c,"Unknown option or number of arguments for "
"SENTINEL SET '%s'", option);
}
}
addReply(c,shared.ok);
return;
badfmt: /* Bad format errors */
addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL SET '%s'",
(char*)c->argv[badarg]->ptr,option);
return;
}
void addReplySentinelDebugInfo(client *c) {
void *mbl;
int fields = 0;
mbl = addReplyDeferredLen(c);
addReplyBulkCString(c,"INFO-PERIOD");
addReplyBulkLongLong(c,sentinel_info_period);
fields++;
addReplyBulkCString(c,"PING-PERIOD");
addReplyBulkLongLong(c,sentinel_ping_period);
fields++;
addReplyBulkCString(c,"ASK-PERIOD");
addReplyBulkLongLong(c,sentinel_ask_period);
fields++;
addReplyBulkCString(c,"PUBLISH-PERIOD");
addReplyBulkLongLong(c,sentinel_publish_period);
fields++;
addReplyBulkCString(c,"DEFAULT-DOWN-AFTER");
addReplyBulkLongLong(c,sentinel_default_down_after);
fields++;
addReplyBulkCString(c,"DEFAULT-FAILOVER-TIMEOUT");
addReplyBulkLongLong(c,sentinel_default_failover_timeout);
fields++;
addReplyBulkCString(c,"TILT-TRIGGER");
addReplyBulkLongLong(c,sentinel_tilt_trigger);
fields++;
addReplyBulkCString(c,"TILT-PERIOD");
addReplyBulkLongLong(c,sentinel_tilt_period);
fields++;
addReplyBulkCString(c,"SLAVE-RECONF-TIMEOUT");
addReplyBulkLongLong(c,sentinel_slave_reconf_timeout);
fields++;
addReplyBulkCString(c,"MIN-LINK-RECONNECT-PERIOD");
addReplyBulkLongLong(c,sentinel_min_link_reconnect_period);
fields++;
addReplyBulkCString(c,"ELECTION-TIMEOUT");
addReplyBulkLongLong(c,sentinel_election_timeout);
fields++;
addReplyBulkCString(c,"SCRIPT-MAX-RUNTIME");
addReplyBulkLongLong(c,sentinel_script_max_runtime);
fields++;
addReplyBulkCString(c,"SCRIPT-RETRY-DELAY");
addReplyBulkLongLong(c,sentinel_script_retry_delay);
fields++;
setDeferredMapLen(c,mbl,fields);
}
/* Output a number of instances contained inside a dictionary as /* Output a number of instances contained inside a dictionary as
* Redis protocol. */ * Redis protocol. */
void addReplyDictOfRedisInstances(client *c, dict *instances) { void addReplyDictOfRedisInstances(client *c, dict *instances) {
...@@ -3518,6 +3731,8 @@ void sentinelCommand(client *c) { ...@@ -3518,6 +3731,8 @@ void sentinelCommand(client *c) {
" Set a global Sentinel configuration parameter.", " Set a global Sentinel configuration parameter.",
"CONFIG GET <param>", "CONFIG GET <param>",
" Get global Sentinel configuration parameter.", " Get global Sentinel configuration parameter.",
"DEBUG",
" Show a list of configurable time parameters and their values (milliseconds).",
"GET-MASTER-ADDR-BY-NAME <master-name>", "GET-MASTER-ADDR-BY-NAME <master-name>",
" Return the ip and port number of the master with that name.", " Return the ip and port number of the master with that name.",
"FAILOVER <master-name>", "FAILOVER <master-name>",
...@@ -3869,7 +4084,13 @@ NULL ...@@ -3869,7 +4084,13 @@ NULL
} }
} }
addReply(c,shared.ok); addReply(c,shared.ok);
} else { } else if (!strcasecmp(c->argv[1]->ptr,"debug")) {
if(c->argc == 2)
addReplySentinelDebugInfo(c);
else
sentinelSetDebugConfigParameters(c);
}
else {
addReplySubcommandSyntaxError(c); addReplySubcommandSyntaxError(c);
} }
return; return;
...@@ -4170,7 +4391,7 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) { ...@@ -4170,7 +4391,7 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
* pending ping for more than half the timeout. */ * pending ping for more than half the timeout. */
if (ri->link->cc && if (ri->link->cc &&
(mstime() - ri->link->cc_conn_time) > (mstime() - ri->link->cc_conn_time) >
SENTINEL_MIN_LINK_RECONNECT_PERIOD && sentinel_min_link_reconnect_period &&
ri->link->act_ping_time != 0 && /* There is a pending ping... */ ri->link->act_ping_time != 0 && /* There is a pending ping... */
/* The pending ping is delayed, and we did not receive /* The pending ping is delayed, and we did not receive
* error replies as well. */ * error replies as well. */
...@@ -4187,8 +4408,8 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) { ...@@ -4187,8 +4408,8 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
*/ */
if (ri->link->pc && if (ri->link->pc &&
(mstime() - ri->link->pc_conn_time) > (mstime() - ri->link->pc_conn_time) >
SENTINEL_MIN_LINK_RECONNECT_PERIOD && sentinel_min_link_reconnect_period &&
(mstime() - ri->link->pc_last_activity) > (SENTINEL_PUBLISH_PERIOD*3)) (mstime() - ri->link->pc_last_activity) > (sentinel_publish_period*3))
{ {
instanceLinkCloseConnection(ri->link,ri->link->pc); instanceLinkCloseConnection(ri->link,ri->link->pc);
} }
...@@ -4203,7 +4424,7 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) { ...@@ -4203,7 +4424,7 @@ void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
(ri->flags & SRI_MASTER && (ri->flags & SRI_MASTER &&
ri->role_reported == SRI_SLAVE && ri->role_reported == SRI_SLAVE &&
mstime() - ri->role_reported_time > mstime() - ri->role_reported_time >
(ri->down_after_period+SENTINEL_INFO_PERIOD*2))) (ri->down_after_period+sentinel_info_period*2)))
{ {
/* Is subjectively down */ /* Is subjectively down */
if ((ri->flags & SRI_S_DOWN) == 0) { if ((ri->flags & SRI_S_DOWN) == 0) {
...@@ -4318,7 +4539,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f ...@@ -4318,7 +4539,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f
int retval; int retval;
/* If the master state from other sentinel is too old, we clear it. */ /* If the master state from other sentinel is too old, we clear it. */
if (elapsed > SENTINEL_ASK_PERIOD*5) { if (elapsed > sentinel_ask_period*5) {
ri->flags &= ~SRI_MASTER_DOWN; ri->flags &= ~SRI_MASTER_DOWN;
sdsfree(ri->leader); sdsfree(ri->leader);
ri->leader = NULL; ri->leader = NULL;
...@@ -4332,7 +4553,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f ...@@ -4332,7 +4553,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f
if ((master->flags & SRI_S_DOWN) == 0) continue; if ((master->flags & SRI_S_DOWN) == 0) continue;
if (ri->link->disconnected) continue; if (ri->link->disconnected) continue;
if (!(flags & SENTINEL_ASK_FORCED) && if (!(flags & SENTINEL_ASK_FORCED) &&
mstime() - ri->last_master_down_reply_time < SENTINEL_ASK_PERIOD) mstime() - ri->last_master_down_reply_time < sentinel_ask_period)
continue; continue;
/* Ask */ /* Ask */
...@@ -4697,16 +4918,16 @@ sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master) { ...@@ -4697,16 +4918,16 @@ sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master) {
if (slave->flags & (SRI_S_DOWN|SRI_O_DOWN)) continue; if (slave->flags & (SRI_S_DOWN|SRI_O_DOWN)) continue;
if (slave->link->disconnected) continue; if (slave->link->disconnected) continue;
if (mstime() - slave->link->last_avail_time > SENTINEL_PING_PERIOD*5) continue; if (mstime() - slave->link->last_avail_time > sentinel_ping_period*5) continue;
if (slave->slave_priority == 0) continue; if (slave->slave_priority == 0) continue;
/* If the master is in SDOWN state we get INFO for slaves every second. /* If the master is in SDOWN state we get INFO for slaves every second.
* Otherwise we get it with the usual period so we need to account for * Otherwise we get it with the usual period so we need to account for
* a larger delay. */ * a larger delay. */
if (master->flags & SRI_S_DOWN) if (master->flags & SRI_S_DOWN)
info_validity_time = SENTINEL_PING_PERIOD*5; info_validity_time = sentinel_ping_period*5;
else else
info_validity_time = SENTINEL_INFO_PERIOD*3; info_validity_time = sentinel_info_period*3;
if (mstime() - slave->info_refresh > info_validity_time) continue; if (mstime() - slave->info_refresh > info_validity_time) continue;
if (slave->master_link_down_time > max_master_down_time) continue; if (slave->master_link_down_time > max_master_down_time) continue;
instance[instances++] = slave; instance[instances++] = slave;
...@@ -4734,7 +4955,7 @@ void sentinelFailoverWaitStart(sentinelRedisInstance *ri) { ...@@ -4734,7 +4955,7 @@ void sentinelFailoverWaitStart(sentinelRedisInstance *ri) {
/* If I'm not the leader, and it is not a forced failover via /* If I'm not the leader, and it is not a forced failover via
* SENTINEL FAILOVER, then I can't continue with the failover. */ * SENTINEL FAILOVER, then I can't continue with the failover. */
if (!isleader && !(ri->flags & SRI_FORCE_FAILOVER)) { if (!isleader && !(ri->flags & SRI_FORCE_FAILOVER)) {
int election_timeout = SENTINEL_ELECTION_TIMEOUT; int election_timeout = sentinel_election_timeout;
/* The election timeout is the MIN between SENTINEL_ELECTION_TIMEOUT /* The election timeout is the MIN between SENTINEL_ELECTION_TIMEOUT
* and the configured failover timeout. */ * and the configured failover timeout. */
...@@ -4904,7 +5125,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) { ...@@ -4904,7 +5125,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) {
* configuration later. */ * configuration later. */
if ((slave->flags & SRI_RECONF_SENT) && if ((slave->flags & SRI_RECONF_SENT) &&
(mstime() - slave->slave_reconf_sent_time) > (mstime() - slave->slave_reconf_sent_time) >
SENTINEL_SLAVE_RECONF_TIMEOUT) sentinel_slave_reconf_timeout)
{ {
sentinelEvent(LL_NOTICE,"-slave-reconf-sent-timeout",slave,"%@"); sentinelEvent(LL_NOTICE,"-slave-reconf-sent-timeout",slave,"%@");
slave->flags &= ~SRI_RECONF_SENT; slave->flags &= ~SRI_RECONF_SENT;
...@@ -5004,7 +5225,7 @@ void sentinelHandleRedisInstance(sentinelRedisInstance *ri) { ...@@ -5004,7 +5225,7 @@ void sentinelHandleRedisInstance(sentinelRedisInstance *ri) {
* TILT happens when we find something odd with the time, like a * TILT happens when we find something odd with the time, like a
* sudden change in the clock. */ * sudden change in the clock. */
if (sentinel.tilt) { if (sentinel.tilt) {
if (mstime()-sentinel.tilt_start_time < SENTINEL_TILT_PERIOD) return; if (mstime()-sentinel.tilt_start_time < sentinel_tilt_period) return;
sentinel.tilt = 0; sentinel.tilt = 0;
sentinelEvent(LL_WARNING,"-tilt",NULL,"#tilt mode exited"); sentinelEvent(LL_WARNING,"-tilt",NULL,"#tilt mode exited");
} }
...@@ -5076,7 +5297,7 @@ void sentinelCheckTiltCondition(void) { ...@@ -5076,7 +5297,7 @@ void sentinelCheckTiltCondition(void) {
mstime_t now = mstime(); mstime_t now = mstime();
mstime_t delta = now - sentinel.previous_time; mstime_t delta = now - sentinel.previous_time;
if (delta < 0 || delta > SENTINEL_TILT_TRIGGER) { if (delta < 0 || delta > sentinel_tilt_trigger) {
sentinel.tilt = 1; sentinel.tilt = 1;
sentinel.tilt_start_time = mstime(); sentinel.tilt_start_time = mstime();
sentinelEvent(LL_WARNING,"+tilt",NULL,"#tilt mode entered"); sentinelEvent(LL_WARNING,"+tilt",NULL,"#tilt mode entered");
......
...@@ -7,5 +7,3 @@ sentinel failover-timeout setmaster 240000 ...@@ -7,5 +7,3 @@ sentinel failover-timeout setmaster 240000
# monitoring set # monitoring set
sentinel monitor setmaster 10.0.0.1 30000 2 sentinel monitor setmaster 10.0.0.1 30000 2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment