From fcb4fdc99d7989e0017f7230fbfdcf5295bfa0cc Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 26 Aug 2022 17:36:23 +0000 Subject: [PATCH 1/2] Fix integer overflow of the track changes counter --- src/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.cpp b/src/server.cpp index 4ba9e73f5..4fb5df41f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2908,7 +2908,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) { static thread_local bool fFirstRun = true; // note: we also copy the DB pointer in case a DB swap is done while the lock is released std::vector vecdb; // note we cache the database pointer in case a dbswap is done while the lock is released - if (cserver.storage_memory_model == STORAGE_WRITETHROUGH && g_pserver->m_pstorageFactory != nullptr && !g_pserver->loading) + if (cserver.storage_memory_model == STORAGE_WRITETHROUGH && !g_pserver->loading) { if (!fFirstRun) { mstime_t storage_process_latency; From f147c758d4b1c23e3d5c8302852385dfd8be2049 Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 26 Aug 2022 18:05:00 +0000 Subject: [PATCH 2/2] Fix P99 latency issue for TLS where we leave work for the next event loop tlsProcessPendingData() needs to be called before we execute queued commands because it may enqueue more commands --- src/server.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 4fb5df41f..f727a82c4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2795,6 +2795,8 @@ void beforeSleep(struct aeEventLoop *eventLoop) { AeLocker locker; int iel = ielFromEventLoop(eventLoop); + tlsProcessPendingData(); + locker.arm(); /* end any snapshots created by fast async commands */ @@ -2825,7 +2827,6 @@ void beforeSleep(struct aeEventLoop *eventLoop) { uint64_t processed = 0; int aof_state = g_pserver->aof_state; locker.disarm(); - processed += tlsProcessPendingData(); processed += handleClientsWithPendingWrites(iel, aof_state); locker.arm(); processed += freeClientsInAsyncFreeQueue(iel); @@ -2836,13 +2837,6 @@ void beforeSleep(struct aeEventLoop *eventLoop) { /* Handle precise timeouts of blocked clients. */ handleBlockedClientsTimeout(); - /* Handle TLS pending data. (must be done before flushAppendOnlyFile) */ - if (tlsHasPendingData()) { - locker.disarm(); - tlsProcessPendingData(); - locker.arm(); - } - /* If tls still has pending unread data don't sleep at all. */ aeSetDontWait(eventLoop, tlsHasPendingData());