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();
}
}
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);
}
}
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);
}
Aggregations