From d6c31a3e6b60c4b8af9ae4661f16614805654e59 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Thu, 7 Dec 2017 14:50:30 -0800 Subject: [PATCH] HDFS-11915. Sync rbw dir on the first hsync() to avoid file lost on power failure. Contributed by Vinayakumar B. --- .../apache/hadoop/hdfs/server/datanode/BlockReceiver.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java index c052d52cf9e..afb9e2afb00 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java @@ -126,6 +126,7 @@ class BlockReceiver implements Closeable { private boolean syncOnClose; private volatile boolean dirSyncOnFinalize; + private boolean dirSyncOnHSyncDone = false; private long restartBudget; /** the reference of the volume where the block receiver writes to */ private ReplicaHandler replicaHandler; @@ -424,6 +425,10 @@ class BlockReceiver implements Closeable { } flushTotalNanos += flushEndNanos - flushStartNanos; } + if (isSync && !dirSyncOnHSyncDone && replicaInfo instanceof LocalReplica) { + ((LocalReplica) replicaInfo).fsyncDirectory(); + dirSyncOnHSyncDone = true; + } if (checksumOut != null || streams.getDataOut() != null) { datanode.metrics.addFlushNanos(flushTotalNanos); if (isSync) {