HDFS-16588. Backport HDFS-16584 to branch-3.3. (#4342). Contributed by JiangHua Zhu.
Signed-off-by: litao <tomleescut@gmail.com> Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
parent
1f111d6a41
commit
fe6b050857
@ -21,6 +21,7 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -255,6 +256,7 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
|
|||||||
}
|
}
|
||||||
boolean isRequestStandby = false;
|
boolean isRequestStandby = false;
|
||||||
NamenodeProtocol nnproxy = null;
|
NamenodeProtocol nnproxy = null;
|
||||||
|
InetSocketAddress standbyAddress = null;
|
||||||
try {
|
try {
|
||||||
if (requestToStandby && nsId != null
|
if (requestToStandby && nsId != null
|
||||||
&& HAUtil.isHAEnabled(config, nsId)) {
|
&& HAUtil.isHAEnabled(config, nsId)) {
|
||||||
@ -264,8 +266,9 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
|
|||||||
try {
|
try {
|
||||||
if (proxy.getHAServiceState().equals(
|
if (proxy.getHAServiceState().equals(
|
||||||
HAServiceProtocol.HAServiceState.STANDBY)) {
|
HAServiceProtocol.HAServiceState.STANDBY)) {
|
||||||
|
standbyAddress = RPC.getServerAddress(proxy);
|
||||||
NamenodeProtocol sbn = NameNodeProxies.createNonHAProxy(
|
NamenodeProtocol sbn = NameNodeProxies.createNonHAProxy(
|
||||||
config, RPC.getServerAddress(proxy), NamenodeProtocol.class,
|
config, standbyAddress, NamenodeProtocol.class,
|
||||||
UserGroupInformation.getCurrentUser(), false).getProxy();
|
UserGroupInformation.getCurrentUser(), false).getProxy();
|
||||||
nnproxy = sbn;
|
nnproxy = sbn;
|
||||||
isRequestStandby = true;
|
isRequestStandby = true;
|
||||||
@ -287,7 +290,8 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
|
|||||||
return nnproxy.getBlocks(datanode, size, minBlockSize);
|
return nnproxy.getBlocks(datanode, size, minBlockSize);
|
||||||
} finally {
|
} finally {
|
||||||
if (isRequestStandby) {
|
if (isRequestStandby) {
|
||||||
LOG.info("Request #getBlocks to Standby NameNode success.");
|
LOG.info("Request #getBlocks to Standby NameNode success. " +
|
||||||
|
"remoteAddress: {}", standbyAddress.getHostString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,13 +199,16 @@ public void testBalancerRequestSBNWithHA() throws Exception {
|
|||||||
try {
|
try {
|
||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
cluster.transitionToActive(0);
|
cluster.transitionToActive(0);
|
||||||
|
String standbyNameNode = cluster.getNameNode(1).
|
||||||
|
getNameNodeAddress().getHostString();
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
client = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf),
|
client = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf),
|
||||||
ClientProtocol.class).getProxy();
|
ClientProtocol.class).getProxy();
|
||||||
doTest(conf);
|
doTest(conf);
|
||||||
// Check getBlocks request to Standby NameNode.
|
// Check getBlocks request to Standby NameNode.
|
||||||
assertTrue(log.getOutput().contains(
|
assertTrue(log.getOutput().contains(
|
||||||
"Request #getBlocks to Standby NameNode success."));
|
"Request #getBlocks to Standby NameNode success. remoteAddress: " +
|
||||||
|
standbyNameNode));
|
||||||
} finally {
|
} finally {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user