Search in sources :

Example 11 with BlockDoesNotExistException

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

the class DefaultBlockWorker method createLocalBlockReader.

/**
 * Creates the block reader to read the local cached block starting from given block offset.
 * Owner of this block reader must close it or lock will leak.
 *
 * @param sessionId the id of the client
 * @param blockId the id of the block to read
 * @param offset the offset within this block
 * @return the block reader for the block or null if block not found
 */
@Nullable
private BlockReader createLocalBlockReader(long sessionId, long blockId, long offset) throws IOException {
    long lockId = mLocalBlockStore.lockBlockNoException(sessionId, blockId);
    if (lockId == BlockWorker.INVALID_LOCK_ID) {
        return null;
    }
    try {
        BlockReader reader = mLocalBlockStore.getBlockReader(sessionId, blockId, lockId);
        ((FileChannel) reader.getChannel()).position(offset);
        mLocalBlockStore.accessBlock(sessionId, blockId);
        return new DelegatingBlockReader(reader, () -> {
            try {
                mLocalBlockStore.unlockBlock(lockId);
            } catch (BlockDoesNotExistException e) {
                throw new IOException(e);
            }
        });
    } catch (Exception e) {
        try {
            mLocalBlockStore.unlockBlock(lockId);
        } catch (Exception ee) {
            LOG.warn("Failed to unlock block blockId={}, lockId={}", blockId, lockId, ee);
        }
        throw new IOException(String.format("Failed to get local block reader, sessionId=%d, " + "blockId=%d, offset=%d", sessionId, blockId, offset), e);
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) BlockReader(alluxio.worker.block.io.BlockReader) DelegatingBlockReader(alluxio.worker.block.io.DelegatingBlockReader) DelegatingBlockReader(alluxio.worker.block.io.DelegatingBlockReader) IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) AlluxioException(alluxio.exception.AlluxioException) UnavailableException(alluxio.exception.status.UnavailableException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Nullable(javax.annotation.Nullable)

Example 12 with BlockDoesNotExistException

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

the class DefaultBlockWorker method createUfsBlockReader.

@Override
public BlockReader createUfsBlockReader(long sessionId, long blockId, long offset, boolean positionShort, Protocol.OpenUfsBlockOptions options) throws BlockDoesNotExistException, IOException {
    try {
        openUfsBlock(sessionId, blockId, options);
        BlockReader reader = mUnderFileSystemBlockStore.getBlockReader(sessionId, blockId, offset, positionShort, options.getUser());
        return new DelegatingBlockReader(reader, () -> {
            try {
                closeUfsBlock(sessionId, blockId);
            } catch (BlockAlreadyExistsException | IOException | WorkerOutOfSpaceException e) {
                throw new IOException(e);
            }
        });
    } catch (Exception e) {
        try {
            closeUfsBlock(sessionId, blockId);
        } catch (Exception ee) {
            LOG.warn("Failed to close UFS block", ee);
        }
        throw new IOException(String.format("Failed to read from UFS, sessionId=%d, " + "blockId=%d, offset=%d, positionShort=%s, options=%s: %s", sessionId, blockId, offset, positionShort, options, e.toString()), e);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) BlockReader(alluxio.worker.block.io.BlockReader) DelegatingBlockReader(alluxio.worker.block.io.DelegatingBlockReader) DelegatingBlockReader(alluxio.worker.block.io.DelegatingBlockReader) IOException(java.io.IOException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) AlluxioException(alluxio.exception.AlluxioException) UnavailableException(alluxio.exception.status.UnavailableException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Example 13 with BlockDoesNotExistException

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

the class AlignTask method generateSwapTransferInfos.

private List<BlockTransferInfo> generateSwapTransferInfos(Pair<List<Long>, List<Long>> swapLists) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating transfer infos from swap lists.\n" + "Source list of size:{} : {}\nDestination list of size:{} : {}", swapLists.getFirst().size(), swapLists.getFirst().stream().map(Object::toString).collect(Collectors.joining(",")), swapLists.getSecond().size(), swapLists.getSecond().stream().map(Object::toString).collect(Collectors.joining(",")));
    }
    // Function that is used to map blockId to <blockId,location> pair.
    Function<Long, Pair<Long, BlockStoreLocation>> blockToPairFunc = (blockId) -> {
        try {
            return new Pair(blockId, mEvictorView.getBlockMeta(blockId).getBlockLocation());
        } catch (BlockDoesNotExistException e) {
            LOG.warn("Failed to find location of a block:{}. Error: {}", blockId, e);
            return new Pair(blockId, BlockStoreLocation.anyTier());
        }
    };
    // Generate an augmented block lists with locations.
    List<Pair<Long, BlockStoreLocation>> blockLocPairListSrc = swapLists.getFirst().stream().map(blockToPairFunc).collect(Collectors.toList());
    List<Pair<Long, BlockStoreLocation>> blockLocPairListDst = swapLists.getSecond().stream().map(blockToPairFunc).collect(Collectors.toList());
    // Sort augmented lists by location.
    // This will help to generate the buckets by a linear sweep.
    Comparator<Pair<Long, BlockStoreLocation>> comparator = (o1, o2) -> {
        BlockStoreLocation loc1 = o1.getSecond();
        BlockStoreLocation loc2 = o2.getSecond();
        int tierComp = loc1.tierAlias().compareTo(loc2.tierAlias());
        if (tierComp != 0) {
            return tierComp;
        } else {
            return loc1.dir() - loc2.dir();
        }
    };
    Collections.sort(blockLocPairListSrc, comparator);
    Collections.sort(blockLocPairListDst, comparator);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated and sorted augmented swap lists.\n" + "Source list of size:{} :\n ->{}\nDestination list of size:{} :\n ->{}", blockLocPairListSrc.size(), blockLocPairListSrc.stream().map(Object::toString).collect(Collectors.joining("\n ->")), blockLocPairListDst.size(), blockLocPairListDst.stream().map(Object::toString).collect(Collectors.joining("\n ->")));
    }
    // Build transfer infos using the sorted locations.
    List<BlockTransferInfo> transferInfos = new ArrayList<>(blockLocPairListSrc.size());
    for (int i = 0; i < blockLocPairListSrc.size(); i++) {
        transferInfos.add(BlockTransferInfo.createSwap(blockLocPairListSrc.get(i).getSecond(), blockLocPairListSrc.get(i).getFirst(), blockLocPairListDst.get(i).getSecond(), blockLocPairListDst.get(i).getFirst()));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated {} swap transfers: \n ->{}", transferInfos.size(), transferInfos.stream().map(Object::toString).collect(Collectors.joining(",\n ->")));
    }
    return transferInfos;
}
Also used : BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockMetadataManager(alluxio.worker.block.BlockMetadataManager) LoggerFactory(org.slf4j.LoggerFactory) BlockOperationResult(alluxio.worker.block.management.BlockOperationResult) PropertyKey(alluxio.conf.PropertyKey) ArrayList(java.util.ArrayList) BlockManagementTaskResult(alluxio.worker.block.management.BlockManagementTaskResult) ExecutorService(java.util.concurrent.ExecutorService) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) Function(com.google.common.base.Function) Logger(org.slf4j.Logger) ServerConfiguration(alluxio.conf.ServerConfiguration) BlockOrder(alluxio.worker.block.annotator.BlockOrder) Pair(alluxio.collections.Pair) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) BlockTransferInfo(alluxio.worker.block.evictor.BlockTransferInfo) BlockOperationType(alluxio.worker.block.management.BlockOperationType) List(java.util.List) StoreLoadTracker(alluxio.worker.block.management.StoreLoadTracker) BlockStore(alluxio.worker.block.BlockStore) AbstractBlockManagementTask(alluxio.worker.block.management.AbstractBlockManagementTask) Preconditions(com.google.common.base.Preconditions) BlockMetadataEvictorView(alluxio.worker.block.BlockMetadataEvictorView) Comparator(java.util.Comparator) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Collections(java.util.Collections) ManagementTaskCoordinator(alluxio.worker.block.management.ManagementTaskCoordinator) BlockTransferInfo(alluxio.worker.block.evictor.BlockTransferInfo) ArrayList(java.util.ArrayList) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) Pair(alluxio.collections.Pair)

