Search in sources :

Example 6 with TempBlockMeta

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

the class BlockWorkerTest method createBlockLowerTier.

/**
   * Tests the {@link BlockWorker#createBlock(long, long, String, long)} method with a tier
   * other than MEM.
   */
@Test
public void createBlockLowerTier() throws Exception {
    long blockId = mRandom.nextLong();
    long initialBytes = mRandom.nextLong();
    long sessionId = mRandom.nextLong();
    String tierAlias = "HDD";
    BlockStoreLocation location = BlockStoreLocation.anyDirInTier(tierAlias);
    StorageDir storageDir = Mockito.mock(StorageDir.class);
    TempBlockMeta meta = new TempBlockMeta(sessionId, blockId, initialBytes, storageDir);
    when(mBlockStore.createBlock(sessionId, blockId, location, initialBytes)).thenReturn(meta);
    when(storageDir.getDirPath()).thenReturn("/tmp");
    assertEquals(PathUtils.concatPath("/tmp", ".tmp_blocks", sessionId % 1024, String.format("%x-%x", sessionId, blockId)), mBlockWorker.createBlock(sessionId, blockId, tierAlias, initialBytes));
}
Also used : StorageDir(alluxio.worker.block.meta.StorageDir) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TempBlockMeta

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

the class DefaultBlockWorker method createBlock.

@Override
public String createBlock(long sessionId, long blockId, String tierAlias, long initialBytes) throws BlockAlreadyExistsException, WorkerOutOfSpaceException, IOException {
    BlockStoreLocation loc = BlockStoreLocation.anyDirInTier(tierAlias);
    TempBlockMeta createdBlock = mBlockStore.createBlock(sessionId, blockId, loc, initialBytes);
    return createdBlock.getPath();
}
Also used : TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 8 with TempBlockMeta

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

the class TieredBlockStore method cleanupSession.

@Override
public void cleanupSession(long sessionId) {
    // Release all locks the session is holding.
    mLockManager.cleanupSession(sessionId);
    // Collect a list of temp blocks the given session owns and abort all of them with best effort
    List<TempBlockMeta> tempBlocksToRemove;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        tempBlocksToRemove = mMetaManager.getSessionTempBlocks(sessionId);
    }
    for (TempBlockMeta tempBlockMeta : tempBlocksToRemove) {
        try {
            LOG.warn("Clean up expired temporary block {} from session {}.", tempBlockMeta.getBlockId(), sessionId);
            abortBlockInternal(sessionId, tempBlockMeta.getBlockId());
        } catch (Exception e) {
            LOG.error("Failed to cleanup tempBlock {} due to {}", tempBlockMeta.getBlockId(), e.getMessage());
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Example 9 with TempBlockMeta

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

the class TieredBlockStore method checkTempBlockOwnedBySession.

/**
   * Checks if block id is a temporary block and owned by session id. This method must be enclosed
   * by {@link #mMetadataLock}.
   *
   * @param sessionId the id of session
   * @param blockId the id of block
   * @throws BlockDoesNotExistException if block id can not be found in temporary blocks
   * @throws BlockAlreadyExistsException if block id already exists in committed blocks
   * @throws InvalidWorkerStateException if block id is not owned by session id
   */
private void checkTempBlockOwnedBySession(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException {
    if (mMetaManager.hasBlockMeta(blockId)) {
        throw new BlockAlreadyExistsException(ExceptionMessage.TEMP_BLOCK_ID_COMMITTED, blockId);
    }
    TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
    long ownerSessionId = tempBlockMeta.getSessionId();
    if (ownerSessionId != sessionId) {
        throw new InvalidWorkerStateException(ExceptionMessage.BLOCK_ID_FOR_DIFFERENT_SESSION, blockId, ownerSessionId, sessionId);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

Example 10 with TempBlockMeta

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

the class TieredBlockStore method commitBlockInternal.

/**
   * Commits a temp block.
   *
   * @param sessionId the id of session
   * @param blockId the id of block
   * @return destination location to move the block
   * @throws BlockDoesNotExistException if block id can not be found in temporary blocks
   * @throws BlockAlreadyExistsException if block id already exists in committed blocks
   * @throws InvalidWorkerStateException if block id is not owned by session id
   * @throws IOException if I/O errors occur when deleting the block file
   */
private BlockStoreLocation commitBlockInternal(long sessionId, long blockId) throws BlockAlreadyExistsException, InvalidWorkerStateException, BlockDoesNotExistException, IOException {
    long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.WRITE);
    try {
        // When committing TempBlockMeta, the final BlockMeta calculates the block size according to
        // the actual file size of this TempBlockMeta. Therefore, commitTempBlockMeta must happen
        // after moving actual block file to its committed path.
        BlockStoreLocation loc;
        String srcPath;
        String dstPath;
        TempBlockMeta tempBlockMeta;
        try (LockResource r = new LockResource(mMetadataReadLock)) {
            checkTempBlockOwnedBySession(sessionId, blockId);
            tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
            srcPath = tempBlockMeta.getPath();
            dstPath = tempBlockMeta.getCommitPath();
            loc = tempBlockMeta.getBlockLocation();
        }
        // Heavy IO is guarded by block lock but not metadata lock. This may throw IOException.
        FileUtils.move(srcPath, dstPath);
        try (LockResource r = new LockResource(mMetadataWriteLock)) {
            mMetaManager.commitTempBlockMeta(tempBlockMeta);
        } catch (BlockAlreadyExistsException | BlockDoesNotExistException | WorkerOutOfSpaceException e) {
            // we shall never reach here
            throw Throwables.propagate(e);
        }
        return loc;
    } finally {
        mLockManager.unlockBlock(lockId);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) LockResource(alluxio.resource.LockResource) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException)

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