コード例 #1
0
ファイル: StorageTier.java プロジェクト: rhli/tachyon
 /** @return the remaining capacity (in bytes) */
 public long getAvailableBytes() {
   long availableBytes = 0;
   for (StorageDir dir : mDirs) {
     availableBytes += dir.getAvailableBytes();
   }
   return availableBytes;
 }
コード例 #2
0
  /**
   * Moves the metadata of an existing block to another location or throws IOExceptions.
   *
   * @param blockMeta the meta data of the block to move
   * @param newLocation new location of the block
   * @return the new block metadata if success, absent otherwise
   * @throws IllegalArgumentException when the newLocation is not in the tiered storage
   * @throws NotFoundException when the block to move is not found
   * @throws AlreadyExistsException when the block to move already exists in the destination
   * @throws OutOfSpaceException when destination have no extra space to hold the block to move
   */
  public synchronized BlockMeta moveBlockMeta(BlockMeta blockMeta, BlockStoreLocation newLocation)
      throws NotFoundException, AlreadyExistsException, OutOfSpaceException {
    // If existing location belongs to the target location, simply return the current block meta.
    BlockStoreLocation oldLocation = blockMeta.getBlockLocation();
    if (oldLocation.belongTo(newLocation)) {
      LOG.info("moveBlockMeta: moving {} to {} is a noop", oldLocation, newLocation);
      return blockMeta;
    }

    long blockSize = blockMeta.getBlockSize();
    int newTierAlias = newLocation.tierAlias();
    StorageTier newTier = getTier(newTierAlias);
    StorageDir newDir = null;
    if (newLocation.equals(BlockStoreLocation.anyDirInTier(newTierAlias))) {
      for (StorageDir dir : newTier.getStorageDirs()) {
        if (dir.getAvailableBytes() >= blockSize) {
          newDir = dir;
          break;
        }
      }
    } else {
      StorageDir dir = newTier.getDir(newLocation.dir());
      if (dir.getAvailableBytes() >= blockSize) {
        newDir = dir;
      }
    }

    if (newDir == null) {
      throw new OutOfSpaceException(
          "Failed to move BlockMeta: newLocation "
              + newLocation
              + " does not have enough space for "
              + blockSize
              + " bytes");
    }
    StorageDir oldDir = blockMeta.getParentDir();
    oldDir.removeBlockMeta(blockMeta);
    BlockMeta newBlockMeta = new BlockMeta(blockMeta.getBlockId(), blockSize, newDir);
    newDir.addBlockMeta(newBlockMeta);
    return newBlockMeta;
  }
コード例 #3
0
ファイル: BlockStoreMeta.java プロジェクト: hailingu/tachyon
 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());
     }
   }
 }
コード例 #4
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();
  }
コード例 #5
0
ファイル: StorageDirView.java プロジェクト: kaka1992/tachyon
 /**
  * Get available bytes for this dir
  *
  * @return available bytes for this dir
  */
 public long getAvailableBytes() {
   return mDir.getAvailableBytes() + mBlocksToMoveOutSize - mBlocksToMoveInSize;
 }