]> git.saurik.com Git - redis.git/commitdiff
Prevent a spurious +sdown event on switch.
authorantirez <antirez@gmail.com>
Tue, 24 Jul 2012 16:46:04 +0000 (18:46 +0200)
committerantirez <antirez@gmail.com>
Thu, 27 Sep 2012 11:04:19 +0000 (13:04 +0200)
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

index 3acadf831f26ab2bb6130d1d9b2421d4da825358..e89b343a93919292a9fc9249b40954ef1f67bb49 100644 (file)
@@ -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->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);
     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;
     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,"%@");
 }
     if (flags & SENTINEL_GENERATE_EVENT)
         sentinelEvent(REDIS_WARNING,"+reset-master",ri,"%@");
 }