use of alluxio.wire.BlockInfo in project alluxio by Alluxio.
the class DataServerIntegrationTest method readThroughClientNonExistent.
// TODO(calvin): Make this work with the new BlockReader.
// @Test
public void readThroughClientNonExistent() throws Exception {
final int length = 10;
FileSystemTestUtils.createByteFile(mFileSystem, "/file", WriteType.MUST_CACHE, length);
BlockInfo block = getFirstBlockInfo(new AlluxioURI("/file"));
// Get the maximum block id, for use in determining a non-existent block id.
URIStatus status = mFileSystem.getStatus(new AlluxioURI("/file"));
long maxBlockId = block.getBlockId();
for (long blockId : status.getBlockIds()) {
if (blockId > maxBlockId) {
maxBlockId = blockId;
}
}
RemoteBlockReader client = RemoteBlockReader.Factory.create(FileSystemContext.INSTANCE);
block.setBlockId(maxBlockId + 1);
ByteBuffer result = readRemotely(client, block, length);
Assert.assertNull(result);
}
use of alluxio.wire.BlockInfo in project alluxio by Alluxio.
the class AlluxioBlockStoreTest method getInStreamRemote.
/**
* Tests {@link AlluxioBlockStore#getInStream(long, InStreamOptions)} when no local block
* exists, making sure that the first {@link BlockLocation} in the {@link BlockInfo} list is
* chosen.
*/
@Test
public void getInStreamRemote() throws Exception {
Mockito.when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo().setLocations(Arrays.asList(BLOCK_LOCATION_REMOTE)));
File mTestFile = mTestFolder.newFile("testFile");
// When a block lock for id BLOCK_ID is requested, a path to a temporary file is returned
Mockito.when(mBlockWorkerClient.lockBlock(BLOCK_ID, LockBlockOptions.defaults())).thenReturn(new LockBlockResource(mBlockWorkerClient, new LockBlockResult().setLockId(LOCK_ID).setBlockPath(mTestFile.getAbsolutePath()), BLOCK_ID));
InputStream stream = mBlockStore.getInStream(BLOCK_ID, InStreamOptions.defaults());
if (Configuration.getBoolean(PropertyKey.USER_PACKET_STREAMING_ENABLED)) {
Assert.assertEquals(alluxio.client.block.stream.BlockInStream.class, stream.getClass());
} else {
Assert.assertEquals(RemoteBlockInStream.class, stream.getClass());
}
}
use of alluxio.wire.BlockInfo in project alluxio by Alluxio.
the class AlluxioBlockStore method promote.
/**
* Attempts to promote a block in Alluxio space. If the block is not present, this method will
* return without an error. If the block is present in multiple workers, only one worker will
* receive the promotion request.
*
* @param blockId the id of the block to promote
* @throws IOException if the block does not exist
*/
public void promote(long blockId) throws IOException {
BlockInfo info;
try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireBlockMasterClientResource()) {
info = blockMasterClientResource.get().getBlockInfo(blockId);
} catch (AlluxioException e) {
throw new IOException(e);
}
if (info.getLocations().isEmpty()) {
// Nothing to promote
return;
}
// Get the first worker address for now, as this will likely be the location being read from
// TODO(calvin): Get this location via a policy (possibly location is a parameter to promote)
BlockWorkerClient blockWorkerClient = mContext.createBlockWorkerClient(info.getLocations().get(0).getWorkerAddress(), null);
try {
blockWorkerClient.promoteBlock(blockId);
} catch (AlluxioException e) {
throw new IOException(e);
} finally {
blockWorkerClient.close();
}
}
Aggregations