Commit 14532772 authored by Wang Yuan's avatar Wang Yuan Committed by Oran Agra
Browse files

Remove temporary aof and rdb files in a background thread (#7905)

If we fail or stop to rewrite aof, we need to remove temporary aof.
We also remove temporary rdb when replicas abort to receive rdb.
But currently we delete them in main thread, to avoid blocking,
we should use bg_unlink to remove them in a background thread.

Btw, we have already used this way to removed child process temporary rdb.

(cherry picked from commit aaacb8c9)
parent e4e24460
...@@ -1680,10 +1680,10 @@ void aofRemoveTempFile(pid_t childpid) { ...@@ -1680,10 +1680,10 @@ void aofRemoveTempFile(pid_t childpid) {
char tmpfile[256]; char tmpfile[256];
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) childpid); snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) childpid);
unlink(tmpfile); bg_unlink(tmpfile);
snprintf(tmpfile,256,"temp-rewriteaof-%d.aof", (int) childpid); snprintf(tmpfile,256,"temp-rewriteaof-%d.aof", (int) childpid);
unlink(tmpfile); bg_unlink(tmpfile);
} }
/* Update the server.aof_current_size field explicitly using stat(2) /* Update the server.aof_current_size field explicitly using stat(2)
......
...@@ -2453,7 +2453,7 @@ void replicationAbortSyncTransfer(void) { ...@@ -2453,7 +2453,7 @@ void replicationAbortSyncTransfer(void) {
undoConnectWithMaster(); undoConnectWithMaster();
if (server.repl_transfer_fd!=-1) { if (server.repl_transfer_fd!=-1) {
close(server.repl_transfer_fd); close(server.repl_transfer_fd);
unlink(server.repl_transfer_tmpfile); bg_unlink(server.repl_transfer_tmpfile);
zfree(server.repl_transfer_tmpfile); zfree(server.repl_transfer_tmpfile);
server.repl_transfer_tmpfile = NULL; server.repl_transfer_tmpfile = NULL;
server.repl_transfer_fd = -1; server.repl_transfer_fd = -1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment