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:
commit
0bf6a0c375
@ -859,6 +859,11 @@ void aeReleaseForkLock()
|
||||
g_forkLock.downgradeWrite();
|
||||
}
|
||||
|
||||
void aeForkLockInChild()
|
||||
{
|
||||
g_forkLock.setNotify(false);
|
||||
}
|
||||
|
||||
int aeThreadOwnsLock()
|
||||
{
|
||||
return fOwnLockOverride || g_lock.fOwnLock();
|
||||
|
1
src/ae.h
1
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);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user