Ejemplo n.º 1
0
  /**
   * Gets the amount of available space of given location in bytes. Master queries the total number
   * of bytes available on each tier of the worker, and Evictor/Allocator often cares about the
   * bytes at a {@link StorageDir}.
   *
   * @param location location the check available bytes
   * @return available bytes
   * @throws IllegalArgumentException when location does not belong to tiered storage
   */
  public synchronized long getAvailableBytes(BlockStoreLocation location) {
    long spaceAvailable = 0;

    if (location.equals(BlockStoreLocation.anyTier())) {
      for (StorageTier tier : mTiers) {
        spaceAvailable += tier.getAvailableBytes();
      }
      return spaceAvailable;
    }

    int tierAlias = location.tierAlias();
    StorageTier tier = getTier(tierAlias);
    // TODO: This should probably be max of the capacity bytes in the dirs?
    if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
      return tier.getAvailableBytes();
    }

    int dirIndex = location.dir();
    StorageDir dir = tier.getDir(dirIndex);
    return dir.getAvailableBytes();
  }
Ejemplo n.º 2
0
 public BlockStoreMeta(BlockMetadataManager manager) {
   Preconditions.checkNotNull(manager);
   for (StorageTier tier : manager.getTiers()) {
     int aliasIndex = tier.getTierAlias() - 1;
     mCapacityBytesOnTiers.set(
         aliasIndex, mCapacityBytesOnTiers.get(aliasIndex) + tier.getCapacityBytes());
     mUsedBytesOnTiers.set(
         aliasIndex,
         mUsedBytesOnTiers.get(aliasIndex) + (tier.getCapacityBytes() - tier.getAvailableBytes()));
     for (StorageDir dir : tier.getStorageDirs()) {
       mBlockIdsOnDirs.put(dir.getStorageDirId(), dir.getBlockIds());
       mCapacityBytesOnDirs.put(dir.getStorageDirId(), dir.getCapacityBytes());
       mUsedBytesOnDirs.put(
           dir.getStorageDirId(), dir.getCapacityBytes() - dir.getAvailableBytes());
       mDirPaths.put(dir.getStorageDirId(), dir.getDirPath());
     }
   }
 }