use of alluxio.worker.block.meta.StorageDir 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(Constants.MEDIUM_MEM).getDir(0);
TempBlockMeta tempBlockMeta = new DefaultTempBlockMeta(TEST_SESSION_ID, TEST_TEMP_BLOCK_ID, TEST_BLOCK_SIZE, dir);
mMetaManager.resizeTempBlockMeta(tempBlockMeta, TEST_BLOCK_SIZE + 1);
assertEquals(TEST_BLOCK_SIZE + 1, tempBlockMeta.getBlockSize());
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class SwapRestoreTaskTest method testTierAlignment.
@Test
public void testTierAlignment() throws Exception {
Random rnd = new Random();
// Start simulating random load on worker.
startSimulateLoad();
// Fill first dir with small blocks.
long sessionIdCounter = 1000;
long blockIdCounter = 1000;
while (mTestDir1.getAvailableBytes() > 0) {
TieredBlockStoreTestUtils.cache(sessionIdCounter++, blockIdCounter++, SMALL_BLOCK_SIZE, mBlockStore, mTestDir1.toBlockStoreLocation(), false);
}
// Fill the rest with big blocks.
StorageDir[] dirArray = new StorageDir[] { mTestDir2, mTestDir3, mTestDir4 };
for (StorageDir dir : dirArray) {
while (dir.getAvailableBytes() > 0) {
TieredBlockStoreTestUtils.cache(sessionIdCounter++, blockIdCounter++, BLOCK_SIZE, mBlockStore, dir.toBlockStoreLocation(), false);
}
}
// which is filled with small blocks.
for (int i = 0; i < 100; i++) {
StorageDir dirToAccess = dirArray[rnd.nextInt(dirArray.length)];
List<Long> blockIdList = dirToAccess.getBlockIds();
if (!blockIdList.isEmpty()) {
mBlockStore.accessBlock(sessionIdCounter++, blockIdList.get(rnd.nextInt(blockIdList.size())));
}
}
// Validate tiers are not aligned. (It's not guaranteed but using LRU helps.)
Assert.assertTrue(!mBlockIterator.aligned(BlockStoreLocation.anyDirInTier(FIRST_TIER_ALIAS), BlockStoreLocation.anyDirInTier(SECOND_TIER_ALIAS), BlockOrder.NATURAL, (b) -> false));
// Stop the load for swap task to continue.
stopSimulateLoad();
// TODO(ggezer): Validate swap-restore task was activated.
CommonUtils.waitFor("Tiers to be aligned by background swap task.", () -> mBlockIterator.aligned(BlockStoreLocation.anyDirInTier(FIRST_TIER_ALIAS), BlockStoreLocation.anyDirInTier(SECOND_TIER_ALIAS), BlockOrder.NATURAL, (b) -> false), WaitForOptions.defaults().setTimeoutMs(60000));
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataManagerViewTest method getAvailableBytes.
/**
* Tests the {@link BlockMetadataManagerView#getAvailableBytes(BlockStoreLocation)} method.
*/
@Test
public void getAvailableBytes() {
BlockStoreLocation location;
// When location represents anyTier
location = BlockStoreLocation.anyTier();
Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
// When location represents one particular tier
for (StorageTier tier : mMetaManager.getTiers()) {
String tierAlias = tier.getTierAlias();
location = BlockStoreLocation.anyDirInTier(tierAlias);
Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
for (StorageDir dir : tier.getStorageDirs()) {
// When location represents one particular dir
location = dir.toBlockStoreLocation();
Assert.assertEquals(mMetaManager.getAvailableBytes(location), mMetaManagerView.getAvailableBytes(location));
}
}
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataManagerViewTest method sameTierViewsBelow.
/**
* Tests that {@link BlockMetadataManagerView#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 = mMetaManagerView.getTierViewsBelow(tierAlias);
// Do some operations on metadata
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL + 1).getDir(TEST_DIR);
BlockMeta blockMeta = new BlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
try {
dir.addBlockMeta(blockMeta);
} catch (Exception e) {
e.printStackTrace();
}
List<StorageTier> tiers2 = mMetaManager.getTiersBelow(tierAlias);
Assert.assertEquals(tierViews1.size(), tiers2.size());
for (int i = 0; i < tierViews1.size(); i++) {
assertSameTierView(tierViews1.get(i), new StorageTierView(tiers2.get(i), mMetaManagerView));
}
}
use of alluxio.worker.block.meta.StorageDir in project alluxio by Alluxio.
the class BlockMetadataManagerViewTest method getBlockMeta.
/**
* Tests the {@link BlockMetadataManagerView#getBlockMeta(long)} method.
*/
@Test
public void getBlockMeta() throws Exception {
StorageDir dir = mMetaManager.getTiers().get(TEST_TIER_ORDINAL).getDir(TEST_DIR);
// Add one block to test dir, expect block meta found
BlockMeta blockMeta = new BlockMeta(TEST_BLOCK_ID, TEST_BLOCK_SIZE, dir);
dir.addBlockMeta(blockMeta);
Assert.assertEquals(blockMeta, mMetaManagerView.getBlockMeta(TEST_BLOCK_ID));
Assert.assertTrue(mMetaManagerView.isBlockEvictable(TEST_BLOCK_ID));
// Lock this block, expect null result
Mockito.when(mMetaManagerView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
Mockito.when(mMetaManagerView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(true);
Assert.assertNull(mMetaManagerView.getBlockMeta(TEST_BLOCK_ID));
Assert.assertFalse(mMetaManagerView.isBlockEvictable(TEST_BLOCK_ID));
// Pin this block, expect null result
Mockito.when(mMetaManagerView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(true);
Mockito.when(mMetaManagerView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
Assert.assertNull(mMetaManagerView.getBlockMeta(TEST_BLOCK_ID));
Assert.assertFalse(mMetaManagerView.isBlockEvictable(TEST_BLOCK_ID));
// No Pin or lock on this block, expect block meta found
Mockito.when(mMetaManagerView.isBlockPinned(TEST_BLOCK_ID)).thenReturn(false);
Mockito.when(mMetaManagerView.isBlockLocked(TEST_BLOCK_ID)).thenReturn(false);
Assert.assertEquals(blockMeta, mMetaManagerView.getBlockMeta(TEST_BLOCK_ID));
Assert.assertTrue(mMetaManagerView.isBlockEvictable(TEST_BLOCK_ID));
}
Aggregations