diff --git a/src/networking.cpp b/src/networking.cpp index 574a8bc6c..c0b4d1944 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -158,6 +158,7 @@ client *createClient(connection *conn, int iel) { c->reploff_cmd = 0; c->repl_ack_off = 0; c->repl_ack_time = 0; + c->repl_down_since = 0; c->slave_listening_port = 0; c->slave_ip[0] = '\0'; c->slave_capa = SLAVE_CAPA_NONE; @@ -1616,7 +1617,8 @@ void freeClientAsync(client *c) { AeLocker lock; lock.arm(c); if (c->flags & CLIENT_CLOSE_ASAP || c->flags & CLIENT_LUA) return; // race condition after we acquire the lock - c->flags |= CLIENT_CLOSE_ASAP; + c->flags |= CLIENT_CLOSE_ASAP; + c->repl_down_since = g_pserver->unixtime; std::unique_lock ul(lockasyncfree); listAddNodeTail(g_pserver->clients_to_close,c); } diff --git a/src/replication.cpp b/src/replication.cpp index 2533bae52..0f7700f92 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -3213,9 +3213,14 @@ void replicationHandleMasterDisconnection(redisMaster *mi) { moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE, REDISMODULE_SUBEVENT_MASTER_LINK_DOWN, NULL); + if (mi->master && mi->master->repl_down_since) { + mi->repl_down_since = mi->master->repl_down_since; + } + else { + mi->repl_down_since = g_pserver->unixtime; + } mi->master = NULL; mi->repl_state = REPL_STATE_CONNECT; - mi->repl_down_since = g_pserver->unixtime; /* We lost connection with our master, don't disconnect slaves yet, * maybe we'll be able to PSYNC with our master later. We'll disconnect * the slaves only if we'll have to do a full resync with our master. */ @@ -3534,6 +3539,7 @@ void replicationResurrectCachedMaster(redisMaster *mi, connection *conn) { mi->master->lastinteraction = g_pserver->unixtime; mi->repl_state = REPL_STATE_CONNECTED; mi->repl_down_since = 0; + mi->master->repl_down_since = 0; /* Normally changing the thread of a client is a BIG NONO, but this client was unlinked so its OK here */ diff --git a/src/server.cpp b/src/server.cpp index 3d547f748..bc268b4fd 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6148,7 +6148,7 @@ void *timeThreadMain(void*) { } } updateCachedTime(); - clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL); + clock_nanosleep(CLOCK_MONOTONIC, 0, &delay, NULL); } } diff --git a/src/server.h b/src/server.h index 878154bc5..66f71062f 100644 --- a/src/server.h +++ b/src/server.h @@ -1507,6 +1507,7 @@ struct client { off_t repldboff; /* Replication DB file offset. */ off_t repldbsize; /* Replication DB file size. */ sds replpreamble; /* Replication DB preamble. */ + time_t repl_down_since; /* When client lost connection. */ long long read_reploff; /* Read replication offset if this is a master. */ long long reploff; /* Applied replication offset if this is a master. */ long long reploff_skipped; /* Repl backlog we did not send to this client */