HDFS-16584.Record StandbyNameNode information when Balancer is running. (#4333). Contributed by JiangHua Zhu.

Signed-off-by: litao <tomleescut@gmail.com>
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
jianghuazhu 2022-05-22 21:59:38 +08:00 committed by GitHub
parent 93a13202d7
commit 4fd4208439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -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;
@ -260,13 +261,15 @@ 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 {
ProxyPair proxyPair = getProxy(); ProxyPair proxyPair = getProxy();
isRequestStandby = proxyPair.isRequestStandby; isRequestStandby = proxyPair.isRequestStandby;
ClientProtocol proxy = proxyPair.clientProtocol; ClientProtocol proxy = proxyPair.clientProtocol;
if (isRequestStandby) { if (isRequestStandby) {
standbyAddress = RPC.getServerAddress(proxy);
nnProxy = NameNodeProxies.createNonHAProxy( nnProxy = NameNodeProxies.createNonHAProxy(
config, RPC.getServerAddress(proxy), NamenodeProtocol.class, config, standbyAddress, NamenodeProtocol.class,
UserGroupInformation.getCurrentUser(), false).getProxy(); UserGroupInformation.getCurrentUser(), false).getProxy();
} else { } else {
nnProxy = namenode; nnProxy = namenode;
@ -274,7 +277,8 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
return nnProxy.getBlocks(datanode, size, minBlockSize, timeInterval); return nnProxy.getBlocks(datanode, size, minBlockSize, timeInterval);
} 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());
} }
} }
} }
@ -297,15 +301,19 @@ public boolean isUpgrading() throws IOException {
public DatanodeStorageReport[] getLiveDatanodeStorageReport() public DatanodeStorageReport[] getLiveDatanodeStorageReport()
throws IOException { throws IOException {
boolean isRequestStandby = false; boolean isRequestStandby = false;
InetSocketAddress standbyAddress = null;
try { try {
ProxyPair proxyPair = getProxy(); ProxyPair proxyPair = getProxy();
isRequestStandby = proxyPair.isRequestStandby; isRequestStandby = proxyPair.isRequestStandby;
ClientProtocol proxy = proxyPair.clientProtocol; ClientProtocol proxy = proxyPair.clientProtocol;
if (isRequestStandby) {
standbyAddress = RPC.getServerAddress(proxy);
}
return proxy.getDatanodeStorageReport(DatanodeReportType.LIVE); return proxy.getDatanodeStorageReport(DatanodeReportType.LIVE);
} finally { } finally {
if (isRequestStandby) { if (isRequestStandby) {
LOG.info("Request #getLiveDatanodeStorageReport to Standby " + LOG.info("Request #getLiveDatanodeStorageReport to Standby " +
"NameNode success."); "NameNode success. remoteAddress: {}", standbyAddress.getHostString());
} }
} }
} }

View File

@ -202,15 +202,19 @@ 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));
assertTrue(log.getOutput().contains( assertTrue(log.getOutput().contains(
"Request #getLiveDatanodeStorageReport to Standby NameNode success")); "Request #getLiveDatanodeStorageReport to Standby NameNode success. " +
"remoteAddress: " + standbyNameNode));
} finally { } finally {
cluster.shutdown(); cluster.shutdown();
} }