Search in sources :

Example 16 with BlockAlreadyExistsException

use of alluxio.exception.BlockAlreadyExistsException 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 17 with BlockAlreadyExistsException

use of alluxio.exception.BlockAlreadyExistsException 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)

Example 18 with BlockAlreadyExistsException

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

the class BlockMetadataManager method commitTempBlockMeta.

/**
 * Commits a temp block.
 *
 * @param tempBlockMeta the metadata of the temp block to commit
 * @throws WorkerOutOfSpaceException when no more space left to hold the block
 * @throws BlockAlreadyExistsException when the block already exists in committed blocks
 * @throws BlockDoesNotExistException when temp block can not be found
 */
public void commitTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException, BlockDoesNotExistException {
    long blockId = tempBlockMeta.getBlockId();
    if (hasBlockMeta(blockId)) {
        BlockMeta blockMeta = getBlockMeta(blockId);
        throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK.getMessage(blockId, blockMeta.getBlockLocation().tierAlias()));
    }
    BlockMeta block = new DefaultBlockMeta(Preconditions.checkNotNull(tempBlockMeta));
    StorageDir dir = tempBlockMeta.getParentDir();
    dir.removeTempBlockMeta(tempBlockMeta);
    dir.addBlockMeta(block);
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Aggregations

BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)18 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)11 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)11 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)9 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)8 LockResource (alluxio.resource.LockResource)8 IOException (java.io.IOException)7 BlockMeta (alluxio.worker.block.meta.BlockMeta)6 AlluxioException (alluxio.exception.AlluxioException)3 UnavailableException (alluxio.exception.status.UnavailableException)2 BlockReader (alluxio.worker.block.io.BlockReader)2 BlockWriter (alluxio.worker.block.io.BlockWriter)2 StorageDirView (alluxio.worker.block.meta.StorageDirView)2 UnderFileSystemBlockMeta (alluxio.worker.block.meta.UnderFileSystemBlockMeta)2 HashMap (java.util.HashMap)2 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 DeadlineExceededException (alluxio.exception.status.DeadlineExceededException)1 AlluxioTException (alluxio.thrift.AlluxioTException)1 BlockWorker (alluxio.worker.block.BlockWorker)1