hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject svn commit: r1493981 - in /hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java
Date Tue, 18 Jun 2013 01:21:09 GMT
Author: cmccabe
Date: Tue Jun 18 01:21:09 2013
New Revision: 1493981

URL: http://svn.apache.org/r1493981
Log:
HDFS-4626. ClientProtocol#getLinkTarget should throw an exception for non-symlink and non-existent
paths.  (Andrew Wang via cmccabe)

Modified:
    hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
    hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java

Modified: hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1493981&r1=1493980&r2=1493981&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Tue
Jun 18 01:21:09 2013
@@ -155,6 +155,9 @@ Release 2.1.0-beta - UNRELEASED
 
   BUG FIXES
 
+    HDFS-4626. ClientProtocol#getLinkTarget should throw an exception for
+    non-symlink and non-existent paths.  (Andrew Wang via cmccabe)
+
     HDFS-3934. duplicative dfs_hosts entries handled wrong. (Colin Patrick
     McCabe)
     

Modified: hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java?rev=1493981&r1=1493980&r2=1493981&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
(original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java
Tue Jun 18 01:21:09 2013
@@ -880,19 +880,21 @@ class NameNodeRpcServer implements Namen
   @Override // ClientProtocol
   public String getLinkTarget(String path) throws IOException {
     metrics.incrGetLinkTargetOps();
+    HdfsFileStatus stat = null;
     try {
-      HdfsFileStatus stat = namesystem.getFileInfo(path, false);
-      if (stat != null) {
-        // NB: getSymlink throws IOException if !stat.isSymlink() 
-        return stat.getSymlink();
-      }
+      stat = namesystem.getFileInfo(path, false);
     } catch (UnresolvedPathException e) {
       return e.getResolvedPath().toString();
     } catch (UnresolvedLinkException e) {
       // The NameNode should only throw an UnresolvedPathException
       throw new AssertionError("UnresolvedLinkException thrown");
     }
-    return null;
+    if (stat == null) {
+      throw new FileNotFoundException("File does not exist: " + path);
+    } else if (!stat.isSymlink()) {
+      throw new IOException("Path " + path + " is not a symbolic link");
+    }
+    return stat.getSymlink();
   }
 
 

Modified: hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java?rev=1493981&r1=1493980&r2=1493981&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java
(original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestResolveHdfsSymlink.java
Tue Jun 18 01:21:09 2013
@@ -18,11 +18,16 @@
 
 package org.apache.hadoop.fs;
 
+import static org.junit.Assert.fail;
+
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.DFSClient;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.DFSTestUtil;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
@@ -31,6 +36,7 @@ import org.apache.hadoop.hdfs.security.t
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
+import org.apache.hadoop.test.GenericTestUtils;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -122,4 +128,48 @@ public class TestResolveHdfsSymlink {
     ((Hdfs) afs).cancelDelegationToken(
         (Token<? extends AbstractDelegationTokenIdentifier>) tokenList.get(0));
   }
+
+  /**
+   * Verifies that attempting to resolve a non-symlink results in client
+   * exception
+   */
+  @Test
+  public void testLinkTargetNonSymlink() throws UnsupportedFileSystemException,
+      IOException {
+    FileContext fc = null;
+    Path notSymlink = new Path("/notasymlink");
+    try {
+      fc = FileContext.getFileContext(cluster.getFileSystem().getUri());
+      fc.create(notSymlink, EnumSet.of(CreateFlag.CREATE));
+      DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
+          cluster.getConfiguration(0));
+      try {
+        client.getLinkTarget(notSymlink.toString());
+        fail("Expected exception for resolving non-symlink");
+      } catch (IOException e) {
+        GenericTestUtils.assertExceptionContains("is not a symbolic link", e);
+      }
+    } finally {
+      if (fc != null) {
+        fc.delete(notSymlink, false);
+      }
+    }
+  }
+
+  /**
+   * Tests that attempting to resolve a non-existent-file
+   */
+  @Test
+  public void testLinkTargetNonExistent() throws IOException {
+    Path doesNotExist = new Path("/filethatdoesnotexist");
+    DFSClient client = new DFSClient(cluster.getFileSystem().getUri(),
+        cluster.getConfiguration(0));
+    try {
+      client.getLinkTarget(doesNotExist.toString());
+      fail("Expected exception for resolving non-existent file");
+    } catch (FileNotFoundException e) {
+      GenericTestUtils.assertExceptionContains("File does not exist: "
+          + doesNotExist.toString(), e);
+    }
+  }
 }



Mime
View raw message