summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-04-24 11:30:17 +0200
committerantirez <antirez@gmail.com>2013-04-24 11:34:05 +0200
commit34a57a5b52c87503c25dc372f3230fef17a3ecca (patch)
tree5b162350de9fa0babf02568e0c5cd6db580f2f74
parent967ae8ca67447a982382872e8e9eb3fce4bd891b (diff)
downloadredis-34a57a5b52c87503c25dc372f3230fef17a3ecca.tar.gz
Sentinel: always redirect on master->slave transition.
Sentinel redirected to the master if the instance changed runid or it was the first time we got INFO, and a role change was detected from master to slave. While this is a good idea in case of slave->master, since otherwise we could detect a failover without good reasons just after a reboot with a slave with a wrong configuration, in the case of master->slave transition is much better to always perform the redirection for the following reasons: 1) A Sentinel may go down for some time. When it is back online there is no other way to understand there was a failover. 2) Pointing clients to a slave seems to be always the wrong thing to do. 3) There is no good rationale about handling things differently once an instance is rebooted (runid change) in that case.
-rw-r--r--src/sentinel.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index 1932c92fe..6e592ae1e 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -1452,19 +1452,15 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
if (sentinel.tilt) return;
/* Act if a master turned into a slave. */
- if ((ri->flags & SRI_MASTER) && role == SRI_SLAVE) {
- if ((first_runid || runid_changed) && ri->slave_master_host) {
- /* If it is the first time we receive INFO from it, but it's
- * a slave while it was configured as a master, we want to monitor
- * its master instead. */
- sentinelEvent(REDIS_WARNING,"+redirect-to-master",ri,
- "%s %s %d %s %d",
- ri->name, ri->addr->ip, ri->addr->port,
- ri->slave_master_host, ri->slave_master_port);
- sentinelResetMasterAndChangeAddress(ri,ri->slave_master_host,
- ri->slave_master_port);
- return;
- }
+ if ((ri->flags & SRI_MASTER) && role == SRI_SLAVE && ri->slave_master_host)
+ {
+ sentinelEvent(REDIS_WARNING,"+redirect-to-master",ri,
+ "%s %s %d %s %d",
+ ri->name, ri->addr->ip, ri->addr->port,
+ ri->slave_master_host, ri->slave_master_port);
+ sentinelResetMasterAndChangeAddress(ri,ri->slave_master_host,
+ ri->slave_master_port);
+ return;
}
/* Act if a slave turned into a master. */