本文整理汇总了Java中org.apache.hadoop.hdfs.server.namenode.BlocksMap.BlockInfo.getDatanode方法的典型用法代码示例。如果您正苦于以下问题:Java BlockInfo.getDatanode方法的具体用法?Java BlockInfo.getDatanode怎么用?Java BlockInfo.getDatanode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hdfs.server.namenode.BlocksMap.BlockInfo
的用法示例。
在下文中一共展示了BlockInfo.getDatanode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlockInfoPlaceUpdate
import org.apache.hadoop.hdfs.server.namenode.BlocksMap.BlockInfo; //导入方法依赖的package包/类
@Test
public void testBlockInfoPlaceUpdate() throws IOException {
insertBlocks(100, true);
for (Block b : blockList) {
BlockInfo oldBlock = map.getBlockInfo(b);
// get current locations
DatanodeDescriptor loc0 = oldBlock.getDatanode(0);
DatanodeDescriptor loc1 = oldBlock.getDatanode(1);
assertNotNull(loc0);
assertNotNull(loc1);
assertEquals(2, oldBlock.numNodes());
// prepare new block with different size and GS
long newGS = b.getGenerationStamp() + 1;
b.setGenerationStamp(newGS);
b.setNumBytes(b.getNumBytes() + 10);
BlockInfo newBlock = new BlockInfo(b, iNode.getReplication());
LOG.info("Updating block: " + oldBlock + " to: " + newBlock);
// do update
newBlock = map.updateINode(oldBlock, newBlock, iNode,
iNode.getReplication(), false);
// preserved new generation stamp
assertEquals(map.getStoredBlockWithoutMatchingGS(newBlock)
.getGenerationStamp(), newGS);
// check locations
assertEquals(0, newBlock.numNodes());
// when id is mismatched, the block should not be updated
newBlock.setBlockId(newBlock.getBlockId() + 1);
try {
map.updateINode(oldBlock, newBlock, iNode, iNode.getReplication(), false);
fail("Should fail here");
} catch (IOException e) {
LOG.info("Can't update " + oldBlock + " to: " + newBlock + " "
+ e.getMessage());
}
}
}
示例2: directoryDataNodeUsage
import org.apache.hadoop.hdfs.server.namenode.BlocksMap.BlockInfo; //导入方法依赖的package包/类
/**
* Iterates through files in the directory dir, and counts the number
* of usages of datanodes for the files in the directory dir.
* Just iterates through threshold number of blocks.
*/
private HashMap<DatanodeDescriptor, Integer> directoryDataNodeUsage(INodeDirectory dir,
int threshold) {
HashMap<DatanodeDescriptor, Integer> dataNodeUsage = new HashMap<DatanodeDescriptor, Integer>();
List<INode> children;
nameSystem.readLock();
try {
if (dir.getChildrenRaw() == null) {
return dataNodeUsage;
}
children = new ArrayList<INode>(dir.getChildrenRaw());
Collections.shuffle(children);
for (INode node : children) {
if (!(node instanceof INodeFile)) { // The condition is always false.
continue;
}
INodeFile file = (INodeFile) node;
BlockInfo[] blocks = file.getBlocks();
for (BlockInfo block : blocks) {
if (threshold == 0) {
return dataNodeUsage;
}
int replication = block.numNodes();
for (int i = 0; i < replication; i++) {
DatanodeDescriptor datanode = block.getDatanode(i);
Integer currentUsage = dataNodeUsage.get(datanode);
dataNodeUsage.put(datanode, currentUsage == null ? 1 : currentUsage + 1);
}
threshold--;
}
}
} finally {
nameSystem.readUnlock();
}
return dataNodeUsage;
}