private int findSlot() { int i = getTotalBlockNum(); for (; i < getCapacity(); i++) { if (getStorageInfo(i) == null) { return i; } } // need to expand the storage size ensureCapacity(i + 1, true); return i; }
byte getStorageBlockIndex(DatanodeStorageInfo storage) { int i = this.findStorageInfo(storage); return i == -1 ? -1 : indices[i]; }
@Override boolean removeStorage(DatanodeStorageInfo storage) { int dnIndex = findStorageInfoFromEnd(storage); if (dnIndex < 0) { // the node is not found return false; } // set the entry to null setStorageInfo(dnIndex, null); indices[dnIndex] = -1; return true; }
@Override final boolean hasNoStorage() { final int len = getCapacity(); for(int idx = 0; idx < len; idx++) { if (getStorageInfo(idx) != null) { return false; } } 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); } }
@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; }
/** * If the block is committed/completed and its length is less than a full * stripe, it returns the the number of actual data blocks. * Otherwise it returns the number of data units specified by erasure coding policy. */ public short getRealDataBlockNum() { if (isComplete() || getBlockUCState() == BlockUCState.COMMITTED) { return (short) Math.min(getDataBlockNum(), (getNumBytes() - 1) / ecPolicy.getCellSize() + 1); } else { return getDataBlockNum(); } }
private void ensureCapacity(int totalSize, boolean keepOld) { if (getCapacity() < totalSize) { DatanodeStorageInfo[] old = storages; byte[] oldIndices = indices; storages = new DatanodeStorageInfo[totalSize]; indices = new byte[totalSize]; initIndices(); if (keepOld) { System.arraycopy(old, 0, storages, 0, old.length); System.arraycopy(oldIndices, 0, indices, 0, oldIndices.length); } } }
/** * 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; } }
new BlockInfoStriped(completeBlk, ecPolicy); final long actualBlockGroupSize = striped.spaceConsumed();
blockInfo = new BlockInfoStriped(block, ecPolicy); blockInfo.convertToBlockUnderConstruction( HdfsServerConstants.BlockUCState.UNDER_CONSTRUCTION, targets);
private Block getBlockOnStorage(BlockInfo storedBlock, DatanodeStorageInfo storage) { return storedBlock.isStriped() ? ((BlockInfoStriped) storedBlock).getBlockOnStorage(storage) : storedBlock; }
@Override public int numNodes() { assert this.storages != null : "BlockInfo is not initialized"; int num = 0; for (int idx = getCapacity()-1; idx >= 0; idx--) { if (getStorageInfo(idx) != null) { num++; } } return num; }
newBI = new BlockInfoStriped(newBlock, ecPolicy); } else { newBI = new BlockInfoContiguous(newBlock, newBI = new BlockInfoStriped(newBlock, ecPolicy); } else { newBI = new BlockInfoContiguous(newBlock,
private int findStorageInfoFromEnd(DatanodeStorageInfo storage) { final int len = getCapacity(); for(int idx = len - 1; idx >= 0; idx--) { DatanodeStorageInfo cur = getStorageInfo(idx); if (storage.equals(cur)) { return idx; } } return -1; }
boolean isStriped = ecPolicy != null; if (isStriped) { newBlockInfo = new BlockInfoStriped(newBlock, ecPolicy); } else { newBlockInfo = new BlockInfoContiguous(newBlock,
"File with ID " + n.getId() + " has an invalid erasure coding policy ID " + ecPolicy.getId()); blocks[i] = new BlockInfoStriped(PBHelperClient.convert(b), ecPolicy); } else { blocks[i] = new BlockInfoContiguous(PBHelperClient.convert(b), if (isStriped) { BlockInfoStriped striped = (BlockInfoStriped) lastBlk; ucBlk = new BlockInfoStriped(striped, ecPolicy); } else { ucBlk = new BlockInfoContiguous(lastBlk,