Search in sources :

Example 31 with BlockDoesNotExistException

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

the class SwapRestoreTask method getBalancingTransfersList.

/**
 * @return the list of transfer in order to balance swap-space within tier
 */
private List<BlockTransferInfo> getBalancingTransfersList() {
    List<BlockTransferInfo> transferInfos = new LinkedList<>();
    for (StorageTierView tierView : mEvictorView.getTierViews()) {
        for (StorageDirView dirView : tierView.getDirViews()) {
            Iterator<Long> dirBlockIter = mMetadataManager.getBlockIterator().getIterator(new BlockStoreLocation(tierView.getTierViewAlias(), dirView.getDirViewIndex()), BlockOrder.NATURAL);
            while (dirBlockIter.hasNext() && dirView.getAvailableBytes() < dirView.getReservedBytes()) {
                long blockId = dirBlockIter.next();
                try {
                    BlockMeta movingOutBlock = mEvictorView.getBlockMeta(blockId);
                    if (movingOutBlock == null) {
                        LOG.debug("Block:{} exist but not available for balancing.", blockId);
                        continue;
                    }
                    // Find where to move the block.
                    StorageDirView dstDirView = null;
                    for (StorageDirView candidateDirView : tierView.getDirViews()) {
                        if (candidateDirView.getDirViewIndex() == dirView.getDirViewIndex()) {
                            continue;
                        }
                        if (candidateDirView.getAvailableBytes() - candidateDirView.getReservedBytes() >= movingOutBlock.getBlockSize()) {
                            dstDirView = candidateDirView;
                            break;
                        }
                    }
                    if (dstDirView == null) {
                        LOG.warn("Could not balance swap-restore space for location: {}", dirView.toBlockStoreLocation());
                        break;
                    }
                    // TODO(ggezer): Consider allowing evictions for this move.
                    transferInfos.add(BlockTransferInfo.createMove(movingOutBlock.getBlockLocation(), blockId, dstDirView.toBlockStoreLocation()));
                    // Account for moving-out blocks.
                    ((StorageDirEvictorView) dirView).markBlockMoveOut(blockId, movingOutBlock.getBlockSize());
                    // Account for moving-in blocks.
                    ((StorageDirEvictorView) dstDirView).markBlockMoveIn(blockId, movingOutBlock.getBlockSize());
                } catch (BlockDoesNotExistException e) {
                    LOG.warn("Failed to find metadata for block:{} during swap-restore balancing.", blockId);
                }
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated {} balance transfers:\n ->{}", transferInfos.size(), transferInfos.stream().map(Object::toString).collect(Collectors.joining(",\n ->")));
    }
    return transferInfos;
}
Also used : BlockTransferInfo(alluxio.worker.block.evictor.BlockTransferInfo) StorageDirEvictorView(alluxio.worker.block.meta.StorageDirEvictorView) StorageDirView(alluxio.worker.block.meta.StorageDirView) LinkedList(java.util.LinkedList) StorageTierView(alluxio.worker.block.meta.StorageTierView) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockMeta(alluxio.worker.block.meta.BlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Aggregations

BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)31 IOException (java.io.IOException)16 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)14 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)12 BlockMeta (alluxio.worker.block.meta.BlockMeta)12 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)11 LockResource (alluxio.resource.LockResource)8 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)8 AlluxioException (alluxio.exception.AlluxioException)6 BlockReader (alluxio.worker.block.io.BlockReader)6 ArrayList (java.util.ArrayList)5 UnavailableException (alluxio.exception.status.UnavailableException)4 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)4 StorageDirView (alluxio.worker.block.meta.StorageDirView)4 AlluxioURI (alluxio.AlluxioURI)3 DelegatingBlockReader (alluxio.worker.block.io.DelegatingBlockReader)3 StorageTierView (alluxio.worker.block.meta.StorageTierView)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Test (org.junit.Test)3