Skip to content

Commit affb8c3

Browse files
HDFS-17746. [ARR] The behavior of throwing exception in getListing should be consistent with sync mode. (#7464). Contributed by hfutatzhanghb.
Reviewed-by: Jian Zhang <[email protected]> Signed-off-by: He Xiaoqiao <[email protected]>
1 parent 1416c94 commit affb8c3

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -526,25 +526,24 @@ public DirectoryListing getListing(
526526
@Override
527527
protected List<RemoteResult<RemoteLocation, DirectoryListing>> getListingInt(
528528
String src, byte[] startAfter, boolean needLocation) throws IOException {
529-
List<RemoteLocation> locations =
530-
rpcServer.getLocationsForPath(src, false, false);
531-
// Locate the dir and fetch the listing.
532-
if (locations.isEmpty()) {
533-
asyncComplete(new ArrayList<>());
534-
return asyncReturn(List.class);
535-
}
536-
asyncTry(() -> {
529+
try {
530+
List<RemoteLocation> locations =
531+
rpcServer.getLocationsForPath(src, false, false);
532+
// Locate the dir and fetch the listing.
533+
if (locations.isEmpty()) {
534+
asyncComplete(new ArrayList<>());
535+
return asyncReturn(List.class);
536+
}
537537
RemoteMethod method = new RemoteMethod("getListing",
538538
new Class<?>[] {String.class, startAfter.getClass(), boolean.class},
539539
new RemoteParam(), startAfter, needLocation);
540540
rpcClient.invokeConcurrent(locations, method, false, -1,
541541
DirectoryListing.class);
542-
});
543-
asyncCatch((CatchFunction<List, RouterResolveException>) (o, e) -> {
542+
} catch (NoLocationException | RouterResolveException e) {
544543
LOG.debug("Cannot get locations for {}, {}.", src, e.getMessage());
545-
LOG.info("Cannot get locations for {}, {}.", src, e.getMessage());
546-
return new ArrayList<>();
547-
}, RouterResolveException.class);
544+
asyncComplete(new ArrayList<>());
545+
}
546+
548547
return asyncReturn(List.class);
549548
}
550549

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.fs.FileSystem;
2222
import org.apache.hadoop.fs.Path;
23-
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
2423
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster;
2524
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
2625
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
@@ -35,14 +34,15 @@
3534
import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse;
3635
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest;
3736
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
38-
import org.apache.hadoop.util.Time;
37+
import org.apache.hadoop.test.LambdaTestUtils;
3938
import org.junit.After;
4039
import org.junit.AfterClass;
4140
import org.junit.BeforeClass;
4241
import org.junit.Test;
4342
import org.slf4j.Logger;
4443
import org.slf4j.LoggerFactory;
4544

45+
import java.io.FileNotFoundException;
4646
import java.io.IOException;
4747
import java.util.Collections;
4848

@@ -56,8 +56,6 @@ public class TestRouterAsyncMountTable {
5656
public static final Logger LOG = LoggerFactory.getLogger(TestRouterAsyncMountTable.class);
5757

5858
private static StateStoreDFSCluster cluster;
59-
private static MiniRouterDFSCluster.NamenodeContext nnContext0;
60-
private static MiniRouterDFSCluster.NamenodeContext nnContext1;
6159
private static MiniRouterDFSCluster.RouterContext routerContext;
6260
private static MountTableResolver mountTable;
6361
private static FileSystem routerFs;
@@ -78,9 +76,6 @@ public static void globalSetUp() throws Exception {
7876
cluster.startRouters();
7977
cluster.waitClusterUp();
8078

81-
// Get the end points.
82-
nnContext0 = cluster.getNamenode("ns0", null);
83-
nnContext1 = cluster.getNamenode("ns1", null);
8479
routerContext = cluster.getRandomRouter();
8580
routerFs = routerContext.getFileSystem();
8681
Router router = routerContext.getRouter();
@@ -134,7 +129,6 @@ private boolean addMountTable(final MountTable entry) throws IOException {
134129

135130
@Test
136131
public void testGetEnclosingRoot() throws Exception {
137-
138132
// Add a read only entry.
139133
MountTable readOnlyEntry = MountTable.newInstance(
140134
"/readonly", Collections.singletonMap("ns0", "/testdir"));
@@ -155,4 +149,13 @@ public void testGetEnclosingRoot() throws Exception {
155149
// Path does not need to exist.
156150
assertEquals(routerFs.getEnclosingRoot(new Path("/regular/pathDNE")), new Path("/regular"));
157151
}
152+
153+
@Test
154+
public void testListNonExistPath() throws Exception {
155+
mountTable.setDefaultNSEnable(false);
156+
LambdaTestUtils.intercept(FileNotFoundException.class,
157+
"File /base does not exist.",
158+
"Expect FileNotFoundException.",
159+
() -> routerFs.listStatus(new Path("/base")));
160+
}
158161
}

0 commit comments

Comments
 (0)