From 218cc5fc394d15af3d7b5fbf6b15376c3e23cd6c Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Tue, 18 Mar 2014 14:37:44 +0100
Subject: [PATCH] Sentinel: propagate down-after-ms changes to slaves and
 sentinels.

---
 src/sentinel.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/sentinel.c b/src/sentinel.c
index 9410a27e..0ae79bde 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -1298,6 +1298,24 @@ sentinelAddr *sentinelGetCurrentMasterAddress(sentinelRedisInstance *master) {
     }
 }
 
+/* This function sets the down_after_period field value in 'master' to all
+ * the slaves and sentinel instances connected to this master. */
+void sentinelPropagateDownAfterPeriod(sentinelRedisInstance *master) {
+    dictIterator *di;
+    dictEntry *de;
+    int j;
+    dict *d[] = {master->slaves, master->sentinels, NULL};
+
+    for (j = 0; d[j]; j++) {
+        di = dictGetIterator(d[j]);
+        while((de = dictNext(di)) != NULL) {
+            sentinelRedisInstance *ri = dictGetVal(de);
+            ri->down_after_period = master->down_after_period;
+        }
+        dictReleaseIterator(di);
+    }
+}
+
 /* ============================ Config handling ============================= */
 char *sentinelHandleConfiguration(char **argv, int argc) {
     sentinelRedisInstance *ri;
@@ -1323,6 +1341,7 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
         ri->down_after_period = atoi(argv[2]);
         if (ri->down_after_period <= 0)
             return "negative or zero time parameter.";
+        sentinelPropagateDownAfterPeriod(ri);
     } else if (!strcasecmp(argv[0],"failover-timeout") && argc == 3) {
         /* failover-timeout <name> <milliseconds> */
         ri = sentinelGetMasterByName(argv[1]);
@@ -2762,6 +2781,7 @@ void sentinelSetCommand(redisClient *c) {
             if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0)
                 goto badfmt;
             ri->down_after_period = ll;
+            sentinelPropagateDownAfterPeriod(ri);
             changes++;
         } else if (!strcasecmp(option,"failover-timeout")) {
             /* failover-timeout <milliseconds> */