Search in sources :

Example 36 with StorageDir

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

the class EvictorTestUtils method blocksInTheSameDir.

/**
   * Whether blocks in the {@link EvictionPlan} are in the same {@link StorageDir}.
   *
   * @param plan the eviction plan
   * @param meta the metadata manager
   * @return true if blocks are in the same dir otherwise false
   * @throws BlockDoesNotExistException if fail to get metadata of a block
   */
public static boolean blocksInTheSameDir(EvictionPlan plan, BlockMetadataManager meta) throws BlockDoesNotExistException {
    Preconditions.checkNotNull(plan);
    StorageDir dir = null;
    List<Long> blockIds = new ArrayList<>();
    for (Pair<Long, BlockStoreLocation> evict : plan.toEvict()) {
        blockIds.add(evict.getFirst());
    }
    for (BlockTransferInfo move : plan.toMove()) {
        blockIds.add(move.getBlockId());
    }
    for (long blockId : blockIds) {
        StorageDir blockDir = meta.getBlockMeta(blockId).getParentDir();
        if (dir == null) {
            dir = blockDir;
        } else if (dir != blockDir) {
            return false;
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 37 with StorageDir

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

Example 38 with StorageDir

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

the class TieredBlockStoreTest method relaxLocationWrites.

@Test
public void relaxLocationWrites() throws Exception {
    long totalCapacityBytes = 0;
    for (StorageDir dir : new StorageDir[] { mTestDir1, mTestDir2, mTestDir3, mTestDir4 }) {
        totalCapacityBytes += dir.getCapacityBytes();
    }
    long fileSizeBytes = 1000;
    int maxFileCount = (int) (totalCapacityBytes / fileSizeBytes);
    // Write to first dir, 2 times of the whole store's peak capacity.
    for (int i = 0; i <= maxFileCount * 2; i++) {
        TieredBlockStoreTestUtils.cache(i, i, fileSizeBytes, mBlockStore, mTestDir1.toBlockStoreLocation(), false);
    }
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 39 with StorageDir

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

the class AbstractBlockAnnotatorTest method testRemovedBlock.

// Common tests for {@link EvictionOrderProvider} implementations.
@Test
public void testRemovedBlock() throws Exception {
    StorageDir dir = getDir(0, 0);
    createBlock(0, dir);
    List<Long> expectedList = new ArrayList<Long>() {

        {
            add(0L);
        }
    };
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
    removeBlock(0);
    expectedList.clear();
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
}
Also used : ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 40 with StorageDir

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

the class AbstractBlockAnnotatorTest method testMovedBlock.

@Test
public void testMovedBlock() throws Exception {
    StorageDir srcDir = getDir(0, 0);
    StorageDir dstDir = getDir(0, 1);
    createBlock(0, srcDir);
    List<Long> expectedList = new ArrayList<Long>() {

        {
            add(0L);
        }
    };
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
    moveBlock(0, dstDir);
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
}
Also used : ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

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