From b94bca01fccffb20b3abdb722a6564b29f749202 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 24 Jul 2012 18:46:04 +0200 Subject: [PATCH] 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. --- src/sentinel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sentinel.c b/src/sentinel.c index 3acadf831..e89b343a9 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,"%@"); }