Search in sources :

Example 16 with TempBlockMeta

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

the class BlockMetadataManagerTest method moveBlockMetaDeprecated.

/**
   * Tests the {@link BlockMetadataManager#moveBlockMeta(BlockMeta, BlockStoreLocation)} method.
   */
@Test
public void moveBlockMetaDeprecated() 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.addTempBlockMeta(tempBlockMeta);
    mMetaManager.commitTempBlockMeta(tempBlockMeta);
    BlockMeta blockMeta = mMetaManager.getBlockMeta(TEST_TEMP_BLOCK_ID);
    // Move to anywhere
    mMetaManager.moveBlockMeta(blockMeta, BlockStoreLocation.anyTier());
    // Move to tier HDD tier
    blockMeta = mMetaManager.moveBlockMeta(blockMeta, BlockStoreLocation.anyDirInTier("HDD"));
    Assert.assertEquals("HDD", blockMeta.getBlockLocation().tierAlias());
    // Move to tier MEM and dir 0
    blockMeta = mMetaManager.moveBlockMeta(blockMeta, new BlockStoreLocation("MEM", 0));
    Assert.assertEquals("MEM", blockMeta.getBlockLocation().tierAlias());
    Assert.assertEquals(0, blockMeta.getBlockLocation().dir());
}
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 17 with TempBlockMeta

use of alluxio.worker.block.meta.TempBlockMeta 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("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 TempBlockMeta(sessionId1, tempBlockId1, TEST_BLOCK_SIZE, dir);
    TempBlockMeta tempBlockMeta2 = new TempBlockMeta(sessionId1, tempBlockId2, TEST_BLOCK_SIZE, dir);
    TempBlockMeta tempBlockMeta3 = new TempBlockMeta(sessionId2, tempBlockId3, TEST_BLOCK_SIZE, dir);
    BlockMeta blockMeta = new BlockMeta(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());
    }
    Assert.assertEquals(Sets.newHashSet(tempBlockMeta1, tempBlockMeta2), new HashSet<>(toRemove));
    Assert.assertTrue(dir.hasTempBlockMeta(tempBlockId1));
    Assert.assertTrue(dir.hasTempBlockMeta(tempBlockId2));
    // Clean up sessionId1, expect tempBlock1 and tempBlock2 to be removed.
    mMetaManager.cleanupSessionTempBlocks(sessionId1, toRemoveBlockIds);
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    Assert.assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    Assert.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());
    }
    Assert.assertTrue(toRemove.isEmpty());
    // Clean up sessionId1 again, expect nothing to happen
    mMetaManager.cleanupSessionTempBlocks(sessionId1, toRemoveBlockIds);
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    Assert.assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    Assert.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());
    }
    Assert.assertEquals(Sets.newHashSet(tempBlockMeta3), new HashSet<>(toRemove));
    Assert.assertTrue(dir.hasTempBlockMeta(tempBlockId3));
    // Clean up sessionId2, expect tempBlock3 to be removed
    mMetaManager.cleanupSessionTempBlocks(sessionId2, toRemoveBlockIds);
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId1));
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId2));
    Assert.assertFalse(dir.hasTempBlockMeta(tempBlockId3));
    Assert.assertTrue(dir.hasBlockMeta(TEST_BLOCK_ID));
}
Also used : ArrayList(java.util.ArrayList) 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 18 with TempBlockMeta

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

the class BlockMetadataManagerTest method moveBlockMetaOutOfSpaceException.

/**
   * Tests that an exception is thrown in the
   * {@link BlockMetadataManager#moveBlockMeta(BlockMeta, TempBlockMeta)} method when the worker is
   * out of space.
   */
@Test
public void moveBlockMetaOutOfSpaceException() throws Exception {
    // Create a committed block under dir2 with larger size than the capacity of dir1,
    // so that WorkerOutOfSpaceException should be thrown when move this block to dir1.
    StorageDir dir1 = mMetaManager.getTier("HDD").getDir(0);
    StorageDir dir2 = mMetaManager.getTier("HDD").getDir(1);
    long maxHddDir1Capacity = TIER_CAPACITY_BYTES[1][0];
    long blockMetaSize = maxHddDir1Capacity + 1;
    BlockMeta blockMeta = new BlockMeta(TEST_BLOCK_ID, blockMetaSize, dir2);
    TempBlockMeta tempBlockMeta2 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID2, TEST_BLOCK_SIZE, dir1);
    mMetaManager.addTempBlockMeta(tempBlockMeta2);
    dir2.addBlockMeta(blockMeta);
    mThrown.expect(WorkerOutOfSpaceException.class);
    mThrown.expectMessage(ExceptionMessage.NO_SPACE_FOR_BLOCK_META.getMessage(TEST_BLOCK_ID, blockMetaSize, maxHddDir1Capacity, TIER_ALIAS[1]));
    mMetaManager.moveBlockMeta(blockMeta, tempBlockMeta2);
}
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 19 with TempBlockMeta

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

the class BlockMetadataManagerTest method moveBlockMetaSameDir.

/**
   * Dummy unit test, actually the case of move block meta to same dir should never happen.
   */
@Test
public void moveBlockMetaSameDir() throws Exception {
    // create and add two temp block metas with same tier and dir to the meta manager
    StorageDir dir = mMetaManager.getTier("MEM").getDir(0);
    TempBlockMeta tempBlockMeta1 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir);
    TempBlockMeta tempBlockMeta2 = new TempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID2, TEST_BLOCK_SIZE, dir);
    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);
    // test to make sure that the dst tempBlockMeta has been removed from the dir
    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 20 with TempBlockMeta

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

the class BlockWorkerTest method createBlockRemote.

/**
   * Tests the {@link BlockWorker#createBlockRemote(long, long, String, long)} method.
   */
@Test
public void createBlockRemote() 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)

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