Search in sources :

Example 6 with DefaultBlockMeta

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

the class BlockMetadataManager method swapBlocks.

/**
 * Swaps location of two blocks in metadata.
 *
 * @param blockMeta1 the first block meta
 * @param blockMeta2 the second block meta
 * @throws BlockDoesNotExistException
 * @throws BlockAlreadyExistsException
 * @throws WorkerOutOfSpaceException
 */
public void swapBlocks(BlockMeta blockMeta1, BlockMeta blockMeta2) throws BlockDoesNotExistException, BlockAlreadyExistsException, WorkerOutOfSpaceException {
    StorageDir blockDir1 = blockMeta1.getParentDir();
    StorageDir blockDir2 = blockMeta2.getParentDir();
    // Remove existing metas from dirs.
    blockDir1.removeBlockMeta(blockMeta1);
    blockDir2.removeBlockMeta(blockMeta2);
    // Add new block metas with new block id and sizes.
    blockDir1.addBlockMeta(new DefaultBlockMeta(blockMeta2.getBlockId(), blockMeta2.getBlockSize(), blockDir1));
    blockDir2.addBlockMeta(new DefaultBlockMeta(blockMeta1.getBlockId(), blockMeta1.getBlockSize(), blockDir2));
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir)

Example 7 with DefaultBlockMeta

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

the class BlockMetadataManager method commitTempBlockMeta.

/**
 * Commits a temp block.
 *
 * @param tempBlockMeta the metadata of the temp block to commit
 * @throws WorkerOutOfSpaceException when no more space left to hold the block
 * @throws BlockAlreadyExistsException when the block already exists in committed blocks
 * @throws BlockDoesNotExistException when temp block can not be found
 */
public void commitTempBlockMeta(TempBlockMeta tempBlockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException, BlockDoesNotExistException {
    long blockId = tempBlockMeta.getBlockId();
    if (hasBlockMeta(blockId)) {
        BlockMeta blockMeta = getBlockMeta(blockId);
        throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK.getMessage(blockId, blockMeta.getBlockLocation().tierAlias()));
    }
    BlockMeta block = new DefaultBlockMeta(Preconditions.checkNotNull(tempBlockMeta));
    StorageDir dir = tempBlockMeta.getParentDir();
    dir.removeTempBlockMeta(tempBlockMeta);
    dir.addBlockMeta(block);
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageDir(alluxio.worker.block.meta.StorageDir) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 8 with DefaultBlockMeta

use of alluxio.worker.block.meta.DefaultBlockMeta 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 != null && 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 DefaultBlockMeta(blockMeta.getBlockId(), blockSize, newDir);
    newDir.addBlockMeta(newBlockMeta);
    return newBlockMeta;
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) DefaultStorageTier(alluxio.worker.block.meta.DefaultStorageTier) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) BlockMeta(alluxio.worker.block.meta.BlockMeta) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 9 with DefaultBlockMeta

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

the class BlockMetadataManagerTest method cleanupSession.

/**
 * Tests the {@link BlockMetadataManager#cleanupSessionTempBlocks(long, List)} method.
 */
