diff --git a/src/ae.cpp b/src/ae.cpp index 9d8c945d5..99093daa8 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -859,6 +859,11 @@ void aeReleaseForkLock() g_forkLock.downgradeWrite(); } +void aeForkLockInChild() +{ + g_forkLock.setNotify(false); +} + int aeThreadOwnsLock() { return fOwnLockOverride || g_lock.fOwnLock(); diff --git a/src/ae.h b/src/ae.h index cd513f652..3868db4a0 100644 --- a/src/ae.h +++ b/src/ae.h @@ -171,6 +171,7 @@ int aeTryAcquireLock(int fWeak); void aeThreadOffline(); void aeReleaseLock(); void aeReleaseForkLock(); +void aeForkLockInChild(); int aeThreadOwnsLock(); void aeSetThreadOwnsLockOverride(int fOverride); int aeLockContested(int threshold); diff --git a/src/aof.cpp b/src/aof.cpp index 94229169b..0044c02ed 100644 --- a/src/aof.cpp +++ b/src/aof.cpp @@ -752,7 +752,7 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a * accumulate the differences between the child DB and the current one * in a buffer, so that when the child process will do its work we * can append the differences to the new append only file. */ - if (g_pserver->child_type == CHILD_TYPE_AOF) + if (hasActiveChildProcess() && g_pserver->child_type == CHILD_TYPE_AOF) aofRewriteBufferAppend((unsigned char*)buf,sdslen(buf)); sdsfree(buf); diff --git a/src/rdb.cpp b/src/rdb.cpp index f3ab5898b..4d699e6fb 100644 --- a/src/rdb.cpp +++ b/src/rdb.cpp @@ -3694,7 +3694,7 @@ void killRDBChild(bool fSynchronous) { serverAssert(GlobalLocksAcquired()); if (cserver.fForkBgSave) { - kill(g_pserver->rdb_child_pid,SIGUSR1); + kill(g_pserver->child_pid,SIGUSR1); } else { g_pserver->rdbThreadVars.fRdbThreadCancel = true; if (g_pserver->rdb_child_type == RDB_CHILD_TYPE_SOCKET) { diff --git a/src/readwritelock.h b/src/readwritelock.h index a7318a29f..79f0ac710 100644 --- a/src/readwritelock.h +++ b/src/readwritelock.h @@ -8,6 +8,7 @@ class readWriteLock { int m_readCount = 0; int m_writeCount = 0; bool m_writeWaiting = false; + bool m_notify = true; public: readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {} @@ -65,7 +66,8 @@ public: void releaseRead() { std::unique_lock rm(m_readLock); m_readCount--; - m_cv.notify_all(); + if (m_notify) + m_cv.notify_all(); } void releaseWrite(bool exclusive = true) { @@ -74,7 +76,8 @@ public: if (exclusive) m_writeLock.unlock(); m_writeCount--; - m_cv.notify_all(); + if (m_notify) + m_cv.notify_all(); } void downgradeWrite(bool exclusive = true) { @@ -82,6 +85,10 @@ public: acquireRead(); } + void setNotify(bool notify) { + m_notify = notify; + } + bool hasReader() { return m_readCount > 0; } diff --git a/src/server.cpp b/src/server.cpp index b2b91cb55..9b983585e 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6888,6 +6888,7 @@ int redisFork(int purpose) { latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000); if ((childpid = fork()) == 0) { /* Child */ + aeForkLockInChild(); aeReleaseForkLock(); g_pserver->in_fork_child = purpose; setOOMScoreAdj(CONFIG_OOM_BGCHILD);