Refactoring: always kill AOF/RDB child via helper functions.

This commit is contained in:
antirez 2019-01-21 11:28:44 +01:00
parent 5f42bfce05
commit 4dc69497f5
6 changed files with 17 additions and 14 deletions

View File

@ -204,7 +204,7 @@ void aof_background_fsync(int fd) {
}
/* Kills an AOFRW child process if exists */
static void killAppendOnlyChild(void) {
void killAppendOnlyChild(void) {
int statloc;
/* No AOFRW child? return. */
if (server.aof_child_pid == -1) return;

View File

@ -448,12 +448,7 @@ void flushallCommand(client *c) {
signalFlushedDb(-1);
server.dirty += emptyDb(-1,flags,NULL);
addReply(c,shared.ok);
if (server.rdb_child_pid != -1) {
kill(server.rdb_child_pid,SIGUSR1);
rdbRemoveTempFile(server.rdb_child_pid);
closeChildInfoPipe();
updateDictResizePolicy();
}
if (server.rdb_child_pid != -1) killRDBChild();
if (server.saveparamslen > 0) {
/* Normally rdbSave() will reset dirty, but we don't want this here
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */

View File

@ -2225,6 +2225,16 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
}
}
/* Kill the RDB saving child using SIGUSR1 (so that the parent will know
* the child did not exit for an error, but because we wanted), and performs
* the cleanup needed. */
void killRDBChild(void) {
kill(server.rdb_child_pid,SIGUSR1);
rdbRemoveTempFile(server.rdb_child_pid);
closeChildInfoPipe();
updateDictResizePolicy();
}
/* Spawn an RDB child that writes the RDB to the sockets of the slaves
* that are currently in SLAVE_STATE_WAIT_BGSAVE_START state. */
int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {

View File

@ -1254,10 +1254,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
"Killing process %ld and removing its temp file to avoid "
"any race",
(long) server.rdb_child_pid);
kill(server.rdb_child_pid,SIGUSR1);
rdbRemoveTempFile(server.rdb_child_pid);
closeChildInfoPipe();
updateDictResizePolicy();
killRDBChild();
}
if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {

View File

@ -2798,8 +2798,7 @@ int prepareForShutdown(int flags) {
overwrite the synchronous saving did by SHUTDOWN. */
if (server.rdb_child_pid != -1) {
serverLog(LL_WARNING,"There is a child saving an .rdb. Killing it!");
kill(server.rdb_child_pid,SIGUSR1);
rdbRemoveTempFile(server.rdb_child_pid);
killRDBChild();
}
if (server.aof_state != AOF_OFF) {
@ -2814,7 +2813,7 @@ int prepareForShutdown(int flags) {
}
serverLog(LL_WARNING,
"There is a child rewriting the AOF. Killing it!");
kill(server.aof_child_pid,SIGUSR1);
killAppendOnlyChild();
}
/* Append only file: flush buffers and fsync() the AOF at exit */
serverLog(LL_NOTICE,"Calling fsync() on the AOF file.");

View File

@ -1674,6 +1674,7 @@ int writeCommandsDeniedByDiskError(void);
/* RDB persistence */
#include "rdb.h"
int rdbSaveRio(rio *rdb, int *error, int flags, rdbSaveInfo *rsi);
void killRDBChild(void);
/* AOF persistence */
void flushAppendOnlyFile(int force);
@ -1687,6 +1688,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal);
void aofRewriteBufferReset(void);
unsigned long aofRewriteBufferSize(void);
ssize_t aofReadDiffFromParent(void);
void killAppendOnlyChild(void);
/* Child info */
void openChildInfoPipe(void);