Example 14 with BlockDoesNotExistException

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

the class TieredBlockStore method lockBlock.

@Override
public long lockBlock(long sessionId, long blockId) throws BlockDoesNotExistException {
    LOG.debug("lockBlock: sessionId={}, blockId={}", sessionId, blockId);
    long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.READ);
    boolean hasBlock;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        hasBlock = mMetaManager.hasBlockMeta(blockId);
    }
    if (hasBlock) {
        return lockId;
    }
    mLockManager.unlockBlock(lockId);
    throw new BlockDoesNotExistException(ExceptionMessage.NO_BLOCK_ID_FOUND, blockId);
}
Also used : LockResource(alluxio.resource.LockResource) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Example 15 with BlockDoesNotExistException

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

the class TieredBlockStore method moveBlockInternal.

/**
 * Moves a block to new location only if allocator finds available space in newLocation. This
 * method will not trigger any eviction. Returns {@link MoveBlockResult}.
 *
 * @param sessionId session id
 * @param blockId block id
 * @param oldLocation the source location of the block
 * @param moveOptions the allocate options for the move
 * @return the resulting information about the move operation
 * @throws BlockDoesNotExistException if block is not found
 * @throws BlockAlreadyExistsException if a block with same id already exists in new location
 * @throws InvalidWorkerStateException if the block to move is a temp block
 */
