Return-Path: X-Original-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 733DE102FC for ; Wed, 11 Dec 2013 01:33:48 +0000 (UTC) Received: (qmail 51915 invoked by uid 500); 11 Dec 2013 01:33:48 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 51875 invoked by uid 500); 11 Dec 2013 01:33:48 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 51867 invoked by uid 99); 11 Dec 2013 01:33:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 01:33:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Dec 2013 01:33:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5F9C82388A5B; Wed, 11 Dec 2013 01:33:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1550017 - in /hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs: ./ src/main/java/org/apache/hadoop/hdfs/server/namenode/ src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/ src/test/java/org/apache/hadoop/hdfs/s... Date: Wed, 11 Dec 2013 01:33:25 -0000 To: hdfs-commits@hadoop.apache.org From: jing9@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131211013325.5F9C82388A5B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jing9 Date: Wed Dec 11 01:33:24 2013 New Revision: 1550017 URL: http://svn.apache.org/r1550017 Log: HDFS-5427. Merge change r1538876 from branch-2. Modified: hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotBlocksMap.java Modified: hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1550017&r1=1550016&r2=1550017&view=diff ============================================================================== --- hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Wed Dec 11 01:33:24 2013 @@ -145,6 +145,9 @@ Release 2.3.0 - UNRELEASED HDFS-5257. addBlock() retry should return LocatedBlock with locations else client will get AIOBE. (Vinay via jing9) + HDFS-5427. Not able to read deleted files from snapshot directly under + snapshottable dir after checkpoint and NN restart. (Vinay via jing9) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES Modified: hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java?rev=1550017&r1=1550016&r2=1550017&view=diff ============================================================================== --- hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java (original) +++ hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java Wed Dec 11 01:33:24 2013 @@ -587,8 +587,12 @@ public class FSImageFormat { namesystem.dir.cacheName(child); if (child.isFile()) { + updateBlocksMap(child.asFile()); + } + } + + public void updateBlocksMap(INodeFile file) { // Add file->block mapping - final INodeFile file = child.asFile(); final BlockInfo[] blocks = file.getBlocks(); if (blocks != null) { final BlockManager bm = namesystem.getBlockManager(); @@ -597,7 +601,6 @@ public class FSImageFormat { } } } - } /** @return The FSDirectory of the namesystem where the fsimage is loaded */ public FSDirectory getFSDirectoryInLoading() { Modified: hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java?rev=1550017&r1=1550016&r2=1550017&view=diff ============================================================================== --- hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java (original) +++ hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java Wed Dec 11 01:33:24 2013 @@ -203,6 +203,9 @@ public class SnapshotFSImageFormat { // useful, but set the parent here to be consistent with the original // fsdir tree. deleted.setParent(parent); + if (deleted.isFile()) { + loader.updateBlocksMap(deleted.asFile()); + } } return deletedList; } Modified: hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotBlocksMap.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotBlocksMap.java?rev=1550017&r1=1550016&r2=1550017&view=diff ============================================================================== --- hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotBlocksMap.java (original) +++ hadoop/common/branches/branch-2.3/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotBlocksMap.java Wed Dec 11 01:33:24 2013 @@ -21,6 +21,7 @@ import static org.apache.hadoop.test.Gen import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -36,6 +37,8 @@ import org.apache.hadoop.hdfs.server.blo import org.apache.hadoop.hdfs.server.namenode.FSDirectory; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.INodeFile; +import org.apache.hadoop.hdfs.server.namenode.NameNode; +import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -205,4 +208,70 @@ public class TestSnapshotBlocksMap { assertExceptionContains("File does not exist: " + s1f0, e); } } + + /* + * Try to read the files inside snapshot but deleted in original place after + * restarting post checkpoint. refer HDFS-5427 + */ + @Test(timeout = 30000) + public void testReadSnapshotFileWithCheckpoint() throws Exception { + Path foo = new Path("/foo"); + hdfs.mkdirs(foo); + hdfs.allowSnapshot(foo); + Path bar = new Path("/foo/bar"); + DFSTestUtil.createFile(hdfs, bar, 100, (short) 2, 100024L); + hdfs.createSnapshot(foo, "s1"); + assertTrue(hdfs.delete(bar, true)); + + // checkpoint + NameNode nameNode = cluster.getNameNode(); + NameNodeAdapter.enterSafeMode(nameNode, false); + NameNodeAdapter.saveNamespace(nameNode); + NameNodeAdapter.leaveSafeMode(nameNode); + + // restart namenode to load snapshot files from fsimage + cluster.restartNameNode(true); + String snapshotPath = Snapshot.getSnapshotPath(foo.toString(), "s1/bar"); + DFSTestUtil.readFile(hdfs, new Path(snapshotPath)); + } + + /* + * Try to read the files inside snapshot but renamed to different file and + * deleted after restarting post checkpoint. refer HDFS-5427 + */ + @Test(timeout = 30000) + public void testReadRenamedSnapshotFileWithCheckpoint() throws Exception { + final Path foo = new Path("/foo"); + final Path foo2 = new Path("/foo2"); + hdfs.mkdirs(foo); + hdfs.mkdirs(foo2); + + hdfs.allowSnapshot(foo); + hdfs.allowSnapshot(foo2); + final Path bar = new Path(foo, "bar"); + final Path bar2 = new Path(foo2, "bar"); + DFSTestUtil.createFile(hdfs, bar, 100, (short) 2, 100024L); + hdfs.createSnapshot(foo, "s1"); + // rename to another snapshottable directory and take snapshot + assertTrue(hdfs.rename(bar, bar2)); + hdfs.createSnapshot(foo2, "s2"); + // delete the original renamed file to make sure blocks are not updated by + // the original file + assertTrue(hdfs.delete(bar2, true)); + + // checkpoint + NameNode nameNode = cluster.getNameNode(); + NameNodeAdapter.enterSafeMode(nameNode, false); + NameNodeAdapter.saveNamespace(nameNode); + NameNodeAdapter.leaveSafeMode(nameNode); + // restart namenode to load snapshot files from fsimage + cluster.restartNameNode(true); + // file in first snapshot + String barSnapshotPath = Snapshot.getSnapshotPath(foo.toString(), "s1/bar"); + DFSTestUtil.readFile(hdfs, new Path(barSnapshotPath)); + // file in second snapshot after rename+delete + String bar2SnapshotPath = Snapshot.getSnapshotPath(foo2.toString(), + "s2/bar"); + DFSTestUtil.readFile(hdfs, new Path(bar2SnapshotPath)); + } }