summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuYunlong <xzsyeb@126.com>2020-09-25 13:08:06 +0800
committerOran Agra <oran@redislabs.com>2020-10-27 08:49:22 +0200
commit54eb66495f1e11ca2018579cdc37e3a747b00c72 (patch)
tree7c6857e95ebec370a550adb793c193273401c627
parent77f91e09cf70d96ee0bc1806d503fc69322257c5 (diff)
downloadredis-54eb66495f1e11ca2018579cdc37e3a747b00c72.tar.gz
Add fsync to readSyncBulkPayload(). (#7839)
We should sync temp DB file before renaming as rdb_fsync_range does not use flag `SYNC_FILE_RANGE_WAIT_AFTER`. Refer to `Linux Programmer's Manual`: SYNC_FILE_RANGE_WAIT_AFTER Wait upon write-out of all pages in the range after performing any write. (cherry picked from commit 0d62caab2113fc12077aadd469e80dd19ca78db2)
-rw-r--r--src/replication.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/replication.c b/src/replication.c
index a5e94db7a..1be5b069a 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -1292,6 +1292,17 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
rdbRemoveTempFile(server.rdb_child_pid);
}
+ /* Make sure the new file (also used for persistence) is fully synced
+ * (not covered by earlier calls to rdb_fsync_range). */
+ if (fsync(server.repl_transfer_fd) == -1) {
+ serverLog(LL_WARNING,
+ "Failed trying to sync the temp DB to disk in "
+ "MASTER <-> REPLICA synchronization: %s",
+ strerror(errno));
+ cancelReplicationHandshake();
+ return;
+ }
+
if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) {
serverLog(LL_WARNING,"Failed trying to rename the temp DB into dump.rdb in MASTER <-> REPLICA synchronization: %s", strerror(errno));
cancelReplicationHandshake();