Search in sources :

Example 26 with OpenFilePOptions

use of alluxio.grpc.OpenFilePOptions in project alluxio by Alluxio.

the class JobUtils method loadThroughCacheRequest.

private static void loadThroughCacheRequest(URIStatus status, FileSystemContext context, long blockId, AlluxioConfiguration conf, WorkerNetAddress localNetAddress) throws IOException {
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
    OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
    InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
    BlockLocationPolicy policy = BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf);
    inOptions.setUfsReadLocationPolicy(policy);
    Protocol.OpenUfsBlockOptions openUfsBlockOptions = inOptions.getOpenUfsBlockOptions(blockId);
    BlockInfo info = Preconditions.checkNotNull(status.getBlockInfo(blockId));
    long blockLength = info.getLength();
    Pair<WorkerNetAddress, BlockInStream.BlockInStreamSource> dataSourceAndType = blockStore.getDataSourceAndType(status.getBlockInfo(blockId), status, policy, ImmutableMap.of());
    WorkerNetAddress dataSource = dataSourceAndType.getFirst();
    String host = dataSource.getHost();
    // to establish the connection.
    if (!dataSource.getContainerHost().equals("")) {
        host = dataSource.getContainerHost();
    }
    CacheRequest request = CacheRequest.newBuilder().setBlockId(blockId).setLength(blockLength).setOpenUfsBlockOptions(openUfsBlockOptions).setSourceHost(host).setSourcePort(dataSource.getDataPort()).build();
    try (CloseableResource<BlockWorkerClient> blockWorker = context.acquireBlockWorkerClient(localNetAddress)) {
        blockWorker.get().cache(request);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : IOException(java.io.IOException) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) CacheRequest(alluxio.grpc.CacheRequest) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) Protocol(alluxio.proto.dataserver.Protocol)

Example 27 with OpenFilePOptions

use of alluxio.grpc.OpenFilePOptions in project alluxio by Alluxio.

the class TieredStoreIntegrationTest method deleteWhileRead.

/**
 * Tests that deletes go through despite failing initially due to concurrent read.
 */
@Test
public void deleteWhileRead() throws Exception {
    // Small enough not to trigger async eviction
    int fileSize = MEM_CAPACITY_BYTES / 2;
    AlluxioURI file = new AlluxioURI("/test1");
    FileSystemTestUtils.createByteFile(mFileSystem, file, WritePType.MUST_CACHE, fileSize);
    CommonUtils.waitFor("file in memory", () -> {
        try {
            return 100 == mFileSystem.getStatus(file).getInAlluxioPercentage();
        } catch (Exception e) {
            return false;
        }
    }, WAIT_OPTIONS);
    // Open the file
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
    FileInStream in = mFileSystem.openFile(file, options);
    Assert.assertEquals(0, in.read());
    // Delete the file
    mFileSystem.delete(file);
    // After the delete, the master should no longer serve the file
    Assert.assertFalse(mFileSystem.exists(file));
    // However, the previous read should still be able to read it as the data still exists
    byte[] res = new byte[fileSize];
    Assert.assertEquals(fileSize - 1, in.read(res, 1, fileSize - 1));
    res[0] = 0;
    Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileSize, res));
    in.close();
    CommonUtils.waitFor("file blocks are deleted", () -> 0 == mBlockMaster.getUsedBytes(), WAIT_OPTIONS);
    // After the file is closed, the master's delete should go through and new files can be created
    AlluxioURI newFile = new AlluxioURI("/test2");
    FileSystemTestUtils.createByteFile(mFileSystem, newFile, WritePType.MUST_CACHE, MEM_CAPACITY_BYTES);
    Assert.assertEquals(100, mFileSystem.getStatus(newFile).getInAlluxioPercentage());
}
Also used : FileInStream(alluxio.client.file.FileInStream) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) ExpectedException(org.junit.rules.ExpectedException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

OpenFilePOptions (alluxio.grpc.OpenFilePOptions)27 InStreamOptions (alluxio.client.file.options.InStreamOptions)20 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 FileBlockInfo (alluxio.wire.FileBlockInfo)10 BlockInfo (alluxio.wire.BlockInfo)9 AlluxioURI (alluxio.AlluxioURI)8 URIStatus (alluxio.client.file.URIStatus)8 WorkerNetAddress (alluxio.wire.WorkerNetAddress)8 FileInfo (alluxio.wire.FileInfo)7 FileInStream (alluxio.client.file.FileInStream)6 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)5 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)4 IOException (java.io.IOException)4 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)3 BlockInStream (alluxio.client.block.stream.BlockInStream)3 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)3 FileSystemContext (alluxio.client.file.FileSystemContext)3 AlluxioException (alluxio.exception.AlluxioException)3 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)2