Search in sources :

Example 26 with BlockInfo

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);
}
Also used : RemoteBlockReader(alluxio.client.RemoteBlockReader) BlockInfo(alluxio.wire.BlockInfo) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI)

Example 27 with BlockInfo

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());
    }
}
Also used : LockBlockResource(alluxio.client.resource.LockBlockResource) BlockInfo(alluxio.wire.BlockInfo) LockBlockResult(alluxio.wire.LockBlockResult) InputStream(java.io.InputStream) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with BlockInfo

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();
    }
}
Also used : BlockInfo(alluxio.wire.BlockInfo) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

BlockInfo (alluxio.wire.BlockInfo)28 Test (org.junit.Test)21 AlluxioURI (alluxio.AlluxioURI)18 BlockLocation (alluxio.wire.BlockLocation)5 FileBlockInfo (alluxio.wire.FileBlockInfo)5 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 RemoteBlockInStream (alluxio.client.block.RemoteBlockInStream)4 ArrayList (java.util.ArrayList)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 InodeFile (alluxio.master.file.meta.InodeFile)3 IOException (java.io.IOException)3 RemoteBlockReader (alluxio.client.RemoteBlockReader)2 URIStatus (alluxio.client.file.URIStatus)2 LockBlockResource (alluxio.client.resource.LockBlockResource)2 AlluxioException (alluxio.exception.AlluxioException)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)2 FileInfo (alluxio.wire.FileInfo)2 LockBlockResult (alluxio.wire.LockBlockResult)2 BlockWorker (alluxio.worker.block.BlockWorker)2