Merge pull request #560 from Snapchat/aof_fixes

* technically possible for child_type == CHILD_TYPE_AOF without active child

* don't release lock on child as it can hang

* need child specific release that doesn't trigger cv

* refactor aeReleaseForkLockChild to capture releaseRead case

* rdb_child_pid isn't the correct value
This commit is contained in:
Malavan Sotheeswaran 2023-02-13 13:07:53 -05:00 committed by GitHub
commit 0bf6a0c375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 4 deletions

View File

@ -859,6 +859,11 @@ void aeReleaseForkLock()
g_forkLock.downgradeWrite();
}
void aeForkLockInChild()
{
g_forkLock.setNotify(false);
}
int aeThreadOwnsLock()
{
return fOwnLockOverride || g_lock.fOwnLock();

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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<fastlock> 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;
}

View File

@ -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);