summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-01-10 13:06:39 +0100
committerGitHub <noreply@github.com>2020-01-10 13:06:39 +0100
commitb8b8dd5c159f37f1ebb1b045254ad29063a40425 (patch)
treebc5c0a439181cdd7695d05f076bb452424317a0b
parent51a01ca8a630fbdee3a1e71fbf318225652afea9 (diff)
parent2bc8db9ca5f80e7c69ca51932aed05745d727ec5 (diff)
downloadredis-b8b8dd5c159f37f1ebb1b045254ad29063a40425.tar.gz
Merge pull request #6114 from ShooterIT/async-rename-rdb
Rename rdb when replica finish receiving rdb asynchronously
-rw-r--r--src/replication.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/replication.c b/src/replication.c
index 68dc77a61..b7e77184a 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -31,6 +31,7 @@
#include "server.h"
#include "cluster.h"
+#include "bio.h"
#include <sys/time.h>
#include <unistd.h>
@@ -1616,14 +1617,20 @@ void readSyncBulkPayload(connection *conn) {
killRDBChild();
}
+ /* Rename rdb like renaming rewrite aof asynchronously. */
+ int old_rdb_fd = open(server.rdb_filename,O_RDONLY|O_NONBLOCK);
if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {
serverLog(LL_WARNING,
"Failed trying to rename the temp DB into %s in "
"MASTER <-> REPLICA synchronization: %s",
server.rdb_filename, strerror(errno));
cancelReplicationHandshake();
+ if (old_rdb_fd != -1) close(old_rdb_fd);
return;
}
+ /* Close old rdb asynchronously. */
+ if (old_rdb_fd != -1) bioCreateBackgroundJob(BIO_CLOSE_FILE,(void*)(long)old_rdb_fd,NULL,NULL);
+
if (rdbLoad(server.rdb_filename,&rsi,RDBFLAGS_REPLICATION) != C_OK) {
serverLog(LL_WARNING,
"Failed trying to load the MASTER synchronization "