From: antirez Date: Tue, 24 Jul 2012 16:46:04 +0000 (+0200) Subject: Prevent a spurious +sdown event on switch. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/f8a19e32e2fffea00e61717d99ecebabafbbe852?ds=inline Prevent a spurious +sdown event on switch. When we reset the master we should start with clean timestamps for ping replies otherwise we'll detect a spurious +sdown event, because on +master-switch event the previous master instance was probably in +sdown condition. Since we updated the address we should count time from scratch again. Also this commit makes sure to explicitly reset the count of pending commands, now we can do this because of the new way the hiredis link is closed. --- diff --git a/src/sentinel.c b/src/sentinel.c index 3acadf83..e89b343a 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -765,6 +765,7 @@ void sentinelResetMaster(sentinelRedisInstance *ri, int flags) { ri->sentinels = dictCreate(&instancesDictType,NULL); if (ri->cc) sentinelKillLink(ri,ri->cc); if (ri->pc) sentinelKillLink(ri,ri->pc); + ri->pending_commands = 0; ri->flags &= SRI_MASTER|SRI_CAN_FAILOVER|SRI_DISCONNECTED; if (ri->leader) { sdsfree(ri->leader); @@ -778,6 +779,8 @@ void sentinelResetMaster(sentinelRedisInstance *ri, int flags) { sdsfree(ri->slave_master_host); ri->runid = NULL; ri->slave_master_host = NULL; + ri->last_avail_time = mstime(); + ri->last_pong_time = mstime(); if (flags & SENTINEL_GENERATE_EVENT) sentinelEvent(REDIS_WARNING,"+reset-master",ri,"%@"); }