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