diff --git a/src/networking.c b/src/networking.c index 549d5ad7..fef5d4b5 100644 --- a/src/networking.c +++ b/src/networking.c @@ -523,6 +523,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 d4cad4e4..c523a537 100644 --- a/src/redis.c +++ b/src/redis.c @@ -853,6 +853,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; @@ -1317,7 +1318,14 @@ sds genRedisInfoString(void) { (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); + } } + if (server.vm_enabled) { lockThreadedIO(); info = sdscatprintf(info, diff --git a/src/redis.h b/src/redis.h index 00fb74f3..38943f2b 100644 --- a/src/redis.h +++ b/src/redis.h @@ -452,6 +452,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;