@Test public void addTempBlockMetaTooBig() throws Exception { final long bigBlockSize = TEST_DIR_CAPACITY + 1; TempBlockMeta bigTempBlockMeta = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, bigBlockSize, mDir); String alias = bigTempBlockMeta.getBlockLocation().tierAlias(); mThrown.expect(WorkerOutOfSpaceException.class); mThrown.expectMessage(ExceptionMessage.NO_SPACE_FOR_BLOCK_META.getMessage(TEST_TEMP_BLOCK_ID, bigBlockSize, TEST_DIR_CAPACITY, alias)); mDir.addTempBlockMeta(bigTempBlockMeta); }
public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(tempBlockMeta, "tempBlockMeta"); long sessionId = tempBlockMeta.getSessionId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), tempBlockMeta.getBlockLocation().tierAlias()); } if (hasTempBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, tempBlockMeta.getBlockLocation().tierAlias()); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> sessionTempBlocks = mSessionIdToTempBlockIdsMap.get(sessionId); if (sessionTempBlocks == null) { mSessionIdToTempBlockIdsMap.put(sessionId, Sets.newHashSet(blockId)); } else { sessionTempBlocks.add(blockId); } reserveSpace(blockSize, false); }
StorageDir { public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(tempBlockMeta, "tempBlockMeta"); long sessionId = tempBlockMeta.getSessionId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), tempBlockMeta.getBlockLocation().tierAlias()); } if (hasTempBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, tempBlockMeta.getBlockLocation().tierAlias()); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> sessionTempBlocks = mSessionIdToTempBlockIdsMap.get(sessionId); if (sessionTempBlocks == null) { mSessionIdToTempBlockIdsMap.put(sessionId, Sets.newHashSet(blockId)); } else { sessionTempBlocks.add(blockId); } reserveSpace(blockSize, false); } }
StorageDir { public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(tempBlockMeta, "tempBlockMeta"); long sessionId = tempBlockMeta.getSessionId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), tempBlockMeta.getBlockLocation().tierAlias()); } if (hasTempBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, tempBlockMeta.getBlockLocation().tierAlias()); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> sessionTempBlocks = mSessionIdToTempBlockIdsMap.get(sessionId); if (sessionTempBlocks == null) { mSessionIdToTempBlockIdsMap.put(sessionId, Sets.newHashSet(blockId)); } else { sessionTempBlocks.add(blockId); } reserveSpace(blockSize, false); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); }
StorageDir { public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(tempBlockMeta, "tempBlockMeta"); long sessionId = tempBlockMeta.getSessionId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), tempBlockMeta.getBlockLocation().tierAlias()); } if (hasTempBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, tempBlockMeta.getBlockLocation().tierAlias()); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> sessionTempBlocks = mSessionIdToTempBlockIdsMap.get(sessionId); if (sessionTempBlocks == null) { mSessionIdToTempBlockIdsMap.put(sessionId, Sets.newHashSet(blockId)); } else { sessionTempBlocks.add(blockId); } reserveSpace(blockSize, false); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); static StorageDir newStorageDir(StorageTier tier, int dirIndex, long capacityBytes,
      long reservedBytes, String dirPath, String dirMedium); long getCapacityBytes(); long getAvailableBytes(); long getCommittedBytes(); String getDirPath(); String getDirMedium(); StorageTier getParentTier(); int getDirIndex(); List<Long> getBlockIds(); List<BlockMeta> getBlocks(); boolean hasBlockMeta(long blockId); boolean hasTempBlockMeta(long blockId); BlockMeta getBlockMeta(long blockId); TempBlockMeta getTempBlockMeta(long blockId); void addBlockMeta(BlockMeta blockMeta); void addTempBlockMeta(TempBlockMeta tempBlockMeta); void removeBlockMeta(BlockMeta blockMeta); void removeTempBlockMeta(TempBlockMeta tempBlockMeta); void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize); void cleanupSessionTempBlocks(long sessionId, List<Long> tempBlockIds); List<TempBlockMeta> getSessionTempBlocks(long sessionId); BlockStoreLocation toBlockStoreLocation(); long getReservedBytes(); }
StorageDir { public void addTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(tempBlockMeta, "tempBlockMeta"); long sessionId = tempBlockMeta.getSessionId(); long blockId = tempBlockMeta.getBlockId(); long blockSize = tempBlockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), tempBlockMeta.getBlockLocation().tierAlias()); } if (hasTempBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, tempBlockMeta.getBlockLocation().tierAlias()); } mBlockIdToTempBlockMap.put(blockId, tempBlockMeta); Set<Long> sessionTempBlocks = mSessionIdToTempBlockIdsMap.get(sessionId); if (sessionTempBlocks == null) { mSessionIdToTempBlockIdsMap.put(sessionId, Sets.newHashSet(blockId)); } else { sessionTempBlocks.add(blockId); } reserveSpace(blockSize, false); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); static StorageDir newStorageDir(StorageTier tier, int dirIndex, long capacityBytes,
      long reservedBytes, String dirPath, String dirMedium); long getCapacityBytes(); long getAvailableBytes(); long getCommittedBytes(); String getDirPath(); String getDirMedium(); StorageTier getParentTier(); int getDirIndex(); List<Long> getBlockIds(); List<BlockMeta> getBlocks(); boolean hasBlockMeta(long blockId); boolean hasTempBlockMeta(long blockId); BlockMeta getBlockMeta(long blockId); TempBlockMeta getTempBlockMeta(long blockId); void addBlockMeta(BlockMeta blockMeta); void addTempBlockMeta(TempBlockMeta tempBlockMeta); void removeBlockMeta(BlockMeta blockMeta); void removeTempBlockMeta(TempBlockMeta tempBlockMeta); void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize); void cleanupSessionTempBlocks(long sessionId, List<Long> tempBlockIds); List<TempBlockMeta> getSessionTempBlocks(long sessionId); BlockStoreLocation toBlockStoreLocation(); long getReservedBytes();  }