This is an automated email from the ASF dual-hosted git repository. keepromise pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new affb8c36aac HDFS-17746. [ARR] The behavior of throwing exception in getListing should be consistent with sync mode. (#7464). Contributed by hfutatzhanghb. affb8c36aac is described below commit affb8c36aac3d8bba47b837e2f03ed454f165686 Author: hfutatzhanghb <hfutzhan...@163.com> AuthorDate: Tue Mar 11 10:22:38 2025 +0800 HDFS-17746. [ARR] The behavior of throwing exception in getListing should be consistent with sync mode. (#7464). Contributed by hfutatzhanghb. Reviewed-by: Jian Zhang <keeprom...@apache.org> Signed-off-by: He Xiaoqiao <hexiaoq...@apache.org> --- .../router/async/RouterAsyncClientProtocol.java | 25 +++++++++++----------- .../router/async/TestRouterAsyncMountTable.java | 19 +++++++++------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java index c12249d16b4..88399e6bd47 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java @@ -526,25 +526,24 @@ public DirectoryListing getListing( @Override protected List<RemoteResult<RemoteLocation, DirectoryListing>> getListingInt( String src, byte[] startAfter, boolean needLocation) throws IOException { - List<RemoteLocation> locations = - rpcServer.getLocationsForPath(src, false, false); - // Locate the dir and fetch the listing. - if (locations.isEmpty()) { - asyncComplete(new ArrayList<>()); - return asyncReturn(List.class); - } - asyncTry(() -> { + try { + List<RemoteLocation> locations = + rpcServer.getLocationsForPath(src, false, false); + // Locate the dir and fetch the listing. + if (locations.isEmpty()) { + asyncComplete(new ArrayList<>()); + return asyncReturn(List.class); + } RemoteMethod method = new RemoteMethod("getListing", new Class<?>[] {String.class, startAfter.getClass(), boolean.class}, new RemoteParam(), startAfter, needLocation); rpcClient.invokeConcurrent(locations, method, false, -1, DirectoryListing.class); - }); - asyncCatch((CatchFunction<List, RouterResolveException>) (o, e) -> { + } catch (NoLocationException | RouterResolveException e) { LOG.debug("Cannot get locations for {}, {}.", src, e.getMessage()); - LOG.info("Cannot get locations for {}, {}.", src, e.getMessage()); - return new ArrayList<>(); - }, RouterResolveException.class); + asyncComplete(new ArrayList<>()); + } + return asyncReturn(List.class); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java index 177f6586079..b86260b0665 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java @@ -20,7 +20,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster; import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster; @@ -35,7 +34,7 @@ import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse; import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest; import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; -import org.apache.hadoop.util.Time; +import org.apache.hadoop.test.LambdaTestUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -43,6 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collections; @@ -56,8 +56,6 @@ public class TestRouterAsyncMountTable { public static final Logger LOG = LoggerFactory.getLogger(TestRouterAsyncMountTable.class); private static StateStoreDFSCluster cluster; - private static MiniRouterDFSCluster.NamenodeContext nnContext0; - private static MiniRouterDFSCluster.NamenodeContext nnContext1; private static MiniRouterDFSCluster.RouterContext routerContext; private static MountTableResolver mountTable; private static FileSystem routerFs; @@ -78,9 +76,6 @@ public static void globalSetUp() throws Exception { cluster.startRouters(); cluster.waitClusterUp(); - // Get the end points. - nnContext0 = cluster.getNamenode("ns0", null); - nnContext1 = cluster.getNamenode("ns1", null); routerContext = cluster.getRandomRouter(); routerFs = routerContext.getFileSystem(); Router router = routerContext.getRouter(); @@ -134,7 +129,6 @@ private boolean addMountTable(final MountTable entry) throws IOException { @Test public void testGetEnclosingRoot() throws Exception { - // Add a read only entry. MountTable readOnlyEntry = MountTable.newInstance( "/readonly", Collections.singletonMap("ns0", "/testdir")); @@ -155,4 +149,13 @@ public void testGetEnclosingRoot() throws Exception { // Path does not need to exist. assertEquals(routerFs.getEnclosingRoot(new Path("/regular/pathDNE")), new Path("/regular")); } + + @Test + public void testListNonExistPath() throws Exception { + mountTable.setDefaultNSEnable(false); + LambdaTestUtils.intercept(FileNotFoundException.class, + "File /base does not exist.", + "Expect FileNotFoundException.", + () -> routerFs.listStatus(new Path("/base"))); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org