Skip to content

Commit e48dd9d

Browse files
committed
HDFS-15665. Balancer logging improvements. Contributed by Konstantin V Shvachko.
(cherry picked from commit d07dc7a)
1 parent dd1634e commit e48dd9d

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ static int getFailedTimesSinceLastSuccessfulBalance() {
282282
*/
283283
Balancer(NameNodeConnector theblockpool, BalancerParameters p,
284284
Configuration conf) {
285+
// NameNode configuration parameters for balancing
286+
getInt(conf, DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_MAX_QPS_KEY,
287+
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_MAX_QPS_DEFAULT);
285288
final long movedWinWidth = getLong(conf,
286289
DFSConfigKeys.DFS_BALANCER_MOVEDWINWIDTH_KEY,
287290
DFSConfigKeys.DFS_BALANCER_MOVEDWINWIDTH_DEFAULT);
@@ -291,10 +294,6 @@ static int getFailedTimesSinceLastSuccessfulBalance() {
291294
final int dispatcherThreads = getInt(conf,
292295
DFSConfigKeys.DFS_BALANCER_DISPATCHERTHREADS_KEY,
293296
DFSConfigKeys.DFS_BALANCER_DISPATCHERTHREADS_DEFAULT);
294-
final int maxConcurrentMovesPerNode = getInt(conf,
295-
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_KEY,
296-
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_DEFAULT);
297-
298297
final long getBlocksSize = getLongBytes(conf,
299298
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_SIZE_KEY,
300299
DFSConfigKeys.DFS_BALANCER_GETBLOCKS_SIZE_DEFAULT);
@@ -311,6 +310,13 @@ static int getFailedTimesSinceLastSuccessfulBalance() {
311310
DFSConfigKeys.DFS_BALANCER_MAX_ITERATION_TIME_KEY,
312311
DFSConfigKeys.DFS_BALANCER_MAX_ITERATION_TIME_DEFAULT);
313312

313+
// DataNode configuration parameters for balancing
314+
final int maxConcurrentMovesPerNode = getInt(conf,
315+
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_KEY,
316+
DFSConfigKeys.DFS_DATANODE_BALANCE_MAX_NUM_CONCURRENT_MOVES_DEFAULT);
317+
getLongBytes(conf, DFSConfigKeys.DFS_DATANODE_BALANCE_BANDWIDTHPERSEC_KEY,
318+
DFSConfigKeys.DFS_DATANODE_BALANCE_BANDWIDTHPERSEC_DEFAULT);
319+
314320
this.nnc = theblockpool;
315321
this.dispatcher =
316322
new Dispatcher(theblockpool, p.getIncludedNodes(),
@@ -603,12 +609,13 @@ static class Result {
603609
this.bytesAlreadyMoved = bytesAlreadyMoved;
604610
}
605611

606-
void print(int iteration, PrintStream out) {
607-
out.printf("%-24s %10d %19s %18s %17s%n",
612+
void print(int iteration, NameNodeConnector nnc, PrintStream out) {
613+
out.printf("%-24s %10d %19s %18s %17s %s%n",
608614
DateFormat.getDateTimeInstance().format(new Date()), iteration,
609615
StringUtils.byteDesc(bytesAlreadyMoved),
610616
StringUtils.byteDesc(bytesLeftToMove),
611-
StringUtils.byteDesc(bytesBeingMoved));
617+
StringUtils.byteDesc(bytesBeingMoved),
618+
nnc.getNameNodeUri());
612619
}
613620
}
614621

@@ -653,8 +660,10 @@ Result runOneIteration() {
653660
System.out.println("No block can be moved. Exiting...");
654661
return newResult(ExitStatus.NO_MOVE_BLOCK, bytesLeftToMove, bytesBeingMoved);
655662
} else {
656-
LOG.info( "Will move " + StringUtils.byteDesc(bytesBeingMoved) +
657-
" in this iteration");
663+
LOG.info("Will move {} in this iteration for {}",
664+
StringUtils.byteDesc(bytesBeingMoved), nnc.toString());
665+
LOG.info("Total target DataNodes in this iteration: {}",
666+
dispatcher.moveTasksTotal());
658667
}
659668

660669
/* For each pair of <source, target>, start a thread that repeatedly
@@ -705,7 +714,9 @@ static private int doBalance(Collection<URI> namenodes,
705714
LOG.info("excluded nodes = " + p.getExcludedNodes());
706715
LOG.info("source nodes = " + p.getSourceNodes());
707716
checkKeytabAndInit(conf);
708-
System.out.println("Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved");
717+
System.out.println("Time Stamp Iteration#"
718+
+ " Bytes Already Moved Bytes Left To Move Bytes Being Moved"
719+
+ " NameNode");
709720

710721
List<NameNodeConnector> connectors = Collections.emptyList();
711722
try {
@@ -721,7 +732,7 @@ static private int doBalance(Collection<URI> namenodes,
721732
|| p.getBlockPools().contains(nnc.getBlockpoolID())) {
722733
final Balancer b = new Balancer(nnc, p, conf);
723734
final Result r = b.runOneIteration();
724-
r.print(iteration, System.out);
735+
r.print(iteration, nnc, System.out);
725736

726737
// clean all lists
727738
b.resetData(conf);

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private void dispatch() {
392392

393393
sendRequest(out, eb, accessToken);
394394
receiveResponse(in);
395-
nnc.getBytesMoved().addAndGet(reportedBlock.getNumBytes());
395+
nnc.addBytesMoved(reportedBlock.getNumBytes());
396396
target.getDDatanode().setHasSuccess();
397397
LOG.info("Successfully moved " + this);
398398
} catch (IOException e) {
@@ -1064,6 +1064,10 @@ long getBytesMoved() {
10641064
return nnc.getBytesMoved().get();
10651065
}
10661066

1067+
long getBblocksMoved() {
1068+
return nnc.getBlocksMoved().get();
1069+
}
1070+
10671071
long bytesToMove() {
10681072
Preconditions.checkState(
10691073
storageGroupMap.size() >= sources.size() + targets.size(),
@@ -1083,6 +1087,14 @@ void add(Source source, StorageGroup target) {
10831087
targets.add(target);
10841088
}
10851089

1090+
public int moveTasksTotal() {
1091+
int b = 0;
1092+
for (Source src : sources) {
1093+
b += src.tasks.size();
1094+
}
1095+
return b;
1096+
}
1097+
10861098
private boolean shouldIgnore(DatanodeInfo dn) {
10871099
// ignore out-of-service nodes
10881100
final boolean outOfService = !dn.isInService();
@@ -1164,12 +1176,13 @@ public boolean dispatchAndCheckContinue() throws InterruptedException {
11641176
*/
11651177
private long dispatchBlockMoves() throws InterruptedException {
11661178
final long bytesLastMoved = getBytesMoved();
1179+
final long blocksLastMoved = getBblocksMoved();
11671180
final Future<?>[] futures = new Future<?>[sources.size()];
11681181

11691182
int concurrentThreads = Math.min(sources.size(),
11701183
((ThreadPoolExecutor)dispatchExecutor).getCorePoolSize());
11711184
assert concurrentThreads > 0 : "Number of concurrent threads is 0.";
1172-
LOG.debug("Balancer concurrent dispatcher threads = {}", concurrentThreads);
1185+
LOG.info("Balancer concurrent dispatcher threads = {}", concurrentThreads);
11731186

11741187
// Determine the size of each mover thread pool per target
11751188
int threadsPerTarget = maxMoverThreads/targets.size();
@@ -1211,6 +1224,9 @@ public void run() {
12111224

12121225
// wait for all reportedBlock moving to be done
12131226
waitForMoveCompletion(targets);
1227+
LOG.info("Total bytes (blocks) moved in this iteration {} ({})",
1228+
StringUtils.byteDesc(getBytesMoved() - bytesLastMoved),
1229+
(getBblocksMoved() - blocksLastMoved));
12141230

12151231
return getBytesMoved() - bytesLastMoved;
12161232
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public static void checkOtherInstanceRunning(boolean toCheck) {
162162
private OutputStream out;
163163
private final List<Path> targetPaths;
164164
private final AtomicLong bytesMoved = new AtomicLong();
165+
private final AtomicLong blocksMoved = new AtomicLong();
165166

166167
private final int maxNotChangedIterations;
167168
private int notChangedIterations = 0;
@@ -233,6 +234,19 @@ AtomicLong getBytesMoved() {
233234
return bytesMoved;
234235
}
235236

237+
AtomicLong getBlocksMoved() {
238+
return blocksMoved;
239+
}
240+
241+
public void addBytesMoved(long numBytes) {
242+
bytesMoved.addAndGet(numBytes);
243+
blocksMoved.incrementAndGet();
244+
}
245+
246+
public URI getNameNodeUri() {
247+
return nameNodeUri;
248+
}
249+
236250
/** @return blocks with locations. */
237251
public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size, long
238252
minBlockSize) throws IOException {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ private static int runBalancer(Collection<URI> namenodes,
10181018
for(NameNodeConnector nnc : connectors) {
10191019
final Balancer b = new Balancer(nnc, p, conf);
10201020
final Result r = b.runOneIteration();
1021-
r.print(iteration, System.out);
1021+
r.print(iteration, nnc, System.out);
10221022

10231023
// clean all lists
10241024
b.resetData(conf);

0 commit comments

Comments
 (0)