Search in sources :

Example 1 with TempBlockMeta

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

the class BlockMetadataManager method moveBlockMeta.

/**
   * Moves an existing block to another location currently hold by a temp block.
   *
   * @param blockMeta the metadata of the block to move
   * @param tempBlockMeta a placeholder in the destination directory
   * @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
   */
public BlockMeta moveBlockMeta(BlockMeta blockMeta, TempBlockMeta tempBlockMeta) throws BlockDoesNotExistException, WorkerOutOfSpaceException, BlockAlreadyExistsException {
    StorageDir srcDir = blockMeta.getParentDir();
    StorageDir dstDir = tempBlockMeta.getParentDir();
    srcDir.removeBlockMeta(blockMeta);
    BlockMeta newBlockMeta = new BlockMeta(blockMeta.getBlockId(), blockMeta.getBlockSize(), dstDir);
    dstDir.removeTempBlockMeta(tempBlockMeta);
    dstDir.addBlockMeta(newBlockMeta);
    return newBlockMeta;
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) AbstractBlockMeta(alluxio.worker.block.meta.AbstractBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 2 with TempBlockMeta

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

the class TieredBlockStore method createBlockMetaInternal.

/**
   * Creates a temp block meta only if allocator finds available space. This method will not trigger
   * any eviction.
   *
   * @param sessionId session Id
   * @param blockId block Id
   * @param location location to create the block
   * @param initialBlockSize initial block size in bytes
   * @param newBlock true if this temp block is created for a new block
   * @return a temp block created if successful, or null if allocation failed (instead of throwing
   *         {@link WorkerOutOfSpaceException} because allocation failure could be an expected case)
   * @throws BlockAlreadyExistsException if there is already a block with the same block id
   */
private TempBlockMeta createBlockMetaInternal(long sessionId, long blockId, BlockStoreLocation location, long initialBlockSize, boolean newBlock) throws BlockAlreadyExistsException {
    // block lock here since no sharing
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        if (newBlock) {
            checkTempBlockIdAvailable(blockId);
        }
        StorageDirView dirView = mAllocator.allocateBlockWithView(sessionId, initialBlockSize, location, getUpdatedView());
        if (dirView == null) {
            // Allocator fails to find a proper place for this new block.
            return null;
        }
        // TODO(carson): Add tempBlock to corresponding storageDir and remove the use of
        // StorageDirView.createTempBlockMeta.
        TempBlockMeta tempBlock = dirView.createTempBlockMeta(sessionId, blockId, initialBlockSize);
        try {
            // Add allocated temp block to metadata manager. This should never fail if allocator
            // correctly assigns a StorageDir.
            mMetaManager.addTempBlockMeta(tempBlock);
        } catch (WorkerOutOfSpaceException | BlockAlreadyExistsException e) {
            // If we reach here, allocator is not working properly
            LOG.error("Unexpected failure: {} bytes allocated at {} by allocator, " + "but addTempBlockMeta failed", initialBlockSize, location);
            throw Throwables.propagate(e);
        }
        return tempBlock;
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) LockResource(alluxio.resource.LockResource) StorageDirView(alluxio.worker.block.meta.StorageDirView) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException)

Example 3 with TempBlockMeta

use of alluxio.worker.block.meta.TempBlockMeta 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("HDD").getDir(0);
    StorageDir dir2 = mMetaManager.getTier("HDD").getDir(1);
    TempBlockMeta tempBlockMeta1 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir1);
    TempBlockMeta tempBlockMeta2 = new TempBlockMeta(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) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) Test(org.junit.Test)

Example 4 with TempBlockMeta

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

the class BlockMetadataManagerTest method resizeTempBlockMeta.

/**
   * Tests the {@link BlockMetadataManager#resizeTempBlockMeta(TempBlockMeta, long)} method.
   */
@Test
public void resizeTempBlockMeta() throws Exception {
    StorageDir dir = mMetaManager.getTier("MEM").getDir(0);
    TempBlockMeta tempBlockMeta = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir);
    mMetaManager.resizeTempBlockMeta(tempBlockMeta, TEST_BLOCK_SIZE + 1);
    Assert.assertEquals(TEST_BLOCK_SIZE + 1, tempBlockMeta.getBlockSize());
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) Test(org.junit.Test)

Example 5 with TempBlockMeta

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

the class TieredBlockStoreTest method createBlockMetaWithEviction.

/**
   * Tests the {@link TieredBlockStore#createBlock(long, long, BlockStoreLocation, long)} method
   * to work with eviction.
   */
@Test
public void createBlockMetaWithEviction() throws Exception {
    TieredBlockStoreTestUtils.cache(SESSION_ID1, BLOCK_ID1, BLOCK_SIZE, mTestDir1, mMetaManager, mEvictor);
    TempBlockMeta tempBlockMeta = mBlockStore.createBlock(SESSION_ID1, TEMP_BLOCK_ID, mTestDir1.toBlockStoreLocation(), mTestDir1.getCapacityBytes());
    // Expect BLOCK_ID1 evicted from mTestDir1
    Assert.assertFalse(mTestDir1.hasBlockMeta(BLOCK_ID1));
    Assert.assertFalse(FileUtils.exists(BlockMeta.commitPath(mTestDir1, BLOCK_ID1)));
    Assert.assertEquals(mTestDir1.getCapacityBytes(), tempBlockMeta.getBlockSize());
    Assert.assertEquals(mTestDir1, tempBlockMeta.getParentDir());
}
Also used : TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) Test(org.junit.Test)

Aggregations

TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)27 StorageDir (alluxio.worker.block.meta.StorageDir)14 Test (org.junit.Test)12 BlockMeta (alluxio.worker.block.meta.BlockMeta)11 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)6 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)5 LockResource (alluxio.resource.LockResource)5 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)4 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)3 AbstractBlockMeta (alluxio.worker.block.meta.AbstractBlockMeta)3 StorageDirView (alluxio.worker.block.meta.StorageDirView)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BlockWriter (alluxio.worker.block.io.BlockWriter)2 LocalFileBlockWriter (alluxio.worker.block.io.LocalFileBlockWriter)2 StorageTier (alluxio.worker.block.meta.StorageTier)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1