@Override final boolean hasNoStorage() { final int len = getCapacity(); for(int idx = 0; idx < len; idx++) { if (getStorageInfo(idx) != null) { return false; } } return true; }
@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; }
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; }
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; }
@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; }