diff options
author | antirez <antirez@gmail.com> | 2013-11-14 00:29:38 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-11-21 15:20:44 +0100 |
commit | 782f9cacaf95c4e812e5a1aed3af6bd49c5a9a0d (patch) | |
tree | 4cbbf4a567775f193eb2e0a9e77a2c4799a47bad | |
parent | 7dbc0a63f5591ed9a1e5aaaecd817b44d27e6bac (diff) | |
download | redis-782f9cacaf95c4e812e5a1aed3af6bd49c5a9a0d.tar.gz |
Sentinel: reconfigure slaves to right master.
-rw-r--r-- | src/sentinel.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/sentinel.c b/src/sentinel.c index e577df116..f40b1ae94 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -1598,7 +1598,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { /* A slave turned into a master. We want to force our view and * reconfigure as slave, but make sure to wait some time before * doing this in order to make sure to receive an updated - * configuratio via Pub/Sub if any. */ + * configuration via Pub/Sub if any. */ mstime_t wait_time = SENTINEL_PUBLISH_PERIOD*4; if (!sentinelRedisInstanceNoDownFor(ri,wait_time) || @@ -1622,6 +1622,32 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { } } + /* Handle slaves replicating to a different master address. */ + if ((ri->flags & SRI_SLAVE) && !sentinel.tilt && + (ri->slave_master_port != ri->master->addr->port || + strcasecmp(ri->slave_master_host,ri->master->addr->ip))) + { + 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 + * 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, + ri->master->addr->ip, + ri->master->addr->port); + if (retval == REDIS_OK) + sentinelEvent(REDIS_NOTICE,"+fix-slave-config",ri,"%@"); + } + } + /* None of the following conditions are processed when in tilt mode, so * return asap. */ if (sentinel.tilt) return; |