YARN-9394. Use new API of RackResolver to get better performance. Contributed by Lantao Jin.

This commit is contained in:
Weiwei Yang 2019-04-04 18:05:01 +08:00
parent a92806d05a
commit 945e8c6064
2 changed files with 6 additions and 5 deletions

View File

@ -40,6 +40,7 @@ import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.net.Node;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
@ -763,10 +764,11 @@ public class AMRMClientImpl<T extends ContainerRequest> extends AMRMClient<T> {
private Set<String> resolveRacks(List<String> nodes) {
Set<String> racks = new HashSet<String>();
if (nodes != null) {
for (String node : nodes) {
List<Node> tmpList = RackResolver.resolve(nodes);
for (Node node : tmpList) {
String rack = node.getNetworkLocation();
// Ensure node requests are accompanied by requests for
// corresponding rack
String rack = RackResolver.resolve(node).getNetworkLocation();
if (rack == null) {
LOG.warn("Failed to resolve rack for node " + node + ".");
} else {
@ -774,7 +776,6 @@ public class AMRMClientImpl<T extends ContainerRequest> extends AMRMClient<T> {
}
}
}
return racks;
}

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.yarn.client.api.impl;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
@ -254,7 +254,7 @@ public class TestAMRMClientContainerRequest {
@Override
public List<String> resolve(List<String> names) {
return Arrays.asList("/rack1");
return Collections.nCopies(names.size(), "/rack1");
}
@Override