Search in sources :

Example 11 with StorageDirView

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

the class RoundRobinAllocator method getNextAvailDirInTier.

/**
 * Finds an available dir in a given tier for a block with blockSize.
 *
 * @param tierView the tier to find a dir
 * @param blockSize the requested block size
 * @param mediumType the medium type to find a dir
 * @return the index of the dir if non-negative; -1 if fail to find a dir
 */
private int getNextAvailDirInTier(StorageTierView tierView, long blockSize, String mediumType, boolean skipReview) {
    int dirIndex = mTierAliasToLastDirMap.get(tierView.getTierViewAlias());
    List<StorageDirView> dirs = tierView.getDirViews();
    for (int i = 0; i < dirs.size(); i++) {
        // try this many times
        dirIndex = (dirIndex + 1) % dirs.size();
        StorageDirView dir = dirs.get(dirIndex);
        if ((mediumType.equals(BlockStoreLocation.ANY_MEDIUM) || dir.getMediumType().equals(mediumType)) && dir.getAvailableBytes() >= blockSize) {
            if (skipReview || mReviewer.acceptAllocation(dir)) {
                return dir.getDirViewIndex();
            }
            // The allocation is rejected. Try the next dir.
            LOG.debug("Allocation to dirIndex {} rejected: {}", dirIndex, dir.toBlockStoreLocation());
        }
    }
    return -1;
}
Also used : StorageDirView(alluxio.worker.block.meta.StorageDirView)

Example 12 with StorageDirView

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

the class BlockMetadataViewTest method assertSameTierView.

/**
 * Assert if two TierViews are the same by comparing their contents.
 */
private void assertSameTierView(StorageTierEvictorView tierView1, StorageTierEvictorView tierView2) {
    assertEquals(tierView1.getTierViewAlias(), tierView2.getTierViewAlias());
    assertEquals(tierView1.getTierViewOrdinal(), tierView2.getTierViewOrdinal());
    List<StorageDirView> dirViews1 = tierView1.getDirViews();
    List<StorageDirView> dirViews2 = tierView2.getDirViews();
    assertEquals(dirViews1.size(), dirViews2.size());
    for (int i = 0; i < dirViews1.size(); i++) {
        StorageDirEvictorView dirView1 = (StorageDirEvictorView) dirViews1.get(i);
        StorageDirEvictorView dirView2 = (StorageDirEvictorView) dirViews2.get(i);
        assertEquals(dirView1.getAvailableBytes(), dirView2.getAvailableBytes());
        assertEquals(dirView1.getCapacityBytes(), dirView2.getCapacityBytes());
        assertEquals(dirView1.getCommittedBytes(), dirView2.getCommittedBytes());
        assertEquals(dirView1.getDirViewIndex(), dirView2.getDirViewIndex());
        assertEquals(dirView1.getEvictableBlocks(), dirView2.getEvictableBlocks());
        assertEquals(dirView1.getEvitableBytes(), dirView2.getEvitableBytes());
    }
}
Also used : StorageDirEvictorView(alluxio.worker.block.meta.StorageDirEvictorView) StorageDirView(alluxio.worker.block.meta.StorageDirView)

Example 13 with StorageDirView

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

the class AllocatorTestBase method assertAllocationAnyDirInAnyTierWithMedium.

/**
 * For each medium, test if anyDirInAnyTierWithMedium gives a dir with the target medium.
 */
protected void assertAllocationAnyDirInAnyTierWithMedium() throws Exception {
    for (String medium : MEDIA_TYPES) {
        BlockStoreLocation loc = BlockStoreLocation.anyDirInAnyTierWithMedium(medium);
        StorageDirView dirView = mAllocator.allocateBlockWithView(AllocatorTestBase.SESSION_ID, 1, loc, getMetadataEvictorView(), true);
        assertNotNull(dirView);
        assertEquals(medium, dirView.getMediumType());
    }
}
Also used : StorageDirView(alluxio.worker.block.meta.StorageDirView) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 14 with StorageDirView

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

the class AllocatorTestBase method assertAllocationAnyDirInTier.

/**
 * For each tier, test if anyDirInTier location gives a dir in the target tier.
 */
