From 9ea8843e14e4b13263705098da4ca6f6d658946f Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 3 Mar 2021 07:05:51 +0000 Subject: [PATCH] In low load async rehash may not complete in time, do it in the cron Former-commit-id: 0a27d30753d887b6251e645abe26118068c55587 --- src/server.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server.cpp b/src/server.cpp index 1bc9ab175..b1124cac9 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2157,6 +2157,14 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { UNUSED(id); UNUSED(clientData); + if (serverTL->rehashCtl != nullptr && !serverTL->rehashCtl->done) { + aeReleaseLock(); + // If there is not enough lock contention we may not have made enough progress on the async + // rehash. Ensure we finish it outside the lock. + dictRehashSomeAsync(serverTL->rehashCtl, serverTL->rehashCtl->queue.size()); + aeAcquireLock(); + } + /* If another threads unblocked one of our clients, and this thread has been idle then beforeSleep won't have a chance to process the unblocking. So we also process them here in the cron job to ensure they don't starve. @@ -2448,6 +2456,14 @@ int serverCronLite(struct aeEventLoop *eventLoop, long long id, void *clientData UNUSED(id); UNUSED(clientData); + if (serverTL->rehashCtl != nullptr && !serverTL->rehashCtl->done) { + aeReleaseLock(); + // If there is not enough lock contention we may not have made enough progress on the async + // rehash. Ensure we finish it outside the lock. + dictRehashSomeAsync(serverTL->rehashCtl, serverTL->rehashCtl->queue.size()); + aeAcquireLock(); + } + int iel = ielFromEventLoop(eventLoop); serverAssert(iel != IDX_EVENT_LOOP_MAIN);