use of alluxio.worker.block.meta.DefaultBlockMeta 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 DefaultBlockMeta(blockMeta.getBlockId(), blockMeta.getBlockSize(), dstDir);
dstDir.removeTempBlockMeta(tempBlockMeta);
dstDir.addBlockMeta(newBlockMeta);
return newBlockMeta;
}
use of alluxio.worker.block.meta.DefaultBlockMeta in project alluxio by Alluxio.
the class BlockMetadataManagerTest method moveBlockMetaDeprecatedExceedCapacity.
/**
* Tests that an exception is thrown in the
* {@link BlockMetadataManager#moveBlockMeta(BlockMeta, BlockStoreLocation)} method when the
* capacity is exceeded.
*/
@Test
public void moveBlockMetaDeprecatedExceedCapacity() throws Exception {
StorageDir dir = mMetaManager.getTier(Constants.MEDIUM_HDD).getDir(0);
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, 2000, dir);
dir.addBlockMeta(blockMeta);
mThrown.expect(WorkerOutOfSpaceException.class);
mThrown.expectMessage("does not have enough space");
mMetaManager.moveBlockMeta(blockMeta, new BlockStoreLocation(Constants.MEDIUM_MEM, 0));
}
use of alluxio.worker.block.meta.DefaultBlockMeta in project alluxio by Alluxio.
the class BlockMetadataViewTest method getBlockMeta.
/**
* Tests the {@link BlockMetadataEvictorView#getBlockMeta(long)} method.
*/
@Test
public void getBlockMeta() throws Exception {
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getDir(TEST_DIR);
// Add one block to test dir, expect block meta found
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
dir.addBlockMeta(blockMeta);
assertEquals(blockMeta, mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertTrue(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// Lock this block, expect null result
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(true);
assertNull(mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertFalse(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// Pin this block, expect null result
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(true);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
assertNull(mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertFalse(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
// No Pin or lock on this block, expect block meta found
when(mMetadataView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
when(mMetadataView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
assertEquals(blockMeta, mMetadataView.getBlockMeta(TEST_BLOCK_ID));
assertTrue(mMetadataView.isBlockEvictable(TEST_BLOCK_ID));
}
use of alluxio.worker.block.meta.DefaultBlockMeta in project alluxio by Alluxio.
the class BlockMetadataViewTest method sameTierView.
/**
* Tests that {@code BlockMetadataEvictorView.getTierView(tierAlias)} returns the same
* TierView as {@code new StorageTierEvictorView(mMetadataManager.getTier(tierAlias), this)}.
*/
@Test
public void sameTierView() {
String tierAlias = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getTierAlias();
StorageTierView tierView1 = mMetadataView.getTierView(tierAlias);
// Do some operations on metadata
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getDir(TEST_DIR);
BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
try {
dir.addBlockMeta(blockMeta);
} catch (Exception e) {
e.printStackTrace();
}
StorageTierEvictorView tierView2 = new StorageTierEvictorView(mMetaManager.getTier(tierAlias), mMetadataView);
assertSameTierView((StorageTierEvictorView) tierView1, tierView2);
}
use of alluxio.worker.block.meta.DefaultBlockMeta in project alluxio by Alluxio.
the class AllocatorTestBase method assertTempBlockMeta.
/**
* Given an allocator with the location, blockSize, tierAlias and dirIndex,
* we assert whether the block can be allocated.
*
* @param allocator the allocation manager of Alluxio managed data
* @param location the location in block store
* @param blockSize the size of block in bytes
* @param avail the block should be successfully allocated or not
* @param tierAlias the block should be allocated at this tier
* @param dirIndex the block should be allocated at this dir
*/
protected void assertTempBlockMeta(Allocator allocator, BlockStoreLocation location, int blockSize, boolean avail, String tierAlias, int dirIndex) throws Exception {
mTestBlockId++;
StorageDirView dirView = allocator.allocateBlockWithView(SESSION_ID, blockSize, location, getMetadataEvictorView(), false);
TempBlockMeta tempBlockMeta = dirView == null ? null : dirView.createTempBlockMeta(SESSION_ID, mTestBlockId, blockSize);
if (!avail) {
assertTrue(tempBlockMeta == null);
} else {
assertTrue(tempBlockMeta != null);
StorageDir pDir = tempBlockMeta.getParentDir();
StorageTier pTier = pDir.getParentTier();
assertEquals(dirIndex, pDir.getDirIndex());
assertEquals(tierAlias, pTier.getTierAlias());
// update the dir meta info
pDir.addBlockMeta(new DefaultBlockMeta(mTestBlockId, blockSize, pDir));
}
}
Aggregations