Search in sources :

Example 21 with TempBlockMeta

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

the class BlockWorkerTest method createBlock.

/**
   * Tests the {@link BlockWorker#createBlock(long, long, String, long)} method.
   */
@Test
public void createBlock() throws Exception {
    long blockId = mRandom.nextLong();
    long initialBytes = mRandom.nextLong();
    long sessionId = mRandom.nextLong();
    String tierAlias = "MEM";
    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 22 with TempBlockMeta

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

the class TieredBlockStoreTest method createBlockMetaWithoutEviction.

/**
   * Tests the {@link TieredBlockStore#createBlock(long, long, BlockStoreLocation, long)} method
   * to work without eviction.
   */
@Test
public void createBlockMetaWithoutEviction() throws Exception {
    TempBlockMeta tempBlockMeta = mBlockStore.createBlock(SESSION_ID1, TEMP_BLOCK_ID, mTestDir1.toBlockStoreLocation(), 1);
    Assert.assertEquals(1, tempBlockMeta.getBlockSize());
    Assert.assertEquals(mTestDir1, tempBlockMeta.getParentDir());
}
Also used : TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) Test(org.junit.Test)

Example 23 with TempBlockMeta

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

the class TieredBlockStoreTestUtils method cache.

/**
   * Caches bytes into {@link BlockStore} at specific location.
   *
   * @param sessionId session who caches the data
   * @param blockId id of the cached block
   * @param bytes size of the block in bytes
   * @param blockStore block store that the block is written into
   * @param location the location where the block resides
   * @throws Exception when fail to cache
   */
public static void cache(long sessionId, long blockId, long bytes, BlockStore blockStore, BlockStoreLocation location) throws Exception {
    TempBlockMeta tempBlockMeta = blockStore.createBlock(sessionId, blockId, location, bytes);
    // write data
    FileUtils.createFile(tempBlockMeta.getPath());
    BlockWriter writer = new LocalFileBlockWriter(tempBlockMeta.getPath());
    writer.append(BufferUtils.getIncreasingByteBuffer(Ints.checkedCast(bytes)));
    writer.close();
    // commit block
    blockStore.commitBlock(sessionId, blockId);
}
Also used : LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) BlockWriter(alluxio.worker.block.io.BlockWriter) LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 24 with TempBlockMeta

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

the class TieredBlockStoreTestUtils method cache.

/**
   * Caches bytes into {@link StorageDir}.
   *
   * @param sessionId session who caches the data
   * @param blockId id of the cached block
   * @param bytes size of the block in bytes
   * @param dir the {@link StorageDir} the block resides in
   * @param meta the metadata manager to update meta of the block
   * @param evictor the evictor to be informed of the new block
   * @throws Exception when fail to cache
   */
public static void cache(long sessionId, long blockId, long bytes, StorageDir dir, BlockMetadataManager meta, Evictor evictor) throws Exception {
    TempBlockMeta tempBlockMeta = createTempBlock(sessionId, blockId, bytes, dir);
    // commit block
    FileUtils.move(tempBlockMeta.getPath(), tempBlockMeta.getCommitPath());
    meta.commitTempBlockMeta(tempBlockMeta);
    // update evictor
    if (evictor instanceof BlockStoreEventListener) {
        ((BlockStoreEventListener) evictor).onCommitBlock(sessionId, blockId, dir.toBlockStoreLocation());
    }
}
Also used : TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 25 with TempBlockMeta

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

the class TieredBlockStoreTestUtils method createTempBlock.

/**
   * Makes a temp block of a given size in {@link StorageDir}.
   *
   * @param sessionId session who caches the data
   * @param blockId id of the cached block
   * @param bytes size of the block in bytes
   * @param dir the {@link StorageDir} the block resides in
   * @return the temp block meta
   * @throws Exception when fail to create this block
   */
public static TempBlockMeta createTempBlock(long sessionId, long blockId, long bytes, StorageDir dir) throws Exception {
    // prepare temp block
    TempBlockMeta tempBlockMeta = new TempBlockMeta(sessionId, blockId, bytes, dir);
    dir.addTempBlockMeta(tempBlockMeta);
    // write data
    FileUtils.createFile(tempBlockMeta.getPath());
    BlockWriter writer = new LocalFileBlockWriter(tempBlockMeta.getPath());
    writer.append(BufferUtils.getIncreasingByteBuffer(Ints.checkedCast(bytes)));
    writer.close();
    return tempBlockMeta;
}
Also used : LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) BlockWriter(alluxio.worker.block.io.BlockWriter) LocalFileBlockWriter(alluxio.worker.block.io.LocalFileBlockWriter) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

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