summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-08-28 17:45:01 +0200
committerantirez <antirez@gmail.com>2012-08-28 17:45:01 +0200
commit3ec701e0597cd59d63835fc1b8e1ebeec78e9788 (patch)
tree72820d9cf99658601b688c659293f83023beead0
parent169a44cbd6b6a143b282206d754b71cd3af0c963 (diff)
downloadredis-3ec701e0597cd59d63835fc1b8e1ebeec78e9788.tar.gz
Sentinel: Sentinel-side support for slave priority.
The slave priority that is now published by Redis in INFO output is now used by Sentinel in order to select the slave with minimum priority for promotion, and in order to consider slaves with priority set to 0 as not able to play the role of master (they will never be promoted by Sentinel). The "slave-priority" field is now one of the fileds that Sentinel publishes when describing an instance via the SENTINEL commands such as "SENTINEL slaves mastername".
-rw-r--r--src/sentinel.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index e683279bb..d5ffa6f7e 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -1410,6 +1410,10 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
SENTINEL_MASTER_LINK_STATUS_UP :
SENTINEL_MASTER_LINK_STATUS_DOWN;
}
+
+ /* slave_priority:<priority> */
+ if (sdslen(l) >= 15 && !memcmp(l,"slave_priority:",15))
+ ri->slave_priority = atoi(l+15);
}
}
ri->info_refresh = mstime();
@@ -1882,6 +1886,10 @@ void addReplySentinelRedisInstance(redisClient *c, sentinelRedisInstance *ri) {
addReplyBulkCString(c,"master-port");
addReplyBulkLongLong(c,ri->slave_master_port);
fields++;
+
+ addReplyBulkCString(c,"slave-priority");
+ addReplyBulkLongLong(c,ri->slave_priority);
+ fields++;
}
/* Only sentinels */
@@ -2439,6 +2447,7 @@ void sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) {
* 3) info_refresh more recent than SENTINEL_INFO_VALIDITY_TIME.
* 4) master_link_down_time no more than:
* (now - master->s_down_since_time) + (master->down_after_period * 10).
+ * 5) Slave priority can't be zero, otherwise the slave is discareded.
*
* Among all the slaves matching the above conditions we select the slave
* with lower slave_priority. If priority is the same we select the slave
@@ -2476,6 +2485,7 @@ sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master) {
if (slave->flags & (SRI_S_DOWN|SRI_O_DOWN|SRI_DISCONNECTED)) continue;
if (slave->last_avail_time < info_validity_time) continue;
+ if (slave->slave_priority == 0) continue;
/* If the master is in SDOWN state we get INFO for slaves every second.
* Otherwise we get it with the usual period so we need to account for