From 3d424defd5440b89c5e6bfd098d5e20d588a67d6 Mon Sep 17 00:00:00 2001 From: christian Date: Mon, 3 May 2021 21:41:04 +0000 Subject: [PATCH] Set repl_down_since in freeClientAsync Former-commit-id: fb4bd2984651837fadd1dbbbb56327e8452b4a2a --- src/networking.cpp | 4 +++- src/replication.cpp | 8 +++++++- src/server.cpp | 2 +- src/server.h | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/networking.cpp b/src/networking.cpp index 15aa6f43a..df1aca947 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; @@ -1606,7 +1607,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 0589868cb..f3b0ebed1 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 96d62e4ea..d4805e8d6 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6082,7 +6082,7 @@ void *timeThreadMain(void*) { delay.tv_nsec = 100; while (true) { 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 07f025c46..f556c6077 100644 --- a/src/server.h +++ b/src/server.h @@ -1509,6 +1509,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 */