Search in sources :

Example 11 with InvalidWorkerStateException

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

the class BlockWorkerDataWriter method create.

/**
 * Creates an instance of {@link BlockWorkerDataWriter}.
 *
 * @param context the file system context
 * @param blockId the block ID
 * @param blockSize the block size in bytes
 * @param options the output stream options
 * @return the {@link BlockWorkerDataWriter} created
 */
public static BlockWorkerDataWriter create(final FileSystemContext context, long blockId, long blockSize, OutStreamOptions options) throws IOException {
    AlluxioConfiguration conf = context.getClusterConf();
    int chunkSize = (int) conf.getBytes(PropertyKey.USER_LOCAL_WRITER_CHUNK_SIZE_BYTES);
    long reservedBytes = Math.min(blockSize, conf.getBytes(PropertyKey.USER_FILE_RESERVED_BYTES));
    BlockWorker blockWorker = context.getProcessLocalWorker();
    Preconditions.checkNotNull(blockWorker, "blockWorker");
    long sessionId = SessionIdUtils.createSessionId();
    try {
        blockWorker.createBlock(sessionId, blockId, options.getWriteTier(), options.getMediumType(), reservedBytes);
        BlockWriter blockWriter = blockWorker.createBlockWriter(sessionId, blockId);
        return new BlockWorkerDataWriter(sessionId, blockId, options, blockWriter, blockWorker, chunkSize, reservedBytes, conf);
    } catch (BlockAlreadyExistsException | WorkerOutOfSpaceException | BlockDoesNotExistException | InvalidWorkerStateException e) {
        throw new IOException(e);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) BlockWriter(alluxio.worker.block.io.BlockWriter) IOException(java.io.IOException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) BlockWorker(alluxio.worker.block.BlockWorker) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

Example 12 with InvalidWorkerStateException

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

the class TieredBlockStore method removeBlockInternal.

@VisibleForTesting
BlockMeta removeBlockInternal(long sessionId, long blockId, BlockStoreLocation location, long timeoutMs) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException {
    long lockId = mLockManager.tryLockBlock(sessionId, blockId, BlockLockType.WRITE, timeoutMs, TimeUnit.MILLISECONDS);
    if (lockId == BlockWorker.INVALID_LOCK_ID) {
        throw new DeadlineExceededException(String.format("Can not acquire lock to remove block %d for session %d after %d ms", blockId, sessionId, REMOVE_BLOCK_TIMEOUT_MS));
    }
    BlockMeta blockMeta;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        if (mMetaManager.hasTempBlockMeta(blockId)) {
            throw new InvalidWorkerStateException(ExceptionMessage.REMOVE_UNCOMMITTED_BLOCK, blockId);
        }
        blockMeta = mMetaManager.getBlockMeta(blockId);
        if (!blockMeta.getBlockLocation().belongsTo(location)) {
            throw new BlockDoesNotExistException(ExceptionMessage.BLOCK_NOT_FOUND_AT_LOCATION, blockId, location);
        }
    } catch (Exception e) {
        mLockManager.unlockBlock(lockId);
        throw e;
    }
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        removeBlockFileAndMeta(blockMeta);
    } finally {
        mLockManager.unlockBlock(lockId);
    }
    return blockMeta;
}
Also used : LockResource(alluxio.resource.LockResource) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) 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) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with InvalidWorkerStateException

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

the class DefaultBlockWorker method commitBlock.

@Override
public void commitBlock(long sessionId, long blockId, boolean pinOnCreate) throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException, IOException, WorkerOutOfSpaceException {
    long lockId = BlockWorker.INVALID_LOCK_ID;
    try {
        lockId = mLocalBlockStore.commitBlockLocked(sessionId, blockId, pinOnCreate);
    } catch (BlockAlreadyExistsException e) {
        LOG.debug("Block {} has been in block store, this could be a retry due to master-side RPC " + "failure, therefore ignore the exception", blockId, e);
    }
    // Block successfully committed, update master with new block metadata
    if (lockId == BlockWorker.INVALID_LOCK_ID) {
        lockId = mLocalBlockStore.lockBlock(sessionId, blockId);
    }
    BlockMasterClient blockMasterClient = mBlockMasterClientPool.acquire();
    try {
        BlockMeta meta = mLocalBlockStore.getBlockMeta(sessionId, blockId, lockId);
        BlockStoreLocation loc = meta.getBlockLocation();
        String mediumType = loc.mediumType();
        Long length = meta.getBlockSize();
        BlockStoreMeta storeMeta = mLocalBlockStore.getBlockStoreMeta();
        Long bytesUsedOnTier = storeMeta.getUsedBytesOnTiers().get(loc.tierAlias());
        blockMasterClient.commitBlock(mWorkerId.get(), bytesUsedOnTier, loc.tierAlias(), mediumType, blockId, length);
    } catch (Exception e) {
        throw new IOException(ExceptionMessage.FAILED_COMMIT_BLOCK_TO_MASTER.getMessage(blockId), e);
    } finally {
        mBlockMasterClientPool.release(blockMasterClient);
        mLocalBlockStore.unlockBlock(lockId);
        Metrics.WORKER_ACTIVE_CLIENTS.dec();
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) IOException(java.io.IOException) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) 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 14 with InvalidWorkerStateException

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

the class TieredBlockStore method checkTempBlockOwnedBySession.

/**
 * Checks if block id is a temporary block and owned by session id. This method must be enclosed
 * by {@link #mMetadataLock}.
 *
 * @param sessionId the id of session
 * @param blockId the id of block
 * @throws BlockDoesNotExistException if block id can not be found in temporary blocks
 * @throws BlockAlreadyExistsException if block id already exists in committed blocks
 * @throws InvalidWorkerStateException if block id is not owned by session id
 */
private void checkTempBlockOwnedBySession(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException {
    if (mMetaManager.hasBlockMeta(blockId)) {
        throw new BlockAlreadyExistsException(ExceptionMessage.TEMP_BLOCK_ID_COMMITTED, blockId);
    }
    TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
    long ownerSessionId = tempBlockMeta.getSessionId();
    if (ownerSessionId != sessionId) {
        throw new InvalidWorkerStateException(ExceptionMessage.BLOCK_ID_FOR_DIFFERENT_SESSION, blockId, ownerSessionId, sessionId);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

Aggregations

InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)14 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)8 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)8 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)7 IOException (java.io.IOException)7 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)6 LockResource (alluxio.resource.LockResource)5 BlockMeta (alluxio.worker.block.meta.BlockMeta)5 DeadlineExceededException (alluxio.exception.status.DeadlineExceededException)2 FileInfo (alluxio.wire.FileInfo)2 OutputStream (java.io.OutputStream)2 AlluxioURI (alluxio.AlluxioURI)1 RpcUtils (alluxio.RpcUtils)1 URIStatus (alluxio.client.file.URIStatus)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 AlluxioException (alluxio.exception.AlluxioException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 CreateLocalBlockResponse (alluxio.grpc.CreateLocalBlockResponse)1 Mode (alluxio.security.authorization.Mode)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1