From 07486df6fecae97b02171bba86f51d5df0a94cb5 Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Fri, 17 Jun 2011 16:13:22 +0200
Subject: [PATCH] new INFO filed master_link_down_since_seconds

---
 src/networking.c | 1 +
 src/redis.c      | 7 +++++++
 src/redis.h      | 1 +
 3 files changed, 9 insertions(+)

diff --git a/src/networking.c b/src/networking.c
index 4a6a8afd8..c7b56ca4c 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -522,6 +522,7 @@ void freeClient(redisClient *c) {
     if (c->flags & REDIS_MASTER) {
         server.master = NULL;
         server.replstate = REDIS_REPL_CONNECT;
+        server.repl_down_since = time(NULL);
         /* Since we lost the connection with the master, we should also
          * close the connection with all our slaves if we have any, so
          * when we'll resync with the master the other slaves will sync again
diff --git a/src/redis.c b/src/redis.c
index e7351b6ef..8fbed746d 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -901,6 +901,7 @@ void initServerConfig() {
     server.replstate = REDIS_REPL_NONE;
     server.repl_syncio_timeout = REDIS_REPL_SYNCIO_TIMEOUT;
     server.repl_serve_stale_data = 1;
+    server.repl_down_since = -1;
 
     /* Double constants initialization */
     R_Zero = 0.0;
@@ -1522,6 +1523,12 @@ sds genRedisInfoString(char *section) {
                     (int)(time(NULL)-server.repl_transfer_lastio)
                 );
             }
+
+            if (server.replstate != REDIS_REPL_CONNECTED) {
+                info = sdscatprintf(info,
+                    "master_link_down_since_seconds:%ld\r\n",
+                    (long)time(NULL)-server.repl_down_since);
+            }
         }
         info = sdscatprintf(info,
             "connected_slaves:%d\r\n",
diff --git a/src/redis.h b/src/redis.h
index ce62d226b..3b5cb0230 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -604,6 +604,7 @@ struct redisServer {
     char *repl_transfer_tmpfile; /* slave-> master SYNC temp file name */
     time_t repl_transfer_lastio; /* unix time of the latest read, for timeout */
     int repl_serve_stale_data; /* Serve stale data when link is down? */
+    time_t repl_down_since; /* unix time at which link with master went down */
     /* Limits */
     unsigned int maxclients;
     unsigned long long maxmemory;