@Test
public void cleanupSession() throws Exception {
    StorageDir dir = mMetaManager.getTier(Constants.MEDIUM_MEM).getDir(0);
    final long tempBlockId1 = 1;
    final long tempBlockId2 = 2;
    final long tempBlockId3 = 3;
    final long sessionId1 = 100;
    final long sessionId2 = 200;
    TempBlockMeta tempBlockMeta1 = new DefaultTempBlockMeta(sessionId1, tempBlockId1, TEST_BLOCK_SIZE, dir);
    TempBlockMeta tempBlockMeta2 = new DefaultTempBlockMeta(sessionId1, tempBlockId2, TEST_BLOCK_SIZE, dir);
    TempBlockMeta tempBlockMeta3 = new DefaultTempBlockMeta(sessionId2, tempBlockId3, TEST_BLOCK_SIZE, dir);
    BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
    dir.addTempBlockMeta(tempBlockMeta1);
    dir.addTempBlockMeta(tempBlockMeta2);
    dir.addTempBlockMeta(tempBlockMeta3);
    dir.addBlockMeta(blockMeta);
    // Get temp blocks for sessionId1, expect to get tempBlock1 and tempBlock2
    List<TempBlockMeta> toRemove = mMetaManager.getSessionTempBlocks(sessionId1);
    List<Long> toRemoveBlockIds = new ArrayList<>(toRemove.size());
    for (TempBlockMeta tempBlockMeta : toRemove) {
        toRemoveBlockIds.add(tempBlockMeta.getBlockId());
    }
    assertEquals(Sets.newHashSet(tempBlockMeta1, tempBlockMeta2), new HashSet<>(toRemove));
    assertTrue(dir.hasTempBlockMeta(tempBlockId1));
    assertTrue(dir.hasTempBlockMeta(tempBlockId2));
    // Clean up sessionId1, expect tempBlock1 and tempBlock2 to be removed.
    mMetaManager.cleanupSessionTempBlocks(sessionId1, toRemoveBlockIds);
    assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    assertTrue(dir.hasBlockMeta(TEST_BLOCK_ID));
    // Get temp blocks for sessionId1 again, expect to get nothing
    toRemove = mMetaManager.getSessionTempBlocks(sessionId1);
    toRemoveBlockIds = new ArrayList<>(toRemove.size());
    for (TempBlockMeta tempBlockMeta : toRemove) {
        toRemoveBlockIds.add(tempBlockMeta.getBlockId());
    }
    assertTrue(toRemove.isEmpty());
    // Clean up sessionId1 again, expect nothing to happen
    mMetaManager.cleanupSessionTempBlocks(sessionId1, toRemoveBlockIds);
    assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    assertTrue(dir.hasBlockMeta(TEST_BLOCK_ID));
    // Get temp blocks for sessionId2, expect to get tempBlock3
    toRemove = mMetaManager.getSessionTempBlocks(sessionId2);
    toRemoveBlockIds = new ArrayList<>(toRemove.size());
    for (TempBlockMeta tempBlockMeta : toRemove) {
        toRemoveBlockIds.add(tempBlockMeta.getBlockId());
    }
    assertEquals(Sets.newHashSet(tempBlockMeta3), new HashSet<>(toRemove));
    assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    // Clean up sessionId2, expect tempBlock3 to be removed
    mMetaManager.cleanupSessionTempBlocks(sessionId2, toRemoveBlockIds);
    assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    assertFalse(dir.hasTempBlockMeta(tempBlockId3));
    assertTrue(dir.hasBlockMeta(TEST_BLOCK_ID));
}
Also used : DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) ArrayList(java.util.ArrayList) 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)

Example 10 with DefaultBlockMeta

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

the class BlockMetadataViewTest method sameTierViewsBelow.

/**
 * Tests that {@link BlockMetadataEvictorView#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 = mMetadataView.getTierViewsBelow(tierAlias);
    // Do some operations on metadata
    StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL + 1).getDir(TEST_DIR);
    BlockMeta blockMeta = new DefaultBlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
    try {
        dir.addBlockMeta(blockMeta);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<StorageTier> tiers2 = mMetaManager.getTiersBelow(tierAlias);
    assertEquals(tierViews1.size(), tiers2.size());
    for (int i = 0; i < tierViews1.size(); i++) {
        assertSameTierView((StorageTierEvictorView) tierViews1.get(i), new StorageTierEvictorView(tiers2.get(i), mMetadataView));
    }
}
Also used : StorageTierEvictorView(alluxio.worker.block.meta.StorageTierEvictorView) DefaultBlockMeta(alluxio.worker.block.meta.DefaultBlockMeta) StorageTier(alluxio.worker.block.meta.StorageTier) 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)

Aggregations

DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)11 StorageDir (alluxio.worker.block.meta.StorageDir)11 BlockMeta (alluxio.worker.block.meta.BlockMeta)9 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)7 Test (org.junit.Test)6 DefaultTempBlockMeta (alluxio.worker.block.meta.DefaultTempBlockMeta)3 StorageTier (alluxio.worker.block.meta.StorageTier)3 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)2 StorageTierEvictorView (alluxio.worker.block.meta.StorageTierEvictorView)2 StorageTierView (alluxio.worker.block.meta.StorageTierView)2 ExpectedException (org.junit.rules.ExpectedException)2 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 DefaultStorageTier (alluxio.worker.block.meta.DefaultStorageTier)1 StorageDirView (alluxio.worker.block.meta.StorageDirView)1 ArrayList (java.util.ArrayList)1