Skip to content

Commit adba37e

Browse files
committed
HDFS-17788. [ARR] getFileInfo not handle exception rightly which may cause FileNotFoundException in DistributedFileSystem.
1 parent 912c260 commit adba37e

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ public HdfsFileStatus getFileInfo(String src) throws IOException {
579579
if (e instanceof NoLocationException
580580
|| e instanceof RouterResolveException) {
581581
noLocationException[0] = e;
582+
} else {
583+
throw e;
582584
}
583585
return null;
584586
}, IOException.class);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void cleanup() {
8585
}
8686
}
8787

88-
private void setupCluster(boolean overloadControl, boolean ha)
88+
protected void setupCluster(boolean overloadControl, boolean ha)
8989
throws Exception {
9090
// Build and start a federated cluster
9191
cluster = new StateStoreDFSCluster(ha, 2);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hdfs.server.federation.router.async;
19+
20+
import org.apache.hadoop.conf.Configuration;
21+
import org.apache.hadoop.hdfs.DFSClient;
22+
import org.apache.hadoop.hdfs.protocol.DirectoryListing;
23+
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
24+
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
25+
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
26+
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
27+
import org.junit.jupiter.api.Test;
28+
29+
import java.io.IOException;
30+
import java.net.URI;
31+
32+
import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.transitionClusterNSToActive;
33+
import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.transitionClusterNSToStandby;
34+
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
import static org.junit.jupiter.api.Assertions.assertThrows;
36+
37+
public class TestRouterAsyncClientRejectOverload {
38+
39+
private StateStoreDFSCluster cluster;
40+
41+
private void setupCluster(boolean ha)
42+
throws Exception {
43+
// Build and start a federated cluster.
44+
cluster = new StateStoreDFSCluster(ha, 2);
45+
Configuration routerConf = new RouterConfigBuilder()
46+
.stateStore()
47+
.metrics()
48+
.admin()
49+
.rpc()
50+
.heartbeat()
51+
.build();
52+
53+
routerConf.setBoolean(RBFConfigKeys.DFS_ROUTER_ASYNC_RPC_ENABLE_KEY, true);
54+
55+
cluster.addRouterOverrides(routerConf);
56+
cluster.startCluster();
57+
cluster.startRouters();
58+
cluster.waitClusterUp();
59+
}
60+
61+
@Test
62+
public void testGetFileInfoWhenNsFailover() throws Exception {
63+
setupCluster(true);
64+
Configuration conf = cluster.getRouterClientConf();
65+
conf.setInt("dfs.client.retry.max.attempts", 2);
66+
DFSClient routerClient = new DFSClient(new URI("hdfs://fed"), conf);
67+
transitionClusterNSToActive(cluster, 0);
68+
69+
String basePath = "/ARR/testGetFileInfo";
70+
routerClient.mkdirs(basePath);
71+
DirectoryListing directoryListing = routerClient.listPaths("/ARR", new byte[0]);
72+
assertEquals(1, directoryListing.getPartialListing().length);
73+
74+
transitionClusterNSToStandby(cluster);
75+
76+
assertThrows(IOException.class, () -> {
77+
HdfsFileStatus fileInfo = routerClient.getFileInfo(basePath + 1);
78+
});
79+
}
80+
}
81+

0 commit comments

Comments
 (0)