Search in sources :

Example 6 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method testGetInStreamFallback.

private void testGetInStreamFallback(int workerCount, boolean isPersisted, int[] blockLocations, Map<Integer, Long> failedWorkers, int expectedWorker) throws Exception {
    WorkerNetAddress[] workers = new WorkerNetAddress[workerCount];
    Arrays.setAll(workers, i -> new WorkerNetAddress().setHost(String.format("worker-%d", i)));
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.stream(blockLocations).mapToObj(x -> new BlockLocation().setWorkerAddress(workers[x])).collect(Collectors.toList()));
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(isPersisted).setBlockIds(Collections.singletonList(BLOCK_ID)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    BlockLocationPolicy mockPolicy = mock(BlockLocationPolicy.class);
    when(mockPolicy.getWorker(any())).thenAnswer(arg -> arg.getArgument(0, GetWorkerOptions.class).getBlockWorkerInfos().iterator().next().getNetAddress());
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(sConf), sConf);
    options.setUfsReadLocationPolicy(mockPolicy);
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    when(mContext.getCachedWorkers()).thenReturn(Arrays.stream(workers).map(x -> new BlockWorkerInfo(x, -1, -1)).collect((Collectors.toList())));
    Map<WorkerNetAddress, Long> failedWorkerAddresses = failedWorkers.entrySet().stream().map(x -> new AbstractMap.SimpleImmutableEntry<>(workers[x.getKey()], x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    BlockInStream inStream = mBlockStore.getInStream(BLOCK_ID, options, failedWorkerAddresses);
    assertEquals(workers[expectedWorker], inStream.getAddress());
}
Also used : Arrays(java.util.Arrays) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) BlockInfo(alluxio.wire.BlockInfo) GrpcDataReader(alluxio.client.block.stream.GrpcDataReader) NoopClosableResource(alluxio.client.block.stream.NoopClosableResource) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) PreconditionMessage(alluxio.exception.PreconditionMessage) ClientContext(alluxio.ClientContext) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) DummyCloseableResource(alluxio.resource.DummyCloseableResource) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) Mockito.any(org.mockito.Mockito.any) WriteType(alluxio.client.WriteType) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) UnavailableException(alluxio.exception.status.UnavailableException) BlockWorker(alluxio.worker.block.BlockWorker) Assert.assertThrows(org.junit.Assert.assertThrows) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RunWith(org.junit.runner.RunWith) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) BlockOutStream(alluxio.client.block.stream.BlockOutStream) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ConfigurationRule(alluxio.ConfigurationRule) OpenLocalBlockResponse(alluxio.grpc.OpenLocalBlockResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) CreateLocalBlockResponse(alluxio.grpc.CreateLocalBlockResponse) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) PowerMockito(org.powermock.api.mockito.PowerMockito) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) Assert.assertTrue(org.junit.Assert.assertTrue) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) OpenLocalBlockRequest(alluxio.grpc.OpenLocalBlockRequest) BlockLocation(alluxio.wire.BlockLocation) Mockito(org.mockito.Mockito) URIStatus(alluxio.client.file.URIStatus) AbstractMap(java.util.AbstractMap) FileSystemContext(alluxio.client.file.FileSystemContext) FileInfo(alluxio.wire.FileInfo) Closeable(java.io.Closeable) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemOptions(alluxio.util.FileSystemOptions) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockInStream(alluxio.client.block.stream.BlockInStream) FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap)

Example 7 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class BlockInStreamTest method before.

@Before
public void before() throws Exception {
    BlockWorkerClient workerClient = Mockito.mock(BlockWorkerClient.class);
    ClientCallStreamObserver requestObserver = Mockito.mock(ClientCallStreamObserver.class);
    when(requestObserver.isReady()).thenReturn(true);
    when(workerClient.openLocalBlock(any(StreamObserver.class))).thenAnswer(new Answer() {

        public Object answer(InvocationOnMock invocation) {
            mResponseObserver = invocation.getArgument(0, StreamObserver.class);
            return requestObserver;
        }
    });
    doAnswer(invocation -> {
        mResponseObserver.onNext(OpenLocalBlockResponse.newBuilder().setPath("/tmp").build());
        mResponseObserver.onCompleted();
        return null;
    }).when(requestObserver).onNext(any(OpenLocalBlockRequest.class));
    mMockContext = Mockito.mock(FileSystemContext.class);
    when(mMockContext.acquireBlockWorkerClient(ArgumentMatchers.any(WorkerNetAddress.class))).thenReturn(new NoopClosableResource<>(workerClient));
    when(mMockContext.getClientContext()).thenReturn(ClientContext.create(mConf));
    when(mMockContext.getClusterConf()).thenReturn(mConf);
    mInfo = new BlockInfo().setBlockId(1);
    mOptions = new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Collections.singletonList(1L))), mConf);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) URIStatus(alluxio.client.file.URIStatus) InStreamOptions(alluxio.client.file.options.InStreamOptions) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FileInfo(alluxio.wire.FileInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileSystemContext(alluxio.client.file.FileSystemContext) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) OpenLocalBlockRequest(alluxio.grpc.OpenLocalBlockRequest) Before(org.junit.Before)

