Author: wheat9 Date: Fri May 9 18:45:19 2014 New Revision: 1593593 URL: http://svn.apache.org/r1593593 Log: HDFS-6240. Merge r1593591 from trunk.
Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1593593&r1=1593592&r2=1593593&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Fri May 9 18:45:19 2014 @@ -186,6 +186,9 @@ Release 2.5.0 - UNRELEASED HDFS-5381. ExtendedBlock#hashCode should use both blockId and block pool ID (Benoy Antony via Colin Patrick McCabe) + HDFS-6240. WebImageViewer returns 404 if LISTSTATUS to an empty directory. + (Akira Ajisaka via wheat9) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java?rev=1593593&r1=1593592&r2=1593593&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java (original) +++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java Fri May 9 18:45:19 2014 @@ -261,6 +261,10 @@ class FSImageLoader { long id = getINodeId(path); FsImageProto.INodeSection.INode inode = inodes.get(id); if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) { + if (!dirmap.containsKey(id)) { + // if the directory is empty, return empty list + return list; + } long[] children = dirmap.get(id); for (long cid : children) { list.add(getFileStatus(inodes.get(cid), true)); @@ -416,7 +420,8 @@ class FSImageLoader { map.put("replication", 0); map.put("type", inode.getType()); map.put("fileId", inode.getId()); - map.put("childrenNum", dirmap.get(inode.getId()).length); + map.put("childrenNum", dirmap.containsKey(inode.getId()) ? + dirmap.get(inode.getId()).length : 0); return map; } case SYMLINK: { Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java?rev=1593593&r1=1593592&r2=1593593&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java (original) +++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java Fri May 9 18:45:19 2014 @@ -120,6 +120,11 @@ public class TestOfflineImageViewer { } } + // Create an empty directory + Path emptydir = new Path("/emptydir"); + hdfs.mkdirs(emptydir); + writtenFiles.put(emptydir.toString(), hdfs.getFileStatus(emptydir)); + // Get delegation tokens so we log the delegation token op Token<?>[] delegationTokens = hdfs .addDelegationTokens(TEST_RENEWER, null); @@ -205,8 +210,8 @@ public class TestOfflineImageViewer { matcher = p.matcher(output.getBuffer()); assertTrue(matcher.find() && matcher.groupCount() == 1); int totalDirs = Integer.parseInt(matcher.group(1)); - // totalDirs includes root directory - assertEquals(NUM_DIRS + 1, totalDirs); + // totalDirs includes root directory and empty directory + assertEquals(NUM_DIRS + 2, totalDirs); FileStatus maxFile = Collections.max(writtenFiles.values(), new Comparator<FileStatus>() { @@ -259,7 +264,7 @@ public class TestOfflineImageViewer { // verify the number of directories FileStatus[] statuses = webhdfs.listStatus(new Path("/")); - assertEquals(NUM_DIRS, statuses.length); + assertEquals(NUM_DIRS + 1, statuses.length); // contains empty directory // verify the number of files in the directory statuses = webhdfs.listStatus(new Path("/dir0")); @@ -270,6 +275,10 @@ public class TestOfflineImageViewer { FileStatus expected = writtenFiles.get("/dir0/file0"); compareFile(expected, status); + // LISTSTATUS operation to an empty directory + statuses = webhdfs.listStatus(new Path("/emptydir")); + assertEquals(0, statuses.length); + // LISTSTATUS operation to a invalid path URL url = new URL("http://localhost:" + port + "/webhdfs/v1/invalid/?op=LISTSTATUS");