protected void assertAllocationAnyDirInTier() throws Exception {
    BlockStoreLocation[] locations = new BlockStoreLocation[] { mAnyDirInTierLoc1, mAnyDirInTierLoc2, mAnyDirInTierLoc3 };
    for (int i = 0; i < locations.length; i++) {
        StorageDirView dirView = mAllocator.allocateBlockWithView(AllocatorTestBase.SESSION_ID, 1, locations[i], getMetadataEvictorView(), true);
        assertNotNull(dirView);
        assertEquals(TIER_ALIAS[i], dirView.getParentTierView().getTierViewAlias());
    }
}
Also used : StorageDirView(alluxio.worker.block.meta.StorageDirView) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 15 with StorageDirView

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

the class ProbabilisticBufferReviewerTest method testProbabilityFunction.

@Test
public void testProbabilityFunction() throws Exception {
    // Empty - 100%
    StorageDirView mockEmptyDir = mock(StorageDirView.class);
    when(mockEmptyDir.getAvailableBytes()).thenReturn(DISK_SIZE);
    when(mockEmptyDir.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probEmptyDir = mReviewer.getProbability(mockEmptyDir);
    assertEquals(1.0, probEmptyDir, 1e-6);
    // Higher than soft limit - 100%
    StorageDirView mockMoreThanSoft = mock(StorageDirView.class);
    when(mockMoreThanSoft.getAvailableBytes()).thenReturn(SOFT_LIMIT_BYTES + 1);
    when(mockMoreThanSoft.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probMoreThanSoft = mReviewer.getProbability(mockMoreThanSoft);
    assertEquals(1.0, probMoreThanSoft, 1e-6);
    // Lower than soft limit - less than 100%
    StorageDirView mockLessThanSoft = mock(StorageDirView.class);
    when(mockLessThanSoft.getAvailableBytes()).thenReturn(SOFT_LIMIT_BYTES - 1);
    when(mockLessThanSoft.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probLessThanSoft = mReviewer.getProbability(mockLessThanSoft);
    assertEquals(0.99999999, probLessThanSoft, 1e-4);
    // Between soft limit and hard limit - linear
    StorageDirView mockMoreThanHard = mock(StorageDirView.class);
    when(mockMoreThanHard.getAvailableBytes()).thenReturn(FormatUtils.parseSpaceSize("128MB"));
    when(mockMoreThanHard.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probMoreThanHard = mReviewer.getProbability(mockMoreThanHard);
    assertEquals(1.0 / 3, probMoreThanHard, 1e-6);
    // Hard limit reached - 0.0
    StorageDirView mockHardLimit = mock(StorageDirView.class);
    when(mockHardLimit.getAvailableBytes()).thenReturn(HARD_LIMIT_BYTES);
    when(mockHardLimit.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probHardLimit = mReviewer.getProbability(mockHardLimit);
    assertEquals(0.0, probHardLimit, 1e-6);
    // Below hard limit - 0.0
    StorageDirView mockLessThanHard = mock(StorageDirView.class);
    when(mockLessThanHard.getAvailableBytes()).thenReturn(HARD_LIMIT_BYTES - 1);
    when(mockLessThanHard.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probLessThanHard = mReviewer.getProbability(mockLessThanHard);
    assertEquals(0.0, probLessThanHard, 1e-6);
    // Full - 0.0
    StorageDirView mockFull = mock(StorageDirView.class);
    when(mockFull.getAvailableBytes()).thenReturn(0L);
    when(mockFull.getCapacityBytes()).thenReturn(DISK_SIZE);
    double probFull = mReviewer.getProbability(mockFull);
    assertEquals(0.0, probFull, 1e-6);
}
Also used : StorageDirView(alluxio.worker.block.meta.StorageDirView) Test(org.junit.Test)

Aggregations

StorageDirView (alluxio.worker.block.meta.StorageDirView)33 StorageTierView (alluxio.worker.block.meta.StorageTierView)15 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)6 BlockMeta (alluxio.worker.block.meta.BlockMeta)6 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)6 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)5 Pair (alluxio.collections.Pair)4 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)4 LockResource (alluxio.resource.LockResource)3 StorageDirEvictorView (alluxio.worker.block.meta.StorageDirEvictorView)3 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)2 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)2 LinkedList (java.util.LinkedList)2 StorageTierAssoc (alluxio.StorageTierAssoc)1 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)1 DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)1 StorageDir (alluxio.worker.block.meta.StorageDir)1 StorageTier (alluxio.worker.block.meta.StorageTier)1