use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class BlockMetadataManager method moveBlockMeta.
/**
* Moves an existing block to another location currently hold by a temp block.
*
* @param blockMeta the metadata of the block to move
* @param tempBlockMeta a placeholder in the destination directory
* @return the new block metadata if success, absent otherwise
* @throws BlockDoesNotExistException when the block to move is not found
* @throws BlockAlreadyExistsException when the block to move already exists in the destination
* @throws WorkerOutOfSpaceException when destination have no extra space to hold the block to
* move
*/
public BlockMeta moveBlockMeta(BlockMeta blockMeta, TempBlockMeta tempBlockMeta) throws BlockDoesNotExistException, WorkerOutOfSpaceException, BlockAlreadyExistsException {
StorageDir srcDir = blockMeta.getParentDir();
StorageDir dstDir = tempBlockMeta.getParentDir();
srcDir.removeBlockMeta(blockMeta);
BlockMeta newBlockMeta = new BlockMeta(blockMeta.getBlockId(), blockMeta.getBlockSize(), dstDir);
dstDir.removeTempBlockMeta(tempBlockMeta);
dstDir.addBlockMeta(newBlockMeta);
return newBlockMeta;
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStore method createBlockMetaInternal.
/**
* Creates a temp block meta only if allocator finds available space. This method will not trigger
* any eviction.
*
* @param sessionId session Id
* @param blockId block Id
* @param location location to create the block
* @param initialBlockSize initial block size in bytes
* @param newBlock true if this temp block is created for a new block
* @return a temp block created if successful, or null if allocation failed (instead of throwing
* {@link WorkerOutOfSpaceException} because allocation failure could be an expected case)
* @throws BlockAlreadyExistsException if there is already a block with the same block id
*/
private TempBlockMeta createBlockMetaInternal(long sessionId, long blockId, BlockStoreLocation location, long initialBlockSize, boolean newBlock) throws BlockAlreadyExistsException {
// block lock here since no sharing
try (LockResource r = new LockResource(mMetadataWriteLock)) {
if (newBlock) {
checkTempBlockIdAvailable(blockId);
}
StorageDirView dirView = mAllocator.allocateBlockWithView(sessionId, initialBlockSize, location, getUpdatedView());
if (dirView == null) {
// Allocator fails to find a proper place for this new block.
return null;
}
// TODO(carson): Add tempBlock to corresponding storageDir and remove the use of
// StorageDirView.createTempBlockMeta.
TempBlockMeta tempBlock = dirView.createTempBlockMeta(sessionId, blockId, initialBlockSize);
try {
// Add allocated temp block to metadata manager. This should never fail if allocator
// correctly assigns a StorageDir.
mMetaManager.addTempBlockMeta(tempBlock);
} catch (WorkerOutOfSpaceException | BlockAlreadyExistsException e) {
// If we reach here, allocator is not working properly
LOG.error("Unexpected failure: {} bytes allocated at {} by allocator, " + "but addTempBlockMeta failed", initialBlockSize, location);
throw Throwables.propagate(e);
}
return tempBlock;
}
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class BlockMetadataManagerTest method moveBlockMetaDiffDir.
/**
* Tests that an exception is thrown in the
* {@link BlockMetadataManager#moveBlockMeta(BlockMeta, TempBlockMeta)} method when trying to move
* a block to a not committed block meta.
*/
@Test
public void moveBlockMetaDiffDir() throws Exception {
// create and add two temp block metas with different dirs in the same HDD tier
StorageDir dir1 = mMetaManager.getTier("HDD").getDir(0);
StorageDir dir2 = mMetaManager.getTier("HDD").getDir(1);
TempBlockMeta tempBlockMeta1 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir1);
TempBlockMeta tempBlockMeta2 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID2, TEST_BLOCK_SIZE, dir2);
mMetaManager.addTempBlockMeta(tempBlockMeta1);
mMetaManager.addTempBlockMeta(tempBlockMeta2);
// commit the first temp block meta
mMetaManager.commitTempBlockMeta(tempBlockMeta1);
BlockMeta blockMeta = mMetaManager.getBlockMeta(TEST_TEMP_BLOCK_ID);
mMetaManager.moveBlockMeta(blockMeta, tempBlockMeta2);
// make sure that the dst tempBlockMeta has been removed from the dir2
mThrown.expect(BlockDoesNotExistException.class);
mThrown.expectMessage(ExceptionMessage.TEMP_BLOCK_META_NOT_FOUND.getMessage(TEST_TEMP_BLOCK_ID2));
mMetaManager.getTempBlockMeta(TEST_TEMP_BLOCK_ID2);
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class BlockMetadataManagerTest method resizeTempBlockMeta.
/**
* Tests the {@link BlockMetadataManager#resizeTempBlockMeta(TempBlockMeta, long)} method.
*/
@Test
public void resizeTempBlockMeta() throws Exception {
StorageDir dir = mMetaManager.getTier("MEM").getDir(0);
TempBlockMeta tempBlockMeta = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir);
mMetaManager.resizeTempBlockMeta(tempBlockMeta, TEST_BLOCK_SIZE + 1);
Assert.assertEquals(TEST_BLOCK_SIZE + 1, tempBlockMeta.getBlockSize());
}
use of alluxio.worker.block.meta.TempBlockMeta in project alluxio by Alluxio.
the class TieredBlockStoreTest method createBlockMetaWithEviction.
/**
* Tests the {@link TieredBlockStore#createBlock(long, long, BlockStoreLocation, long)} method
* to work with eviction.
*/
@Test
public void createBlockMetaWithEviction() throws Exception {
TieredBlockStoreTestUtils.cache(SESSION_ID1, BLOCK_ID1, BLOCK_SIZE, mTestDir1, mMetaManager, mEvictor);
TempBlockMeta tempBlockMeta = mBlockStore.createBlock(SESSION_ID1, TEMP_BLOCK_ID, mTestDir1.toBlockStoreLocation(), mTestDir1.getCapacityBytes());
// Expect BLOCK_ID1 evicted from mTestDir1
Assert.assertFalse(mTestDir1.hasBlockMeta(BLOCK_ID1));
Assert.assertFalse(FileUtils.exists(BlockMeta.commitPath(mTestDir1, BLOCK_ID1)));
Assert.assertEquals(mTestDir1.getCapacityBytes(), tempBlockMeta.getBlockSize());
Assert.assertEquals(mTestDir1, tempBlockMeta.getParentDir());
}
Aggregations