From d5c046518e9b519747d746e233ca256fbd66176d Mon Sep 17 00:00:00 2001 From: huhaiyang Date: Thu, 9 Feb 2023 10:47:57 +0800 Subject: [PATCH] HDFS-16910. Fix incorrectly initializing RandomAccessFile caused flush performance decreased for JN (#5359) --- .../hadoop/hdfs/server/namenode/EditLogFileOutputStream.java | 4 ++-- .../hadoop-hdfs/src/main/resources/hdfs-default.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java index c5d7ea7eb41..9dd3c24d5b4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileOutputStream.java @@ -84,9 +84,9 @@ public class EditLogFileOutputStream extends EditLogOutputStream { doubleBuf = new EditsDoubleBuffer(size); RandomAccessFile rp; if (shouldSyncWritesAndSkipFsync) { - rp = new RandomAccessFile(name, "rw"); + rp = new RandomAccessFile(name, "rwd"); } else { - rp = new RandomAccessFile(name, "rws"); + rp = new RandomAccessFile(name, "rw"); } try { fp = new FileOutputStream(rp.getFD()); // open for append diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml index 49f75aac955..5643a9b5c5e 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml @@ -2721,10 +2721,10 @@ Specifies whether to flush edit log file channel. When set, expensive FileChannel#force calls are skipped and synchronous disk writes are - enabled instead by opening the edit log file with RandomAccessFile("rws") + enabled instead by opening the edit log file with RandomAccessFile("rwd") flags. This can significantly improve the performance of edit log writes on the Windows platform. - Note that the behavior of the "rws" flags is platform and hardware specific + Note that the behavior of the "rwd" flags is platform and hardware specific and might not provide the same level of guarantees as FileChannel#force. For example, the write will skip the disk-cache on SAS and SCSI devices while it might not on SATA devices. This is an expert level setting,