Search in sources :

Example 1 with DefaultBlockMeta

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;
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 2 with DefaultBlockMeta

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));
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) Test(org.junit.Test)

Example 3 with DefaultBlockMeta

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));
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) Test(org.junit.Test)

Example 4 with DefaultBlockMeta

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);
}
Also used : StorageTierEvictorView(alluxio.worker.block.meta.StorageTierEvictorView) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageTierView(alluxio.worker.block.meta.StorageTierView) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) ExpectedException(org.junit.rules.ExpectedException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Test(org.junit.Test)

Example 5 with DefaultBlockMeta

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));
    }
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) StorageDirView(alluxio.worker.block.meta.StorageDirView) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Aggregations

DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)11 StorageDir (alluxio.worker.block.meta.StorageDir)11 BlockMeta (alluxio.worker.block.meta.BlockMeta)9 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)7 Test (org.junit.Test)6 DefaultTempBlockMeta (alluxio.worker.block.meta.DefaultTempBlockMeta)3 StorageTier (alluxio.worker.block.meta.StorageTier)3 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)2 StorageTierEvictorView (alluxio.worker.block.meta.StorageTierEvictorView)2 StorageTierView (alluxio.worker.block.meta.StorageTierView)2 ExpectedException (org.junit.rules.ExpectedException)2 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 DefaultStorageTier (alluxio.worker.block.meta.DefaultStorageTier)1 StorageDirView (alluxio.worker.block.meta.StorageDirView)1 ArrayList (java.util.ArrayList)1