Skip to content

Commit 9b38be4

Browse files
committed
HDFS-13183. Addendum: Standby NameNode process getBlocks request to reduce Active load. Contributed by Xiaoqiao He.
1 parent 10db97d commit 9b38be4

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Balancer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,12 @@ static private int doBalance(Collection<URI> namenodes,
708708
System.out.println("Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved");
709709

710710
List<NameNodeConnector> connectors = Collections.emptyList();
711-
boolean done = false;
712-
for(int iteration = 0; !done; iteration++) {
713-
try {
714-
connectors = NameNodeConnector.newNameNodeConnectors(namenodes, nsIds,
715-
Balancer.class.getSimpleName(), BALANCER_ID_PATH, conf,
716-
p.getMaxIdleIteration());
711+
try {
712+
connectors = NameNodeConnector.newNameNodeConnectors(namenodes, nsIds,
713+
Balancer.class.getSimpleName(), BALANCER_ID_PATH, conf,
714+
p.getMaxIdleIteration());
715+
boolean done = false;
716+
for(int iteration = 0; !done; iteration++) {
717717
done = true;
718718
Collections.shuffle(connectors);
719719
for(NameNodeConnector nnc : connectors) {
@@ -741,10 +741,10 @@ static private int doBalance(Collection<URI> namenodes,
741741
if (!done) {
742742
Thread.sleep(sleeptime);
743743
}
744-
} finally {
745-
for(NameNodeConnector nnc : connectors) {
746-
IOUtils.cleanupWithLogger(LOG, nnc);
747-
}
744+
}
745+
} finally {
746+
for(NameNodeConnector nnc : connectors) {
747+
IOUtils.cleanupWithLogger(LOG, nnc);
748748
}
749749
}
750750
return ExitStatus.SUCCESS.getExitCode();

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/NameNodeConnector.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ public static void checkOtherInstanceRunning(boolean toCheck) {
147147

148148
private final BalancerProtocols namenode;
149149
/**
150-
* If set balancerShouldRequestStandby true, Balancer will getBlocks from
150+
* If set requestToStandby true, Balancer will getBlocks from
151151
* Standby NameNode only and it can reduce the performance impact of Active
152152
* NameNode, especially in a busy HA mode cluster.
153153
*/
154-
private boolean balancerShouldRequestStandby;
155-
private NamenodeProtocol standbyNameNode;
154+
private boolean requestToStandby;
155+
private String nsId;
156+
private Configuration config;
156157
private final KeyManager keyManager;
157158
final AtomicBoolean fallbackToSimpleAuth = new AtomicBoolean(false);
158159

@@ -188,10 +189,10 @@ public NameNodeConnector(String name, URI nameNodeUri, Path idPath,
188189

189190
this.namenode = NameNodeProxies.createProxy(conf, nameNodeUri,
190191
BalancerProtocols.class, fallbackToSimpleAuth).getProxy();
191-
this.balancerShouldRequestStandby = conf.getBoolean(
192+
this.requestToStandby = conf.getBoolean(
192193
DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_KEY,
193194
DFSConfigKeys.DFS_HA_ALLOW_STALE_READ_DEFAULT);
194-
this.standbyNameNode = null;
195+
this.config = conf;
195196

196197
this.fs = (DistributedFileSystem)FileSystem.get(nameNodeUri, conf);
197198

@@ -216,24 +217,7 @@ public NameNodeConnector(String name, URI nameNodeUri, String nsId,
216217
Configuration conf, int maxNotChangedIterations)
217218
throws IOException {
218219
this(name, nameNodeUri, idPath, targetPaths, conf, maxNotChangedIterations);
219-
if (nsId != null && HAUtil.isHAEnabled(conf, nsId)) {
220-
List<ClientProtocol> namenodes =
221-
HAUtil.getProxiesForAllNameNodesInNameservice(conf, nsId);
222-
for (ClientProtocol proxy : namenodes) {
223-
try {
224-
if (proxy.getHAServiceState().equals(
225-
HAServiceProtocol.HAServiceState.STANDBY)) {
226-
this.standbyNameNode = NameNodeProxies.createNonHAProxy(
227-
conf, RPC.getServerAddress(proxy), NamenodeProtocol.class,
228-
UserGroupInformation.getCurrentUser(), false).getProxy();
229-
break;
230-
}
231-
} catch (Exception e) {
232-
//Ignore the exception while connecting to a namenode.
233-
LOG.debug("Error while connecting to namenode", e);
234-
}
235-
}
236-
}
220+
this.nsId = nsId;
237221
}
238222

239223
public DistributedFileSystem getDistributedFileSystem() {
@@ -255,23 +239,43 @@ public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
255239
if (getBlocksRateLimiter != null) {
256240
getBlocksRateLimiter.acquire();
257241
}
258-
boolean isRequestStandby = true;
242+
boolean isRequestStandby = false;
243+
NamenodeProtocol nnproxy = null;
259244
try {
260-
if (balancerShouldRequestStandby && standbyNameNode != null) {
261-
return standbyNameNode.getBlocks(datanode, size, minBlockSize);
245+
if (requestToStandby && nsId != null
246+
&& HAUtil.isHAEnabled(config, nsId)) {
247+
List<ClientProtocol> namenodes =
248+
HAUtil.getProxiesForAllNameNodesInNameservice(config, nsId);
249+
for (ClientProtocol proxy : namenodes) {
250+
try {
251+
if (proxy.getHAServiceState().equals(
252+
HAServiceProtocol.HAServiceState.STANDBY)) {
253+
NamenodeProtocol sbn = NameNodeProxies.createNonHAProxy(
254+
config, RPC.getServerAddress(proxy), NamenodeProtocol.class,
255+
UserGroupInformation.getCurrentUser(), false).getProxy();
256+
nnproxy = sbn;
257+
isRequestStandby = true;
258+
break;
259+
}
260+
} catch (Exception e) {
261+
// Ignore the exception while connecting to a namenode.
262+
LOG.debug("Error while connecting to namenode", e);
263+
}
264+
}
265+
if (nnproxy == null) {
266+
LOG.warn("Request #getBlocks to Standby NameNode but meet exception,"
267+
+ " will fallback to normal way.");
268+
nnproxy = namenode;
269+
}
262270
} else {
263-
isRequestStandby = false;
271+
nnproxy = namenode;
264272
}
265-
} catch (Exception e) {
266-
LOG.warn("Request #getBlocks to Standby NameNode but meet exception, " +
267-
"will fallback to normal way", e);
268-
isRequestStandby = false;
273+
return nnproxy.getBlocks(datanode, size, minBlockSize);
269274
} finally {
270275
if (isRequestStandby) {
271276
LOG.info("Request #getBlocks to Standby NameNode success.");
272277
}
273278
}
274-
return namenode.getBlocks(datanode, size, minBlockSize);
275279
}
276280

277281
/**

0 commit comments

Comments
 (0)