[
https://issues.apache.org/jira/browse/HDFS-5939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13908708#comment-13908708
]
Haohui Mai commented on HDFS-5939:
----------------------------------
The patch looks good. Some comments on the unit test:
{code}
+ LOG.info("Running testNoDatanode ...");
+ LOG.info("Done with testNoDatanode.");
{code}
This is unnecessary.
{code}
+ new MiniDFSCluster.Builder(conf).numDataNodes(numDNs).build();
{code}
You can set numDNs to zero in order to reproduce this bug. The statement has to
be placed in the {{try..finally}} block as start nn / dn could fail.
{code}
+ WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsFileSystem.SCHEME)
+ .setPermission(new Path("/"),
+ new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
+
+ for (int i=0; i < numDNs; i++) {
+ cluster.stopDataNode(0);
+ }
+ // Restart namenode so namenode is updated with the
+ // information that datanodes are gone
+ cluster.restartNameNodes();
+
{code}
The above code are unnecessary.
{code}
+ FileSystem fs = WebHdfsTestUtil.getWebHdfsFileSystem(conf,
+ WebHdfsFileSystem.SCHEME);
+ Path d = new Path("/");
+ Path p = new Path(d, "filex");
+ Assert.assertTrue(fs.createNewFile(p));
+ } catch (IOException ex) {
+ boolean expected = ex.getMessage().contains("Failed to find datanode");
+ LOG.info("Caught exception \"" + ex + "\" " +
+ (expected? " as expected." : "unexpectedly."));
+ Assert.assertTrue(expected);
{code}
The first assert is unreachable. You can assume that in the normal case the
webhdfs won't fail (it'll be caught by other unit tests). There is little value
to explicitly check whether the exception has to contain the message. Thus you
can write something like this:
{code}
@Expected(class=IOException.class)
public void testNoDatanode() ...{
...
+ FileSystem fs = WebHdfsTestUtil.getWebHdfsFileSystem(conf,
+ WebHdfsFileSystem.SCHEME);
fs.create(new Path("/foo")).close();
{code}
The name of the unit test might need to convey more information, such as
{{testCreateWithoutDataNode}}.
> WebHdfs returns misleading error code and logs nothing if trying to create a
> file with no DNs in cluster
> --------------------------------------------------------------------------------------------------------
>
> Key: HDFS-5939
> URL: https://issues.apache.org/jira/browse/HDFS-5939
> Project: Hadoop HDFS
> Issue Type: Bug
> Components: hdfs-client
> Affects Versions: 2.3.0
> Reporter: Yongjun Zhang
> Assignee: Yongjun Zhang
> Attachments: HDFS-5939.001.patch, HDFS-5939.002.patch,
> HDFS-5939.003.patch
>
>
> When trying to access hdfs via webhdfs, and when datanode is dead, user will
> see an exception below without any clue that it's caused by dead datanode:
> $ curl -i -X PUT
> ".../webhdfs/v1/t1?op=CREATE&user.name=<userName>&overwrite=false"
> ...
> {"RemoteException":{"exception":"IllegalArgumentException","javaClassName":"java.lang.IllegalArgumentException","message":"n
> must be positive"}}
> Need to fix the report to give user hint about dead datanode.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)