mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Wait zero active threads condition before to fork() for BGSAVE or BGREWRITEAOF
This commit is contained in:
parent
c7df85a484
commit
4ee9488d7e
17
redis.c
17
redis.c
@ -561,6 +561,7 @@ static void freeIOJob(iojob *j);
|
||||
static void queueIOJob(iojob *j);
|
||||
static int vmWriteObjectOnSwap(robj *o, off_t page);
|
||||
static robj *vmReadObjectFromSwap(off_t page, int type);
|
||||
static void waitZeroActiveThreads(void);
|
||||
|
||||
static void authCommand(redisClient *c);
|
||||
static void pingCommand(redisClient *c);
|
||||
@ -3085,6 +3086,7 @@ static int rdbSaveBackground(char *filename) {
|
||||
pid_t childpid;
|
||||
|
||||
if (server.bgsavechildpid != -1) return REDIS_ERR;
|
||||
if (server.vm_enabled) waitZeroActiveThreads();
|
||||
if ((childpid = fork()) == 0) {
|
||||
/* Child */
|
||||
close(server.fd);
|
||||
@ -6906,6 +6908,7 @@ static int rewriteAppendOnlyFileBackground(void) {
|
||||
pid_t childpid;
|
||||
|
||||
if (server.bgrewritechildpid != -1) return REDIS_ERR;
|
||||
if (server.vm_enabled) waitZeroActiveThreads();
|
||||
if ((childpid = fork()) == 0) {
|
||||
/* Child */
|
||||
char tmpfile[256];
|
||||
@ -7669,6 +7672,20 @@ static void spawnIOThread(void) {
|
||||
server.io_active_threads++;
|
||||
}
|
||||
|
||||
/* We need to wait for the last thread to exit before we are able to
|
||||
* fork() in order to BGSAVE or BGREWRITEAOF. */
|
||||
static void waitZeroActiveThreads(void) {
|
||||
while(1) {
|
||||
lockThreadedIO();
|
||||
if (server.io_active_threads == 0) {
|
||||
unlockThreadedIO();
|
||||
return;
|
||||
}
|
||||
unlockThreadedIO();
|
||||
usleep(10000); /* 10 milliseconds */
|
||||
}
|
||||
}
|
||||
|
||||
/* This function must be called while with threaded IO locked */
|
||||
static void queueIOJob(iojob *j) {
|
||||
redisLog(REDIS_DEBUG,"Queued IO Job %p type %d about key '%s'\n",
|
||||
|
Loading…
Reference in New Issue
Block a user