Search in sources :

Example 6 with StorageTier

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

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

the class BlockMetadataManager method moveBlockMeta.

/**
   * Moves the metadata of an existing block to another location or throws IOExceptions. Throws an
   * {@link IllegalArgumentException} if the newLocation is not in the tiered storage.
   *
   * @param blockMeta the metadata of the block to move
   * @param newLocation new location of the block
   * @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
   * @deprecated As of version 0.8. Use {@link #moveBlockMeta(BlockMeta, TempBlockMeta)} instead.
   */
@Deprecated
public BlockMeta moveBlockMeta(BlockMeta blockMeta, BlockStoreLocation newLocation) throws BlockDoesNotExistException, BlockAlreadyExistsException, WorkerOutOfSpaceException {
    // If existing location belongs to the target location, simply return the current block meta.
    BlockStoreLocation oldLocation = blockMeta.getBlockLocation();
    if (oldLocation.belongsTo(newLocation)) {
        LOG.info("moveBlockMeta: moving {} to {} is a noop", oldLocation, newLocation);
        return blockMeta;
    }
    long blockSize = blockMeta.getBlockSize();
    String newTierAlias = newLocation.tierAlias();
    StorageTier newTier = getTier(newTierAlias);
    StorageDir newDir = null;
    if (newLocation.equals(BlockStoreLocation.anyDirInTier(newTierAlias))) {
        for (StorageDir dir : newTier.getStorageDirs()) {
            if (dir.getAvailableBytes() >= blockSize) {
                newDir = dir;
                break;
            }
        }
    } else {
        StorageDir dir = newTier.getDir(newLocation.dir());
        if (dir.getAvailableBytes() >= blockSize) {
            newDir = dir;
        }
    }
    if (newDir == null) {
        throw new WorkerOutOfSpaceException("Failed to move BlockMeta: newLocation " + newLocation + " does not have enough space for " + blockSize + " bytes");
    }
    StorageDir oldDir = blockMeta.getParentDir();
    oldDir.removeBlockMeta(blockMeta);
    BlockMeta newBlockMeta = new BlockMeta(blockMeta.getBlockId(), blockSize, newDir);
    newDir.addBlockMeta(newBlockMeta);
    return newBlockMeta;
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) AbstractBlockMeta(alluxio.worker.block.meta.AbstractBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 8 with StorageTier

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

the class BlockMetadataManagerViewTest method getAvailableBytes.

/**
   * Tests the {@link BlockMetadataManagerView#getAvailableBytes(BlockStoreLocation)} method.
   */
@Test
public void getAvailableBytes() {
    BlockStoreLocation location;
    // When location represents anyTier
    location = BlockStoreLocation.anyTier();
    Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
    // When location represents one particular tier
    for (StorageTier tier : mMetaManager.getTiers()) {
        String tierAlias = tier.getTierAlias();
        location = BlockStoreLocation.anyDirInTier(tierAlias);
        Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
        for (StorageDir dir : tier.getStorageDirs()) {
            // When location represents one particular dir
            location = dir.toBlockStoreLocation();
            Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
        }
    }
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Test(org.junit.Test)

Example 9 with StorageTier

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

the class BlockMetadataManagerViewTest method sameTierViewsBelow.

/**
   * Tests that {@link BlockMetadataManagerView#getTierViewsBelow(String)} returns the same
   * TierViews as constructing by {@link BlockMetadataManager#getTiersBelow(String)}.
   */
@Test
public void sameTierViewsBelow() {
    String tierAlias = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getTierAlias();
    List<StorageTierView> tierViews1 = mMetaManagerView.getTierViewsBelow(tierAlias);
    // Do some operations on metadata
    StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL + 1).getDir(TEST_DIR);
    BlockMeta blockMeta = new BlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
    try {
        dir.addBlockMeta(blockMeta);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<StorageTier> tiers2 = mMetaManager.getTiersBelow(tierAlias);
    Assert.assertEquals(tierViews1.size(), tiers2.size());
    for (int i = 0; i < tierViews1.size(); i++) {
        assertSameTierView(tierViews1.get(i), new StorageTierView(tiers2.get(i), mMetaManagerView));
    }
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageTierView(alluxio.worker.block.meta.StorageTierView) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 10 with StorageTier

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

the class BlockMetadataManagerViewTest method getTierView.

/**
   * Tests the {@link BlockMetadataManagerView#getTierView(String)} method.
   */
@Test
public void getTierView() {
    for (StorageTier tier : mMetaManager.getTiers()) {
        String tierAlias = tier.getTierAlias();
        StorageTierView tierView = mMetaManagerView.getTierView(tierAlias);
        Assert.assertEquals(tier.getTierAlias(), tierView.getTierViewAlias());
        Assert.assertEquals(tier.getTierOrdinal(), tierView.getTierViewOrdinal());
    }
}
Also used : StorageTier(alluxio.worker.block.meta.StorageTier) StorageTierView(alluxio.worker.block.meta.StorageTierView) Test(org.junit.Test)

Aggregations

StorageTier (alluxio.worker.block.meta.StorageTier)14 StorageDir (alluxio.worker.block.meta.StorageDir)11 Test (org.junit.Test)11 BlockMeta (alluxio.worker.block.meta.BlockMeta)3 HashMap (java.util.HashMap)3 Pair (alluxio.collections.Pair)2 StorageTierView (alluxio.worker.block.meta.StorageTierView)2 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)2 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 AbstractBlockMeta (alluxio.worker.block.meta.AbstractBlockMeta)1 StorageDirView (alluxio.worker.block.meta.StorageDirView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExpectedException (org.junit.rules.ExpectedException)1