/** * Adds the metadata of a new block into this storage dir or throws IOException. * * @param tempBlockMeta the meta data of a temp block to add * @throws IOException if blockId already exists or not enough space */ public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws IOException { Preconditions.checkNotNull(tempBlockMeta); long userId = tempBlockMeta.getUserId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() < blockSize) { throw new IOException( "Failed to add TempBlockMeta: blockId " + blockId + " is " + blockSize + " bytes, but only " + getAvailableBytes() + " bytes available"); } if (hasTempBlockMeta(blockId)) { throw new IOException("Failed to add TempBlockMeta: blockId " + blockId + " exists"); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> userTempBlocks = mUserIdToTempBlockIdsMap.get(userId); if (userTempBlocks == null) { mUserIdToTempBlockIdsMap.put(userId, Sets.newHashSet(blockId)); } else { userTempBlocks.add(blockId); } reserveSpace(blockSize, false); }
/** * Changes the size of a temp block or throws IOException. * * @param tempBlockMeta the meta data of the temp block to resize * @param newSize the new size after change in bytes * @throws IOException */ public void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize) throws IOException { long oldSize = tempBlockMeta.getBlockSize(); tempBlockMeta.setBlockSize(newSize); if (newSize > oldSize) { reserveSpace(newSize - oldSize, false); } else if (newSize < oldSize) { throw new IOException("Shrinking block, not supported!"); } }
/** * Adds the metadata of a new block into this storage dir or throws IOException. * * @param blockMeta the meta data of the block * @throws IOException if blockId already exists or not enough space */ public void addBlockMeta(BlockMeta blockMeta) throws IOException { Preconditions.checkNotNull(blockMeta); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() < blockSize) { throw new IOException( "Failed to add BlockMeta: blockId " + blockId + " is " + blockSize + " bytes, but only " + getAvailableBytes() + " bytes available"); } if (hasBlockMeta(blockId)) { throw new IOException("Failed to add BlockMeta: blockId " + blockId + " exists"); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); }