Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
Mar 10, 2014 11:03:40 AM 0 0 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:41 AM 1 0 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:42 AM 2 443 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:43 AM 3 443 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:44 AM 4 891.85 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:45 AM 5 891.85 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:46 AM 6 891.85 KB 614.5 GB 20 GB
Mar 10, 2014 11:03:47 AM 7 891.85 KB 614.49 GB 20 GB
Mar 10, 2014 11:03:48 AM 8 891.85 KB 614.49 GB 20 GB
No block has been moved for 5 iterations. Exiting...
Balancing took 10.023 seconds
很明显,balancer已经计算出要移动的数据量,但是就是没有移动,这是为什么呢?
查看hadoop-mysql-balancer-master.log并没有发现Error或者Warning,那只能去看源码了。
原来hadoop balancer在进行转移block的时候是会判断的,具体要求见下面的代码:
/* Decide if it is OK to move the given block from source to target
* A block is a good candidate if
* 1. the block is not in the process of being moved/has not been moved;
* 2. the block does not have a replica on the target;
* 3. doing the move does not reduce the number of racks that the block has
*/
private boolean isGoodBlockCandidate(Source source,
BalancerDatanode target, BalancerBlock block) {
// check if the block is moved or not
if (movedBlocks.contains(block)) {
return false;
}
if (block.isLocatedOnDatanode(target)) {
return false;
}
boolean goodBlock = false;
if (cluster.isOnSameRack(source.getDatanode(), target.getDatanode())) {
// good if source and target are on the same rack
goodBlock = true;
} else {
boolean notOnSameRack = true;
synchronized (block) {
for (BalancerDatanode loc : block.locations) {
if (cluster.isOnSameRack(loc.datanode, target.datanode)) {
notOnSameRack = false;
break;
}
}
}
if (notOnSameRack) {
// good if target is target is not on the same rack as any replica
goodBlock = true;
} else {
// good if source is on the same rack as on of the replicas
for (BalancerDatanode loc : block.locations) {
if (loc != source &&
cluster.isOnSameRack(loc.datanode, source.datanode)) {
goodBlock = true;
break;
}
}
}
}
return goodBlock;
}