Search in sources :

Example 6 with WorkerOutOfSpaceException

use of alluxio.exception.WorkerOutOfSpaceException in project alluxio by Alluxio.

the class BlockMetadataManager method moveBlockMeta.

/**
   * Moves the metadata of an existing block to another location or throws IOExceptions. Throws an
   * {@link IllegalArgumentException} if the newLocation is not in the tiered storage.
   *
   * @param blockMeta the metadata of the block to move
   * @param newLocation new location of the block
   * @return the new block metadata if success, absent otherwise
   * @throws BlockDoesNotExistException when the block to move is not found
   * @throws BlockAlreadyExistsException when the block to move already exists in the destination
   * @throws WorkerOutOfSpaceException when destination have no extra space to hold the block to
   *         move
   * @deprecated As of version 0.8. Use {@link #moveBlockMeta(BlockMeta, TempBlockMeta)} instead.
   */
@Deprecated
public BlockMeta moveBlockMeta(BlockMeta blockMeta, BlockStoreLocation newLocation) throws BlockDoesNotExistException, BlockAlreadyExistsException, WorkerOutOfSpaceException {
    // If existing location belongs to the target location, simply return the current block meta.
    BlockStoreLocation oldLocation = blockMeta.getBlockLocation();
    if (oldLocation.belongsTo(newLocation)) {
        LOG.info("moveBlockMeta: moving {} to {} is a noop", oldLocation, newLocation);
        return blockMeta;
    }
    long blockSize = blockMeta.getBlockSize();
    String 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 WorkerOutOfSpaceException("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;
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) AbstractBlockMeta(alluxio.worker.block.meta.AbstractBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Aggregations

WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)6 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)5 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)4 LockResource (alluxio.resource.LockResource)4 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)4 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)3 BlockMeta (alluxio.worker.block.meta.BlockMeta)2 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)1 EvictionPlan (alluxio.worker.block.evictor.EvictionPlan)1 LocalFileBlockWriter (alluxio.worker.block.io.LocalFileBlockWriter)1 AbstractBlockMeta (alluxio.worker.block.meta.AbstractBlockMeta)1 StorageDir (alluxio.worker.block.meta.StorageDir)1 StorageDirView (alluxio.worker.block.meta.StorageDirView)1 StorageTier (alluxio.worker.block.meta.StorageTier)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1