Skip to content

Commit

Permalink
HDFS-16584.Record StandbyNameNode information when Balancer is runnin…
Browse files Browse the repository at this point in the history
…g. (#4333). Contributed by JiangHua Zhu.

Signed-off-by: litao <tomleescut@gmail.com>
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
  • Loading branch information
jianghuazhu authored May 22, 2022
1 parent 93a1320 commit 4fd4208
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -260,21 +261,24 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
}
boolean isRequestStandby = false;
NamenodeProtocol nnProxy = null;
InetSocketAddress standbyAddress = null;
try {
ProxyPair proxyPair = getProxy();
isRequestStandby = proxyPair.isRequestStandby;
ClientProtocol proxy = proxyPair.clientProtocol;
if (isRequestStandby) {
standbyAddress = RPC.getServerAddress(proxy);
nnProxy = NameNodeProxies.createNonHAProxy(
config, RPC.getServerAddress(proxy), NamenodeProtocol.class,
config, standbyAddress, NamenodeProtocol.class,
UserGroupInformation.getCurrentUser(), false).getProxy();
} else {
nnProxy = namenode;
}
return nnProxy.getBlocks(datanode, size, minBlockSize, timeInterval);
} finally {
if (isRequestStandby) {
LOG.info("Request #getBlocks to Standby NameNode success.");
LOG.info("Request #getBlocks to Standby NameNode success. " +
"remoteAddress: {}", standbyAddress.getHostString());
}
}
}
Expand All @@ -297,15 +301,19 @@ public boolean isUpgrading() throws IOException {
public DatanodeStorageReport[] getLiveDatanodeStorageReport()
throws IOException {
boolean isRequestStandby = false;
InetSocketAddress standbyAddress = null;
try {
ProxyPair proxyPair = getProxy();
isRequestStandby = proxyPair.isRequestStandby;
ClientProtocol proxy = proxyPair.clientProtocol;
if (isRequestStandby) {
standbyAddress = RPC.getServerAddress(proxy);
}
return proxy.getDatanodeStorageReport(DatanodeReportType.LIVE);
} finally {
if (isRequestStandby) {
LOG.info("Request #getLiveDatanodeStorageReport to Standby " +
"NameNode success.");
"NameNode success. remoteAddress: {}", standbyAddress.getHostString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,19 @@ public void testBalancerRequestSBNWithHA() throws Exception {
try {
cluster.waitActive();
cluster.transitionToActive(0);
String standbyNameNode = cluster.getNameNode(1).
getNameNodeAddress().getHostString();
Thread.sleep(500);
client = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf),
ClientProtocol.class).getProxy();
doTest(conf);
// Check getBlocks request to Standby NameNode.
assertTrue(log.getOutput().contains(
"Request #getBlocks to Standby NameNode success."));
"Request #getBlocks to Standby NameNode success. remoteAddress: " +
standbyNameNode));
assertTrue(log.getOutput().contains(
"Request #getLiveDatanodeStorageReport to Standby NameNode success"));
"Request #getLiveDatanodeStorageReport to Standby NameNode success. " +
"remoteAddress: " + standbyNameNode));
} finally {
cluster.shutdown();
}
Expand Down

0 comments on commit 4fd4208

Please sign in to comment.