Skip to content

Commit 1416c94

Browse files
HDFS-17750. [ARR] RouterWebHdfsMethods adapts to async rpc. (#7462). Contributed by hfutatzhanghb.
Reviewed-by: Jian Zhang <keepromise@apache.org>
1 parent 8337251 commit 1416c94

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.router;
1919

20+
import static org.apache.hadoop.hdfs.server.federation.router.async.utils.AsyncUtil.syncReturn;
2021
import static org.apache.hadoop.util.StringUtils.getTrimmedStringCollection;
2122

2223
import org.apache.hadoop.fs.InvalidPathException;
@@ -28,6 +29,7 @@
2829
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
2930
import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
3031
import org.apache.hadoop.hdfs.server.common.JspHelper;
32+
import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
3133
import org.apache.hadoop.hdfs.server.federation.router.security.RouterSecurityManager;
3234
import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
3335

@@ -478,8 +480,14 @@ private DatanodeInfo chooseDatanode(final Router router,
478480

479481
if (op == PutOpParam.Op.CREATE) {
480482
try {
481-
resolvedNs = rpcServer.getCreateLocation(path).getNameserviceId();
482-
} catch (IOException e) {
483+
if (rpcServer.isAsync()) {
484+
rpcServer.getCreateLocation(path);
485+
RemoteLocation remoteLocation = syncReturn(RemoteLocation.class);
486+
resolvedNs = remoteLocation.getNameserviceId();
487+
} else {
488+
resolvedNs = rpcServer.getCreateLocation(path).getNameserviceId();
489+
}
490+
} catch (Exception e) {
483491
LOG.error("Cannot get the name service " +
484492
"to create file for path {} ", path, e);
485493
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@
4747
/**
4848
* Test suite for Router Web Hdfs methods.
4949
*/
50+
@SuppressWarnings("checkstyle:visibilitymodifier")
5051
public class TestRouterWebHdfsMethods {
5152
static final Logger LOG =
5253
LoggerFactory.getLogger(TestRouterWebHdfsMethods.class);
5354

54-
private static StateStoreDFSCluster cluster;
55-
private static RouterContext router;
56-
private static String httpUri;
55+
protected static StateStoreDFSCluster cluster;
56+
protected static RouterContext router;
57+
protected static String httpUri;
5758

5859
@BeforeClass
5960
public static void globalSetUp() throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.server.federation.RouterConfigBuilder;
22+
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
23+
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
24+
import org.apache.hadoop.hdfs.server.federation.router.TestRouterWebHdfsMethods;
25+
import org.junit.BeforeClass;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
/**
30+
* Test suite for Router Web Hdfs methods using async router rpc.
31+
*/
32+
public class TestRouterAsyncWebHdfsMethods extends TestRouterWebHdfsMethods {
33+
public static final Logger LOG =
34+
LoggerFactory.getLogger(TestRouterAsyncWebHdfsMethods.class);
35+
36+
@BeforeClass
37+
public static void globalSetUp() throws Exception {
38+
cluster = new StateStoreDFSCluster(false, 2);
39+
Configuration conf = new RouterConfigBuilder()
40+
.stateStore()
41+
.rpc()
42+
.http()
43+
.admin()
44+
.build();
45+
conf.setBoolean(RBFConfigKeys.DFS_ROUTER_ASYNC_RPC_ENABLE_KEY, true);
46+
cluster.addRouterOverrides(conf);
47+
cluster.setIndependentDNs();
48+
cluster.startCluster();
49+
cluster.startRouters();
50+
cluster.waitClusterUp();
51+
router = cluster.getRandomRouter();
52+
httpUri = "http://"+router.getHttpAddress();
53+
}
54+
}

0 commit comments

Comments
 (0)