Exemplo n.º 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
  /**
   * Get a filtered list of block metadata, for blocks that are neither pinned or being blocked.
   *
   * @return a list of metadata for all evictable blocks
   */
  public List<BlockMeta> getEvictableBlocks() {
    List<BlockMeta> filteredList = new ArrayList<BlockMeta>();

    for (BlockMeta blockMeta : mDir.getBlocks()) {
      long blockId = blockMeta.getBlockId();
      if (mManagerView.isBlockEvictable(blockId)) {
        filteredList.add(blockMeta);
      }
    }
    return filteredList;
  }
Exemplo n.º 4
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);
  }