Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1E731109E4 for ; Wed, 24 Dec 2014 19:35:24 +0000 (UTC) Received: (qmail 28486 invoked by uid 500); 24 Dec 2014 19:35:16 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 28211 invoked by uid 500); 24 Dec 2014 19:35:16 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 27780 invoked by uid 99); 24 Dec 2014 19:35:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Dec 2014 19:35:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C1A8AA37DCA; Wed, 24 Dec 2014 19:35:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhz@apache.org To: common-commits@hadoop.apache.org Date: Wed, 24 Dec 2014 19:35:24 -0000 Message-Id: <7ba64aaa2285441898ba087704d9519f@git.apache.org> In-Reply-To: <37d82d341aa143f1bda35bb9397804ad@git.apache.org> References: <37d82d341aa143f1bda35bb9397804ad@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/50] hadoop git commit: HDFS-7373. Clean up temporary files after fsimage transfer failures. Contributed by Kihwal Lee HDFS-7373. Clean up temporary files after fsimage transfer failures. Contributed by Kihwal Lee Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/21160436 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/21160436 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/21160436 Branch: refs/heads/HDFS-EC Commit: 21160436059c6f3afcacb9e2f14045448b1ff539 Parents: 52ff324 Author: Kihwal Lee Authored: Thu Dec 18 12:58:59 2014 -0600 Committer: Zhe Zhang Committed: Wed Dec 24 11:22:14 2014 -0800 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/TransferFsImage.java | 21 ++++++++++++++++++++ .../hdfs/server/namenode/TestCheckpoint.java | 19 ++++++++++++++++++ 3 files changed, 43 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/21160436/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 8e9961a..8150a54 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -468,6 +468,9 @@ Release 2.7.0 - UNRELEASED HDFS-7531. Improve the concurrent access on FsVolumeList (Lei Xu via Colin P. McCabe) + HDFS-7373. Clean up temporary files after fsimage transfer failures. + (kihwal) + OPTIMIZATIONS HDFS-7454. Reduce memory footprint for AclEntries in NameNode. http://git-wip-us.apache.org/repos/asf/hadoop/blob/21160436/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java index 160371a..1f52ff7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java @@ -528,10 +528,18 @@ public class TransferFsImage { fos.getChannel().force(true); fos.close(); } + + // Something went wrong and did not finish reading. + // Remove the temporary files. + if (!finishedReceiving) { + deleteTmpFiles(localPaths); + } + if (finishedReceiving && received != advertisedSize) { // only throw this exception if we think we read all of it on our end // -- otherwise a client-side IOException would be masked by this // exception that makes it look like a server-side problem! + deleteTmpFiles(localPaths); throw new IOException("File " + url + " received length " + received + " is not of the advertised size " + advertisedSize); @@ -548,6 +556,7 @@ public class TransferFsImage { if (advertisedDigest != null && !computedDigest.equals(advertisedDigest)) { + deleteTmpFiles(localPaths); throw new IOException("File " + url + " computed digest " + computedDigest + " does not match advertised digest " + advertisedDigest); @@ -558,6 +567,18 @@ public class TransferFsImage { } } + private static void deleteTmpFiles(List files) { + if (files == null) { + return; + } + + LOG.info("Deleting temporary files: " + files); + for (File file : files) { + file.delete(); // ignore the return value + } + } + + private static MD5Hash parseMD5Header(HttpURLConnection connection) { String header = connection.getHeaderField(MD5_HEADER); return (header != null) ? new MD5Hash(header) : null; http://git-wip-us.apache.org/repos/asf/hadoop/blob/21160436/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java index bb4689d..95da838 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java @@ -633,6 +633,22 @@ public class TestCheckpoint { }); } + private void checkTempImages(NNStorage storage) throws IOException { + List dirs = new ArrayList(); + dirs.add(storage.getStorageDir(0).getCurrentDir()); + dirs.add(storage.getStorageDir(1).getCurrentDir()); + + for (File dir : dirs) { + File[] list = dir.listFiles(); + for (File f : list) { + // Throw an exception if a temp image file is found. + if(f.getName().contains(NNStorage.NameNodeFile.IMAGE_NEW.getName())) { + throw new IOException("Found " + f); + } + } + } + } + /** * Simulate 2NN failing to send the whole file (error type 3) * The length header in the HTTP transfer should prevent @@ -694,6 +710,9 @@ public class TestCheckpoint { GenericTestUtils.assertExceptionContains(exceptionSubstring, e); } Mockito.reset(faultInjector); + // Make sure there is no temporary files left around. + checkTempImages(cluster.getNameNode().getFSImage().getStorage()); + checkTempImages(secondary.getFSImage().getStorage()); secondary.shutdown(); // secondary namenode crash! secondary = null;