/** * Identify the block stored in the given datanode storage. Note that * the returned block has the same block Id with the one seen/reported by the * DataNode. */ Block getBlockOnStorage(DatanodeStorageInfo storage) { int index = getStorageBlockIndex(storage); if (index < 0) { return null; } else { Block block = new Block(this); block.setBlockId(this.getBlockId() + index); return block; } }
@Override boolean addStorage(DatanodeStorageInfo storage, Block reportedBlock) { Preconditions.checkArgument(BlockIdManager.isStripedBlockID( reportedBlock.getBlockId()), "reportedBlock is not striped"); Preconditions.checkArgument(BlockIdManager.convertToStripedID( reportedBlock.getBlockId()) == this.getBlockId(), "reported blk_%s does not belong to the group of stored blk_%s", reportedBlock.getBlockId(), this.getBlockId()); int blockIndex = BlockIdManager.getBlockIndex(reportedBlock); int index = blockIndex; DatanodeStorageInfo old = getStorageInfo(index); if (old != null && !old.equals(storage)) { // over replicated // check if the storage has been stored int i = findStorageInfo(storage); if (i == -1) { index = findSlot(); } else { return true; } } addStorage(storage, index, blockIndex); return true; }
private void createReplicationWork(int sourceIndex, DatanodeStorageInfo target) { BlockInfoStriped stripedBlk = (BlockInfoStriped) getBlock(); final byte blockIndex = liveBlockIndicies[sourceIndex]; final DatanodeDescriptor source = getSrcNodes()[sourceIndex]; final long internBlkLen = StripedBlockUtil.getInternalBlockLength( stripedBlk.getNumBytes(), stripedBlk.getCellSize(), stripedBlk.getDataBlockNum(), blockIndex); final Block targetBlk = new Block(stripedBlk.getBlockId() + blockIndex, internBlkLen, stripedBlk.getGenerationStamp()); source.addBlockToBeReplicated(targetBlk, new DatanodeStorageInfo[] {target}); if (BlockManager.LOG.isDebugEnabled()) { BlockManager.LOG.debug("Add replication task from source {} to " + "target {} for EC block {}", source, target, targetBlk); } }