From 8b1abad18527402c6d99e9b48424ce7cec52148b Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Sat, 14 Jun 2014 02:17:10 +0000 Subject: [PATCH] HDFS-6499. Use NativeIO#renameTo instead of File#renameTo in FileJournalManager. Contributed by Yongjun Zhang. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1602543 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../server/namenode/FileJournalManager.java | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 80421efc3e6..16dcdebd784 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -183,6 +183,9 @@ Release 2.5.0 - UNRELEASED HDFS-6529. Trace logging for RemoteBlockReader2 to identify remote datanode and file being read. (Anubhav Dhoot via atm) + HDFS-6499. Use NativeIO#renameTo instead of File#renameTo in + FileJournalManager. (Yongjun Zhang via atm) + OPTIMIZATIONS HDFS-6214. Webhdfs has poor throughput for files >2GB (daryn) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java index 193e9904226..10a28e323c0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FileJournalManager.java @@ -42,6 +42,7 @@ import org.apache.hadoop.hdfs.server.namenode.NNStorageRetentionManager.StoragePurger; import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog; +import org.apache.hadoop.io.nativeio.NativeIO; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; @@ -132,10 +133,14 @@ synchronized public void finalizeLogSegment(long firstTxId, long lastTxId) Preconditions.checkState(!dstFile.exists(), "Can't finalize edits file " + inprogressFile + " since finalized file " + "already exists"); - if (!inprogressFile.renameTo(dstFile)) { + + try { + NativeIO.renameTo(inprogressFile, dstFile); + } catch (IOException e) { errorReporter.reportErrorOnFile(dstFile); - throw new IllegalStateException("Unable to finalize edits file " + inprogressFile); + throw new IllegalStateException("Unable to finalize edits file " + inprogressFile, e); } + if (inprogressFile.equals(currentInProgress)) { currentInProgress = null; } @@ -513,11 +518,16 @@ private void renameSelf(String newSuffix) throws IOException { File src = file; File dst = new File(src.getParent(), src.getName() + newSuffix); // renameTo fails on Windows if the destination file already exists. - if (!src.renameTo(dst)) { - if (!dst.delete() || !src.renameTo(dst)) { - throw new IOException( - "Couldn't rename log " + src + " to " + dst); + try { + if (dst.exists()) { + if (!dst.delete()) { + throw new IOException("Couldn't delete " + dst); + } } + NativeIO.renameTo(src, dst); + } catch (IOException e) { + throw new IOException( + "Couldn't rename log " + src + " to " + dst, e); } file = dst; }