List<LocatedBlockWithMetaInfo> srcBlockList = new LinkedList<LocatedBlockWithMetaInfo>();
List<BlockInfo> srcInfoList = new LinkedList<BlockInfo>();
for (int i = 0; i < sourceLocations.length; i+=2) {
DatanodeInfo d = sourceLocations[i];
DatanodeInfo d1 = sourceLocations[i+1];
LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
new Block(blockId, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
0, 0, 0);
BlockInfo info = createBlockInfo(srcStat, lb);
srcBlockList.add(lb);
srcInfoList.add(info);
resolver.addBlock(info, lb);
resolver.addNode(d.getName(), d);
resolver.addNode(d1.getName(), d1);
List<DatanodeInfo> dnList = new ArrayList<DatanodeInfo>();
dnList.add(d);
dnList.add(d1);
blockLocations.put(String.valueOf(blockId), dnList);
++ blockId;
}
List<LocatedBlock> parityBlockList = new LinkedList<LocatedBlock>();
List<BlockInfo> parityInfoList = new LinkedList<BlockInfo>();
for (int i = 0; i < parityLocations.length; i+=2) {
DatanodeInfo d = parityLocations[i];
DatanodeInfo d1 = parityLocations[i+1];
LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
new Block(blockId, 0, 0L), new DatanodeInfo[]{d, d1}, 0L,
0, 0, 0);
parityBlockList.add(lb);
BlockInfo info = createBlockInfo(parityStat, lb);
parityInfoList.add(info);
resolver.addBlock(info, lb);
resolver.addNode(d.getName(), d);
resolver.addNode(d1.getName(), d1);
List<DatanodeInfo> dnList = new ArrayList<DatanodeInfo>();
dnList.add(d);
dnList.add(d1);
blockLocations.put(String.valueOf(blockId), dnList);
++ blockId;
}
fakeBlockMover.setBlockLocations(blockLocations);
placementMonitor.checkBlockLocations(
srcInfoList, parityInfoList, Codec.getCodec("xor"), xorPolicy,
srcStat, resolver);
for (BlockMover.BlockMoveAction action :
fakeBlockMover.getSubmittedActions()) {
LOG.info("Block move:" + action);
}
Set<Block> movedBlocks = new HashSet<Block>();
for (BlockMover.BlockMoveAction action :
fakeBlockMover.getSubmittedActions()) {
movedBlocks.add(action.block.getBlock());
}
Map<Integer, Long> hist =
placementMonitor.blockHistograms.get("xor");
Assert.assertEquals(3, hist.size());
Assert.assertEquals(3, hist.get(0).longValue());
Assert.assertEquals(2, hist.get(1).longValue());
Assert.assertEquals(3, hist.get(2).longValue());
// since each node is on different rack, the rack histogram should
// be the same the one for nodes.
Map<Integer, Long> histRack =
placementMonitor.blockHistogramsPerRack.get("xor");
Assert.assertEquals(3, histRack.size());
Assert.assertEquals(3, histRack.get(0).longValue());
Assert.assertEquals(2, histRack.get(1).longValue());
Assert.assertEquals(3, histRack.get(2).longValue());
// Note that the first block will stay.
Assert.assertEquals(8, fakeBlockMover.getSubmittedActions().size());
Assert.assertEquals(6, movedBlocks.size());
Assert.assertTrue(movedBlocks.contains(new Block(1L, 0, 0L)));
Assert.assertTrue(movedBlocks.contains(new Block(2L, 0, 0L)));
Assert.assertTrue(movedBlocks.contains(new Block(4L, 0, 0L)));
Assert.assertTrue(movedBlocks.contains(new Block(5L, 0, 0L)));
Assert.assertTrue(movedBlocks.contains(new Block(6L, 0, 0L)));
Assert.assertTrue(movedBlocks.contains(new Block(7L, 0, 0L)));
fakeBlockMover.clearActions();
resolver = new FakeBlockAndDatanodeResolver();
// rebuild the block infos
srcInfoList = new LinkedList<BlockInfo>();
for (LocatedBlock srcBlock : srcBlockList) {
List<DatanodeInfo> replicaNodes = blockLocations.get(
String.valueOf(srcBlock.getBlock().getBlockId()));
LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
new Block(srcBlock.getBlock().getBlockId(), 0, 0L),
replicaNodes.toArray(new DatanodeInfo[]{}),
0L, 0, 0, 0);
BlockInfo info = createBlockInfo(srcStat, lb);
srcInfoList.add(info);
resolver.addBlock(info, lb);
for (DatanodeInfo d : replicaNodes) {
resolver.addNode(d.getName(), d);
}
}
parityInfoList = new LinkedList<BlockInfo>();
for (LocatedBlock parityBlock : parityBlockList) {
List<DatanodeInfo> replicaNodes = blockLocations.get(
String.valueOf(parityBlock.getBlock().getBlockId()));
LocatedBlockWithMetaInfo lb = new LocatedBlockWithMetaInfo(
new Block(parityBlock.getBlock().getBlockId(), 0, 0L),
replicaNodes.toArray(new DatanodeInfo[]{}),
0L, 0, 0, 0);
BlockInfo info = createBlockInfo(srcStat, lb);