use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class BlockWorkerTest method createBlockLowerTier.
/**
* Tests the {@link BlockWorker#createBlock(long, long, String, long)} method with a tier
* other than MEM.
*/
@Test
public void createBlockLowerTier() throws Exception {
long blockId = mRandom.nextLong();
long initialBytes = mRandom.nextLong();
long sessionId = mRandom.nextLong();
String tierAlias = "HDD";
BlockStoreLocation location = BlockStoreLocation.anyDirInTier(tierAlias);
StorageDir storageDir = Mockito.mock(StorageDir.class);
TempBlockMeta meta = new TempBlockMeta(sessionId, blockId, initialBytes, storageDir);
when(mBlockStore.createBlock(sessionId, blockId, location, initialBytes)).thenReturn(meta);
when(storageDir.getDirPath()).thenReturn("/tmp");
assertEquals(PathUtils.concatPath("/tmp", ".tmp_blocks", sessionId % 1024, String.format("%x-%x", sessionId, blockId)), mBlockWorker.createBlock(sessionId, blockId, tierAlias, initialBytes));
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class DefaultBlockWorker method createBlock.
@Override
public String createBlock(long sessionId, long blockId, String tierAlias, long initialBytes) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException {
BlockStoreLocation loc = BlockStoreLocation.anyDirInTier(tierAlias);
TempBlockMeta createdBlock = mBlockStore.createBlock(sessionId, blockId, loc, initialBytes);
return createdBlock.getPath();
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStore method cleanupSession.
@Override
public void cleanupSession(long sessionId) {
// Release all locks the session is holding.
mLockManager.cleanupSession(sessionId);
// Collect a list of temp blocks the given session owns and abort all of them with best effort
List<TempBlockMeta> tempBlocksToRemove;
try (LockResource r = new LockResource(mMetadataReadLock)) {
tempBlocksToRemove = mMetaManager.getSessionTempBlocks(sessionId);
}
for (TempBlockMeta tempBlockMeta : tempBlocksToRemove) {
try {
LOG.warn("Clean up expired temporary block {} from session {}.", tempBlockMeta.getBlockId(), sessionId);
abortBlockInternal(sessionId, tempBlockMeta.getBlockId());
} catch (Exception e) {
LOG.error("Failed to cleanup tempBlock {} due to {}", tempBlockMeta.getBlockId(), e.getMessage());
}
}
}
use of alluxio.worker.block.meta.TempBlockMeta 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.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStore method commitBlockInternal.
/**
* Commits a temp block.
*
* @param sessionId the id of session
* @param blockId the id of block
* @return destination location to move the 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
* @throws IOException if I/O errors occur when deleting the block file
*/
private BlockStoreLocation commitBlockInternal(long sessionId, long blockId) throws BlockAlreadyExistsException, InvalidWorkerStateException, BlockDoesNotExistException, IOException {
long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.WRITE);
try {
// When committing TempBlockMeta, the final BlockMeta calculates the block size according to
// the actual file size of this TempBlockMeta. Therefore, commitTempBlockMeta must happen
// after moving actual block file to its committed path.
BlockStoreLocation loc;
String srcPath;
String dstPath;
TempBlockMeta tempBlockMeta;
try (LockResource r = new LockResource(mMetadataReadLock)) {
checkTempBlockOwnedBySession(sessionId, blockId);
tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
srcPath = tempBlockMeta.getPath();
dstPath = tempBlockMeta.getCommitPath();
loc = tempBlockMeta.getBlockLocation();
}
// Heavy IO is guarded by block lock but not metadata lock. This may throw IOException.
FileUtils.move(srcPath, dstPath);
try (LockResource r = new LockResource(mMetadataWriteLock)) {
mMetaManager.commitTempBlockMeta(tempBlockMeta);
} catch (BlockAlreadyExistsException | BlockDoesNotExistException | WorkerOutOfSpaceException e) {
// we shall never reach here
throw Throwables.propagate(e);
}
return loc;
} finally {
mLockManager.unlockBlock(lockId);
}
}
Aggregations