Skip to content

Commit 261191c

Browse files
authored
HDFS-15904 : De-flake TestBalancer#testBalancerWithSortTopNodes() (#2785)
Contributed by Viraj Jasani. Signed-off-by: Mingliang Liu <[email protected]> Signed-off-by: Ayush Saxena <[email protected]>
1 parent cd44e91 commit 261191c

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,10 @@ void resetData(Configuration conf) {
634634
}
635635

636636
static class Result {
637-
final ExitStatus exitStatus;
638-
final long bytesLeftToMove;
639-
final long bytesBeingMoved;
640-
final long bytesAlreadyMoved;
637+
private final ExitStatus exitStatus;
638+
private final long bytesLeftToMove;
639+
private final long bytesBeingMoved;
640+
private final long bytesAlreadyMoved;
641641

642642
Result(ExitStatus exitStatus, long bytesLeftToMove, long bytesBeingMoved,
643643
long bytesAlreadyMoved) {
@@ -647,6 +647,22 @@ static class Result {
647647
this.bytesAlreadyMoved = bytesAlreadyMoved;
648648
}
649649

650+
public ExitStatus getExitStatus() {
651+
return exitStatus;
652+
}
653+
654+
public long getBytesLeftToMove() {
655+
return bytesLeftToMove;
656+
}
657+
658+
public long getBytesBeingMoved() {
659+
return bytesBeingMoved;
660+
}
661+
662+
public long getBytesAlreadyMoved() {
663+
return bytesAlreadyMoved;
664+
}
665+
650666
void print(int iteration, NameNodeConnector nnc, PrintStream out) {
651667
out.printf("%-24s %10d %19s %18s %17s %s%n",
652668
DateFormat.getDateTimeInstance().format(new Date()), iteration,

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,12 +1158,7 @@ public void executePendingMove(final PendingMove p) {
11581158
p.proxySource.removePendingBlock(p);
11591159
return;
11601160
}
1161-
moveExecutor.execute(new Runnable() {
1162-
@Override
1163-
public void run() {
1164-
p.dispatch();
1165-
}
1166-
});
1161+
moveExecutor.execute(p::dispatch);
11671162
}
11681163

11691164
public boolean dispatchAndCheckContinue() throws InterruptedException {

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,14 +1024,14 @@ private static int runBalancer(Collection<URI> namenodes,
10241024

10251025
// clean all lists
10261026
b.resetData(conf);
1027-
if (r.exitStatus == ExitStatus.IN_PROGRESS) {
1027+
if (r.getExitStatus() == ExitStatus.IN_PROGRESS) {
10281028
done = false;
1029-
} else if (r.exitStatus != ExitStatus.SUCCESS) {
1029+
} else if (r.getExitStatus() != ExitStatus.SUCCESS) {
10301030
//must be an error statue, return.
1031-
return r.exitStatus.getExitCode();
1031+
return r.getExitStatus().getExitCode();
10321032
} else {
10331033
if (iteration > 0) {
1034-
assertTrue(r.bytesAlreadyMoved > 0);
1034+
assertTrue(r.getBytesAlreadyMoved() > 0);
10351035
}
10361036
}
10371037
}
@@ -1657,7 +1657,7 @@ public void testMaxIterationTime() throws Exception {
16571657
// When a block move is not canceled in 2 seconds properly and then
16581658
// a block is moved unexpectedly, IN_PROGRESS will be reported.
16591659
assertEquals("We expect ExitStatus.NO_MOVE_PROGRESS to be reported.",
1660-
ExitStatus.NO_MOVE_PROGRESS, r.exitStatus);
1660+
ExitStatus.NO_MOVE_PROGRESS, r.getExitStatus());
16611661
}
16621662
} finally {
16631663
for (NameNodeConnector nnc : connectors) {
@@ -2297,7 +2297,20 @@ public void testBalancerWithSortTopNodes() throws Exception {
22972297
maxUsage = Math.max(maxUsage, datanodeReport[i].getDfsUsed());
22982298
}
22992299

2300-
assertEquals(200, balancerResult.bytesAlreadyMoved);
2300+
// The 95% usage DN will have 9 blocks of 100B and 1 block of 50B - all for the same file.
2301+
// The HDFS balancer will choose a block to move from this node randomly. More likely it will
2302+
// be 100B block. Since 100B is greater than DFS_BALANCER_MAX_SIZE_TO_MOVE_KEY which is 99L,
2303+
// it will stop here. Total bytes moved from this 95% DN will be 1 block of size 100B.
2304+
// However, chances are the first block selected to be moved from this 95% DN is the 50B block.
2305+
// After this block is moved, the total moved size so far would be 50B which is smaller than
2306+
// DFS_BALANCER_MAX_SIZE_TO_MOVE_KEY (99L), hence it will try to move another block.
2307+
// The second block will always be of size 100B. So total bytes moved from this 95% DN will be
2308+
// 2 blocks of size (100B + 50B) 150B.
2309+
// Hence, overall total blocks moved by HDFS balancer would be either of these 2 options:
2310+
// a) 2 blocks of total size (100B + 100B)
2311+
// b) 3 blocks of total size (50B + 100B + 100B)
2312+
assertTrue(balancerResult.getBytesAlreadyMoved() == 200
2313+
|| balancerResult.getBytesAlreadyMoved() == 250);
23012314
// 100% and 95% used nodes will be balanced, so top used will be 900
23022315
assertEquals(900, maxUsage);
23032316
}

0 commit comments

Comments
 (0)