Search in sources :

Example 16 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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 17 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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 18 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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 19 with StorageDir

use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.

the class BlockStoreMetaTest method getUsedBytesOnDirs.

/**
 * Tests the {@link BlockStoreMeta#getUsedBytesOnDirs()} method.
 */
@Test
public void getUsedBytesOnDirs() {
    Map<Pair<String, String>, Long> dirsToUsedBytes = new HashMap<>();
    for (StorageTier tier : mMetadataManager.getTiers()) {
        for (StorageDir dir : tier.getStorageDirs()) {
            dirsToUsedBytes.put(new Pair<>(tier.getTierAlias(), dir.getDirPath()), dir.getCapacityBytes() - dir.getAvailableBytes());
        }
    }
    Assert.assertEquals(dirsToUsedBytes, mBlockStoreMeta.getUsedBytesOnDirs());
}
Also used : HashMap(java.util.HashMap) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Pair(alluxio.collections.Pair) Test(org.junit.Test)

Example 20 with StorageDir

use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.

the class TieredBlockStoreTestUtils method cache.

/**
 * Caches bytes into {@link StorageDir}.
 *
 * @param sessionId session who caches the data
 * @param blockId id of the cached block
 * @param bytes size of the block in bytes
 * @param tierLevel tier level of the {@link StorageDir} the block resides in
 * @param dirIndex index of directory in the tierLevel the block resides in
 * @param meta the metadata manager to update meta of the block
 * @param evictor the evictor to be informed of the new block
 */
public static void cache(long sessionId, long blockId, long bytes, int tierLevel, int dirIndex, BlockMetadataManager meta, Evictor evictor) throws Exception {
    StorageDir dir = meta.getTiers().get(tierLevel).getDir(dirIndex);
    cache(sessionId, blockId, bytes, dir, meta, evictor);
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir)

Aggregations

StorageDir (alluxio.worker.block.meta.StorageDir)55 Test (org.junit.Test)38 BlockMeta (alluxio.worker.block.meta.BlockMeta)18 StorageTier (alluxio.worker.block.meta.StorageTier)16 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)16 DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)15 DefaultTempBlockMeta (alluxio.worker.block.meta.DefaultTempBlockMeta)8 ArrayList (java.util.ArrayList)8 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)6 HashMap (java.util.HashMap)5 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)4 StorageTierView (alluxio.worker.block.meta.StorageTierView)4 List (java.util.List)4 Random (java.util.Random)4 ExpectedException (org.junit.rules.ExpectedException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Pair (alluxio.collections.Pair)3 Before (org.junit.Before)3 PropertyKey (alluxio.conf.PropertyKey)2 ServerConfiguration (alluxio.conf.ServerConfiguration)2