Beispiel #1
0
 /**
  * Removes a block from this storage dir or throws IOException.
  *
  * @param blockMeta the meta data of the block
  * @throws IOException if no block is found
  */
 public void removeBlockMeta(BlockMeta blockMeta) throws IOException {
   Preconditions.checkNotNull(blockMeta);
   long blockId = blockMeta.getBlockId();
   BlockMeta deletedBlockMeta = mBlockIdToBlockMap.remove(blockId);
   if (deletedBlockMeta == null) {
     throw new IOException("Failed to remove BlockMeta: blockId " + blockId + " not found");
   }
   reclaimSpace(blockMeta.getBlockSize(), true);
 }
Beispiel #2
0
 /**
  * Get evictable bytes for this dir, i.e., the total bytes of total evictable blocks
  *
  * @return evictable bytes for this dir
  */
 public long getEvitableBytes() {
   long bytes = 0;
   for (BlockMeta blockMeta : mDir.getBlocks()) {
     long blockId = blockMeta.getBlockId();
     if (mManagerView.isBlockEvictable(blockId)) {
       bytes += blockMeta.getBlockSize();
     }
   }
   return bytes;
 }
Beispiel #3
0
  /**
   * 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);
  }