private MoveBlockResult moveBlockInternal(long sessionId, long blockId, BlockStoreLocation oldLocation, AllocateOptions moveOptions) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException {
    long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.WRITE);
    try {
        long blockSize;
        String srcFilePath;
        String dstFilePath;
        BlockMeta srcBlockMeta;
        BlockStoreLocation srcLocation;
        BlockStoreLocation dstLocation;
        try (LockResource r = new LockResource(mMetadataReadLock)) {
            if (mMetaManager.hasTempBlockMeta(blockId)) {
                throw new InvalidWorkerStateException(ExceptionMessage.MOVE_UNCOMMITTED_BLOCK, blockId);
            }
            srcBlockMeta = mMetaManager.getBlockMeta(blockId);
            srcLocation = srcBlockMeta.getBlockLocation();
            srcFilePath = srcBlockMeta.getPath();
            blockSize = srcBlockMeta.getBlockSize();
            // Update moveOptions with the block size.
            moveOptions.setSize(blockSize);
        }
        if (!srcLocation.belongsTo(oldLocation)) {
            throw new BlockDoesNotExistException(ExceptionMessage.BLOCK_NOT_FOUND_AT_LOCATION, blockId, oldLocation);
        }
        if (srcLocation.belongsTo(moveOptions.getLocation())) {
            return new MoveBlockResult(true, blockSize, srcLocation, srcLocation);
        }
        TempBlockMeta dstTempBlock;
        try {
            dstTempBlock = createBlockMetaInternal(sessionId, blockId, false, moveOptions);
        } catch (Exception e) {
            return new MoveBlockResult(false, blockSize, null, null);
        }
        // When `newLocation` is some specific location, the `newLocation` and the `dstLocation` are
        // just the same; while for `newLocation` with a wildcard significance, the `dstLocation`
        // is a specific one with specific tier and dir which belongs to newLocation.
        dstLocation = dstTempBlock.getBlockLocation();
        // internally from the newLocation and return success with specific block location.
        if (dstLocation.belongsTo(srcLocation)) {
            mMetaManager.abortTempBlockMeta(dstTempBlock);
            return new MoveBlockResult(true, blockSize, srcLocation, dstLocation);
        }
        dstFilePath = dstTempBlock.getCommitPath();
        // Heavy IO is guarded by block lock but not metadata lock. This may throw IOException.
        FileUtils.move(srcFilePath, dstFilePath);
        try (LockResource r = new LockResource(mMetadataWriteLock)) {
            // If this metadata update fails, we panic for now.
            // TODO(bin): Implement rollback scheme to recover from IO failures.
            mMetaManager.moveBlockMeta(srcBlockMeta, dstTempBlock);
        } catch (BlockAlreadyExistsException | BlockDoesNotExistException | WorkerOutOfSpaceException e) {
            // we shall never reach here
            throw Throwables.propagate(e);
        }
        return new MoveBlockResult(true, blockSize, srcLocation, dstLocation);
    } finally {
        mLockManager.unlockBlock(lockId);
    }
}
Also used : WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) IOException(java.io.IOException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) LockResource(alluxio.resource.LockResource) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

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