提交 64ad6648 编写于 作者: A antirez

Sentinel: reconfigure slaves to right master.

上级 3e27d678
......@@ -1596,7 +1596,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) ||
......@@ -1620,6 +1620,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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册