From 877f94734c5418f794db9ea43d209ad0c4403ed2 Mon Sep 17 00:00:00 2001 From: Kajaruban Surendran Date: Mon, 30 Nov 2020 20:20:37 +0000 Subject: [PATCH] Handling of aeResizeSetSize's return code for current thread Former-commit-id: c25fb3d74fb9e7adb6ad7ef730355e325e982cd2 --- src/ae.cpp | 5 +++++ src/ae.h | 1 + src/config.cpp | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ae.cpp b/src/ae.cpp index cb500d7b6..0d9bf21e7 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -373,6 +373,11 @@ int aeGetSetSize(aeEventLoop *eventLoop) { return eventLoop->setsize; } +/* Return the current EventLoop. */ +aeEventLoop *aeGetCurrentEventLoop(){ + return g_eventLoopThisThread; +} + /* Tells the next iteration/s of the event processing to set timeout of 0. */ void aeSetDontWait(aeEventLoop *eventLoop, int noWait) { if (noWait) diff --git a/src/ae.h b/src/ae.h index fdd444d3a..e77abb01f 100644 --- a/src/ae.h +++ b/src/ae.h @@ -160,6 +160,7 @@ const char *aeGetApiName(void); void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep, int flags); void aeSetAfterSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *aftersleep, int flags); int aeGetSetSize(aeEventLoop *eventLoop); +aeEventLoop *aeGetCurrentEventLoop(); int aeResizeSetSize(aeEventLoop *eventLoop, int setsize); void aeSetDontWait(aeEventLoop *eventLoop, int noWait); diff --git a/src/config.cpp b/src/config.cpp index 88939b001..e00fdf641 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2273,14 +2273,33 @@ static int updateMaxclients(long long val, long long prev, const char **err) { } return 0; } + /* Change the SetSize for the current thread first. + * If any error, return the error message to the client, otherwise, continue to do the same for other threads */ + if ((unsigned int) aeGetSetSize(aeGetCurrentEventLoop()) < + g_pserver->maxclients + CONFIG_FDSET_INCR) + { + if (aeResizeSetSize(aeGetCurrentEventLoop(), + g_pserver->maxclients + CONFIG_FDSET_INCR) == AE_ERR) + { + *err = "The event loop API used by Redis is not able to handle the specified number of clients"; + return 0; + } + serverLog(LL_DEBUG,"Successfully changed the setsize for current thread %d", ielFromEventLoop(aeGetCurrentEventLoop())); + } + for (int iel = 0; iel < cserver.cthreads; ++iel) { + if (g_pserver->rgthreadvar[iel].el == aeGetCurrentEventLoop()) + { + continue; + } + if ((unsigned int) aeGetSetSize(g_pserver->rgthreadvar[iel].el) < g_pserver->maxclients + CONFIG_FDSET_INCR) { int res = aePostFunction(g_pserver->rgthreadvar[iel].el, [iel] { if (aeResizeSetSize(g_pserver->rgthreadvar[iel].el, g_pserver->maxclients + CONFIG_FDSET_INCR) == AE_ERR) { - serverPanic("Failed to change the setsize for Thread %d", iel); + serverLog(LL_WARNING,"Failed to change the setsize for Thread %d", iel); } }); @@ -2290,6 +2309,7 @@ static int updateMaxclients(long long val, long long prev, const char **err) { *err = msg; return 0; } + serverLog(LL_DEBUG,"Successfully post the request to change the setsize for thread %d", iel); } } }