From 7c5ab54a787fd88f9edd1ad9f1f5fd682e261abb Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Sun, 9 Aug 2020 19:33:36 -0700 Subject: [PATCH 1/2] HDFS-15515: mkdirs on fallback should throw IOE out instead of suppressing and returning false --- .../java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java | 7 +++---- .../hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index baf0027fa6a84..ad62f94ec6297 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -1421,7 +1421,7 @@ public FsStatus getStatus(Path p) throws IOException { @Override public boolean mkdirs(Path dir, FsPermission permission) - throws AccessControlException, FileAlreadyExistsException { + throws IOException { if (theInternalDir.isRoot() && dir == null) { throw new FileAlreadyExistsException("/ already exits"); } @@ -1451,7 +1451,7 @@ public boolean mkdirs(Path dir, FsPermission permission) .append(linkedFallbackFs.getUri()); LOG.debug(msg.toString(), e); } - return false; + throw e; } } @@ -1459,8 +1459,7 @@ public boolean mkdirs(Path dir, FsPermission permission) } @Override - public boolean mkdirs(Path dir) - throws AccessControlException, FileAlreadyExistsException { + public boolean mkdirs(Path dir) throws IOException { return mkdirs(dir, null); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java index bd2b5af02ad87..ce99a3b763143 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java @@ -759,7 +759,11 @@ public void testMkdirsShouldReturnFalseWhenFallbackFSNotAvailable() cluster.shutdownNameNodes(); // Stopping fallback server // /user1/test1 does not exist in mount internal dir tree, it would // attempt to create in fallback. - assertFalse(vfs.mkdirs(nextLevelToInternalDir)); + try { + vfs.mkdirs(nextLevelToInternalDir); + fail("dir creation should fail."); + } catch (IOException ioe) { + } cluster.restartNameNodes(); // should return true succeed when fallback fs is back to normal. assertTrue(vfs.mkdirs(nextLevelToInternalDir)); From d1b59ffe0a15f5e718ae6dc7502fba6deac04498 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Mon, 10 Aug 2020 10:43:49 -0700 Subject: [PATCH 2/2] Used LambdaTestUtils#intercept in test --- .../hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java index ce99a3b763143..e7317608147be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkFallback.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; +import static org.apache.hadoop.test.LambdaTestUtils.intercept; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -759,11 +760,9 @@ public void testMkdirsShouldReturnFalseWhenFallbackFSNotAvailable() cluster.shutdownNameNodes(); // Stopping fallback server // /user1/test1 does not exist in mount internal dir tree, it would // attempt to create in fallback. - try { + intercept(IOException.class, () -> { vfs.mkdirs(nextLevelToInternalDir); - fail("dir creation should fail."); - } catch (IOException ioe) { - } + }); cluster.restartNameNodes(); // should return true succeed when fallback fs is back to normal. assertTrue(vfs.mkdirs(nextLevelToInternalDir));