mirror of
https://github.com/fluencelabs/redis
synced 2025-03-31 14:51:04 +00:00
Sentinel: simplify and refactor slave reconfig code.
This commit is contained in:
parent
64ad6648a8
commit
dfbd9c5aeb
@ -1431,6 +1431,19 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
|
|||||||
|
|
||||||
/* ======================== Redis instances pinging ======================== */
|
/* ======================== Redis instances pinging ======================== */
|
||||||
|
|
||||||
|
/* Return true if master looks "sane", that is:
|
||||||
|
* 1) It is actually a master in the current configuration.
|
||||||
|
* 2) It reports itself as a master.
|
||||||
|
* 3) It is not SDOWN or ODOWN.
|
||||||
|
* 4) We obtained last INFO no more than two times the INFO period of time ago. */
|
||||||
|
int sentinelMasterLooksSane(sentinelRedisInstance *master) {
|
||||||
|
return
|
||||||
|
master->flags & SRI_MASTER &&
|
||||||
|
master->role_reported == SRI_MASTER &&
|
||||||
|
(master->flags & (SRI_S_DOWN|SRI_O_DOWN)) == 0 &&
|
||||||
|
(mstime() - master->info_refresh) < SENTINEL_INFO_PERIOD*2;
|
||||||
|
}
|
||||||
|
|
||||||
/* Process the INFO output from masters. */
|
/* Process the INFO output from masters. */
|
||||||
void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
||||||
sds *lines;
|
sds *lines;
|
||||||
@ -1594,22 +1607,13 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
|||||||
"start",ri->master->addr,ri->addr);
|
"start",ri->master->addr,ri->addr);
|
||||||
} else if (!sentinel.tilt) {
|
} else if (!sentinel.tilt) {
|
||||||
/* 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, but make sure to wait some time before
|
* reconfigure as slave. Wait some time after the change before
|
||||||
* doing this in order to make sure to receive an updated
|
* going forward, to receive new configs if any. */
|
||||||
* configuration via Pub/Sub if any. */
|
|
||||||
mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4;
|
mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4;
|
||||||
|
|
||||||
if (!sentinelRedisInstanceNoDownFor(ri,wait_time) ||
|
if (sentinelMasterLooksSane(ri->master) &&
|
||||||
mstime() - ri->role_reported_time < wait_time ||
|
sentinelRedisInstanceNoDownFor(ri,wait_time) &&
|
||||||
mstime() - sentinel.tilt_start_time < wait_time)
|
mstime() - ri->role_reported_time > wait_time)
|
||||||
return;
|
|
||||||
|
|
||||||
/* Make sure the master is sane before reconfiguring this instance
|
|
||||||
* into a slave. */
|
|
||||||
if (ri->master->flags & SRI_MASTER &&
|
|
||||||
ri->master->role_reported == SRI_MASTER &&
|
|
||||||
(ri->master->flags & (SRI_S_DOWN|SRI_O_DOWN)) == 0 &&
|
|
||||||
(mstime() - ri->master->info_refresh) < SENTINEL_INFO_PERIOD*2)
|
|
||||||
{
|
{
|
||||||
int retval = sentinelSendSlaveOf(ri,
|
int retval = sentinelSendSlaveOf(ri,
|
||||||
ri->master->addr->ip,
|
ri->master->addr->ip,
|
||||||
@ -1627,16 +1631,11 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
|||||||
{
|
{
|
||||||
mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4;
|
mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4;
|
||||||
|
|
||||||
if (!sentinelRedisInstanceNoDownFor(ri,wait_time) ||
|
|
||||||
mstime() - ri->slave_conf_change_time < wait_time)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Make sure the master is sane before reconfiguring this instance
|
/* Make sure the master is sane before reconfiguring this instance
|
||||||
* into a slave. */
|
* into a slave. */
|
||||||
if (ri->master->flags & SRI_MASTER &&
|
if (sentinelMasterLooksSane(ri->master) &&
|
||||||
ri->master->role_reported == SRI_MASTER &&
|
sentinelRedisInstanceNoDownFor(ri,wait_time) &&
|
||||||
(ri->master->flags & (SRI_S_DOWN|SRI_O_DOWN)) == 0 &&
|
mstime() - ri->slave_conf_change_time > wait_time)
|
||||||
(mstime() - ri->master->info_refresh) < SENTINEL_INFO_PERIOD*2)
|
|
||||||
{
|
{
|
||||||
int retval = sentinelSendSlaveOf(ri,
|
int retval = sentinelSendSlaveOf(ri,
|
||||||
ri->master->addr->ip,
|
ri->master->addr->ip,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user