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();
|
g_forkLock.downgradeWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void aeForkLockInChild()
|
||||||
|
{
|
||||||
|
g_forkLock.setNotify(false);
|
||||||
|
}
|
||||||
|
|
||||||
int aeThreadOwnsLock()
|
int aeThreadOwnsLock()
|
||||||
{
|
{
|
||||||
return fOwnLockOverride || g_lock.fOwnLock();
|
return fOwnLockOverride || g_lock.fOwnLock();
|
||||||
|
1
src/ae.h
1
src/ae.h
@ -171,6 +171,7 @@ int aeTryAcquireLock(int fWeak);
|
|||||||
void aeThreadOffline();
|
void aeThreadOffline();
|
||||||
void aeReleaseLock();
|
void aeReleaseLock();
|
||||||
void aeReleaseForkLock();
|
void aeReleaseForkLock();
|
||||||
|
void aeForkLockInChild();
|
||||||
int aeThreadOwnsLock();
|
int aeThreadOwnsLock();
|
||||||
void aeSetThreadOwnsLockOverride(int fOverride);
|
void aeSetThreadOwnsLockOverride(int fOverride);
|
||||||
int aeLockContested(int threshold);
|
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
|
* 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
|
* in a buffer, so that when the child process will do its work we
|
||||||
* can append the differences to the new append only file. */
|
* 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));
|
aofRewriteBufferAppend((unsigned char*)buf,sdslen(buf));
|
||||||
|
|
||||||
sdsfree(buf);
|
sdsfree(buf);
|
||||||
|
@ -3694,7 +3694,7 @@ void killRDBChild(bool fSynchronous) {
|
|||||||
serverAssert(GlobalLocksAcquired());
|
serverAssert(GlobalLocksAcquired());
|
||||||
|
|
||||||
if (cserver.fForkBgSave) {
|
if (cserver.fForkBgSave) {
|
||||||
kill(g_pserver->rdb_child_pid,SIGUSR1);
|
kill(g_pserver->child_pid,SIGUSR1);
|
||||||
} else {
|
} else {
|
||||||
g_pserver->rdbThreadVars.fRdbThreadCancel = true;
|
g_pserver->rdbThreadVars.fRdbThreadCancel = true;
|
||||||
if (g_pserver->rdb_child_type == RDB_CHILD_TYPE_SOCKET) {
|
if (g_pserver->rdb_child_type == RDB_CHILD_TYPE_SOCKET) {
|
||||||
|
@ -8,6 +8,7 @@ class readWriteLock {
|
|||||||
int m_readCount = 0;
|
int m_readCount = 0;
|
||||||
int m_writeCount = 0;
|
int m_writeCount = 0;
|
||||||
bool m_writeWaiting = false;
|
bool m_writeWaiting = false;
|
||||||
|
bool m_notify = true;
|
||||||
public:
|
public:
|
||||||
readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {}
|
readWriteLock(const char *name) : m_readLock(name), m_writeLock(name) {}
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ public:
|
|||||||
void releaseRead() {
|
void releaseRead() {
|
||||||
std::unique_lock<fastlock> rm(m_readLock);
|
std::unique_lock<fastlock> rm(m_readLock);
|
||||||
m_readCount--;
|
m_readCount--;
|
||||||
|
if (m_notify)
|
||||||
m_cv.notify_all();
|
m_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +76,7 @@ public:
|
|||||||
if (exclusive)
|
if (exclusive)
|
||||||
m_writeLock.unlock();
|
m_writeLock.unlock();
|
||||||
m_writeCount--;
|
m_writeCount--;
|
||||||
|
if (m_notify)
|
||||||
m_cv.notify_all();
|
m_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +85,10 @@ public:
|
|||||||
acquireRead();
|
acquireRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setNotify(bool notify) {
|
||||||
|
m_notify = notify;
|
||||||
|
}
|
||||||
|
|
||||||
bool hasReader() {
|
bool hasReader() {
|
||||||
return m_readCount > 0;
|
return m_readCount > 0;
|
||||||
}
|
}
|
||||||
|
@ -6888,6 +6888,7 @@ int redisFork(int purpose) {
|
|||||||
latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000);
|
latencyAddSampleIfNeeded("fork-lock",(ustime()-startWriteLock)/1000);
|
||||||
if ((childpid = fork()) == 0) {
|
if ((childpid = fork()) == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
|
aeForkLockInChild();
|
||||||
aeReleaseForkLock();
|
aeReleaseForkLock();
|
||||||
g_pserver->in_fork_child = purpose;
|
g_pserver->in_fork_child = purpose;
|
||||||
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user