Example 8 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class BaseFileSystem method openFile.

@Override
public FileInStream openFile(URIStatus status, OpenFilePOptions options) throws FileDoesNotExistException, OpenDirectoryException, FileIncompleteException, IOException, AlluxioException {
    AlluxioURI path = new AlluxioURI(status.getPath());
    if (status.isFolder()) {
        throw new OpenDirectoryException(path);
    }
    if (!status.isCompleted()) {
        throw new FileIncompleteException(path);
    }
    AlluxioConfiguration conf = mFsContext.getPathConf(path);
    OpenFilePOptions mergedOptions = FileSystemOptions.openFileDefaults(conf).toBuilder().mergeFrom(options).build();
    InStreamOptions inStreamOptions = new InStreamOptions(status, mergedOptions, conf);
    return new AlluxioFileInStream(status, inStreamOptions, mFsContext);
}
Also used : OpenDirectoryException(alluxio.exception.OpenDirectoryException) FileIncompleteException(alluxio.exception.FileIncompleteException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) AlluxioURI(alluxio.AlluxioURI) InStreamOptions(alluxio.client.file.options.InStreamOptions)

Example 9 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method testSeekWithNoLocalWorker.

/**
 * Tests reading and seeking with no local worker. Nothing should be cached.
 */
@Test
public void testSeekWithNoLocalWorker() throws IOException {
    // Overrides the get local worker call
    when(mContext.getNodeLocalWorker()).thenReturn(null);
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int readAmount = (int) (BLOCK_LENGTH / 2);
    byte[] buffer = new byte[readAmount];
    // read and seek several times
    mTestStream.read(buffer);
    assertEquals(readAmount, mInStreams.get(0).getBytesRead());
    mTestStream.seek(BLOCK_LENGTH + BLOCK_LENGTH / 2);
    mTestStream.seek(0);
    // only reads the read amount, regardless of block source
    assertEquals(readAmount, mInStreams.get(0).getBytesRead());
    assertEquals(0, mInStreams.get(1).getBytesRead());
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method triggerAsyncOnClose.

// See https://github.com/Alluxio/alluxio/issues/13828
@Test
public void triggerAsyncOnClose() throws Exception {
    assumeTrue(mBlockSource == BlockInStreamSource.UFS);
    mInfo.setReplicationMax(1);
    mStatus = new URIStatus(mInfo);
    OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, readOptions, mConf), mContext);
    mTestStream.read(new byte[(int) mFileSize], 0, (int) mFileSize);
    assertEquals(mFileSize, mTestStream.getPos());
    assertTrue(mTestStream.triggerAsyncCaching(mInStreams.get(mInStreams.size() - 1)));
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

InStreamOptions (alluxio.client.file.options.InStreamOptions)36 Test (org.junit.Test)26 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)23 BlockInfo (alluxio.wire.BlockInfo)22 URIStatus (alluxio.client.file.URIStatus)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 WorkerNetAddress (alluxio.wire.WorkerNetAddress)18 FileBlockInfo (alluxio.wire.FileBlockInfo)17 FileInfo (alluxio.wire.FileInfo)16 BlockInStream (alluxio.client.block.stream.BlockInStream)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)7 FileSystemContext (alluxio.client.file.FileSystemContext)7 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)7 IOException (java.io.IOException)7 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)6 BlockLocation (alluxio.wire.BlockLocation)6 Before (org.junit.Before)6 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)5 BlockWorkerDataReader (alluxio.client.block.stream.BlockWorkerDataReader)5