Search in sources :

Example 21 with StorageDir

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

the class LRFUAnnotatorTest method testLRFU.

@Test
public void testLRFU() throws Exception {
    Random rand = new Random();
    List<Long> expectedList = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        StorageDir pickedDir = getDir(rand.nextInt(2), rand.nextInt(2));
        createBlock(i, pickedDir);
        for (int j = 0; j < i * 2 + 1; j++) {
            accessBlock(i);
        }
        expectedList.add(i);
    }
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
    Collections.reverse(expectedList);
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.REVERSE), expectedList.iterator());
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 22 with StorageDir

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

the class AlignTaskTest method testTierAlignment.

@Test
public void testTierAlignment() throws Exception {
    Random rnd = new Random();
    StorageDir[] dirArray = new StorageDir[] { mTestDir1, mTestDir2, mTestDir3, mTestDir4 };
    // Start simulating random load on worker.
    startSimulateLoad();
    // Fill each directory.
    long sessionIdCounter = 1000;
    long blockIdCounter = 1000;
    for (StorageDir dir : dirArray) {
        while (dir.getAvailableBytes() > 0) {
            TieredBlockStoreTestUtils.cache(sessionIdCounter++, blockIdCounter++, BLOCK_SIZE, mBlockStore, dir.toBlockStoreLocation(), false);
        }
    }
    // Access blocks randomly.
    for (int i = 0; i < 100; i++) {
        StorageDir dirToAccess = dirArray[rnd.nextInt(dirArray.length)];
        List<Long> blockIdList = dirToAccess.getBlockIds();
        if (!blockIdList.isEmpty()) {
            mBlockStore.accessBlock(sessionIdCounter++, blockIdList.get(rnd.nextInt(blockIdList.size())));
        }
    }
    // Validate tiers are not aligned. (It's not guaranteed but using LRU helps.)
    Assert.assertTrue(!mBlockIterator.aligned(BlockStoreLocation.anyDirInTier(FIRST_TIER_ALIAS), BlockStoreLocation.anyDirInTier(SECOND_TIER_ALIAS), BlockOrder.NATURAL, (b) -> false));
    // Stop the load for align task to continue.
    stopSimulateLoad();
    CommonUtils.waitFor("Tiers to be aligned by a background task.", () -> mBlockIterator.aligned(BlockStoreLocation.anyDirInTier(FIRST_TIER_ALIAS), BlockStoreLocation.anyDirInTier(SECOND_TIER_ALIAS), BlockOrder.NATURAL, (b) -> false), WaitForOptions.defaults().setTimeoutMs(60000));
}
Also used : BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) ServerConfiguration(alluxio.conf.ServerConfiguration) BlockOrder(alluxio.worker.block.annotator.BlockOrder) Test(org.junit.Test) Random(java.util.Random) PropertyKey(alluxio.conf.PropertyKey) TieredBlockStoreTestUtils(alluxio.worker.block.TieredBlockStoreTestUtils) WaitForOptions(alluxio.util.WaitForOptions) List(java.util.List) StorageDir(alluxio.worker.block.meta.StorageDir) Assert(org.junit.Assert) CommonUtils(alluxio.util.CommonUtils) Before(org.junit.Before) Random(java.util.Random) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 23 with StorageDir

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

the class EmulatingBlockIteratorTest method testLRUEmulation.

@Test
public void testLRUEmulation() throws Exception {
    // Block size that is common denominator to each dir capacity.
    final long blockSize = 1000;
    // Fill all directories and calculate expected block order for each of them as per LRU.
    Map<StorageDir, List<Long>> expectedListPerDir = new HashMap<>();
    long blockId = 0;
    for (StorageTier tier : mMetaManager.getTiers()) {
        for (StorageDir dir : tier.getStorageDirs()) {
            expectedListPerDir.put(dir, new LinkedList<>());
            while (dir.getAvailableBytes() > 0) {
                createBlock(++blockId, blockSize, dir);
                accessBlock(blockId);
                expectedListPerDir.get(dir).add(blockId);
            }
        }
    }
    // That's also why emulation can't be tested reliably with 'Reverse' iteration order.
    for (StorageDir dir : expectedListPerDir.keySet()) {
        validateIteratorHeader(mBlockIterator.getIterator(dir.toBlockStoreLocation(), BlockOrder.NATURAL), expectedListPerDir.get(dir).iterator());
    }
}
Also used : HashMap(java.util.HashMap) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with StorageDir

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

the class LRUAnnotatorTest method testLRU.

@Test
public void testLRU() throws Exception {
    Random rand = new Random();
    List<Long> expectedList = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        StorageDir pickedDir = getDir(rand.nextInt(2), rand.nextInt(2));
        createBlock(i, pickedDir);
        accessBlock(i);
        expectedList.add(i);
    }
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.NATURAL), expectedList.iterator());
    Collections.reverse(expectedList);
    validateIterator(mBlockIterator.getIterator(BlockStoreLocation.anyTier(), BlockOrder.REVERSE), expectedList.iterator());
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 25 with StorageDir

use of alluxio.worker.block.meta.StorageDir 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(Constants.MEDIUM_HDD).getDir(0);
    StorageDir dir2 = mMetaManager.getTier(Constants.MEDIUM_HDD).getDir(1);
    TempBlockMeta tempBlockMeta1 = new DefaultTempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir1);
    TempBlockMeta tempBlockMeta2 = new DefaultTempBlockMeta(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);
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) DefaultTempBlockMeta(alluxio.worker.block.meta.DefaultTempBlockMeta) 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