Search in sources :

Example 11 with InStreamOptions

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

the class AlluxioFileInStreamTest method shortSeekForwardCachingPartiallyReadBlocks.

/**
 * Tests seeking with incomplete block caching enabled. It seeks forward within a block.
 */
@Test
public void shortSeekForwardCachingPartiallyReadBlocks() throws IOException {
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int seekAmount = (int) (BLOCK_LENGTH / 4);
    int readAmount = (int) (BLOCK_LENGTH * 2 - BLOCK_LENGTH / 2);
    byte[] buffer = new byte[readAmount];
    mTestStream.read(buffer);
    // Seek backward.
    mTestStream.seek(readAmount + seekAmount);
    // Block 1 (till seek pos) is being cached.
    validatePartialCaching(1, (int) BLOCK_LENGTH / 2);
    // Seek forward many times. The prefix is always cached.
    for (int i = 0; i < seekAmount; i++) {
        mTestStream.seek(readAmount + seekAmount + i);
        validatePartialCaching(1, (int) BLOCK_LENGTH / 2);
    }
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with InStreamOptions

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

the class RemoteReadIntegrationTest method readTest5.

/**
 * Tests the batch read API from a remote location when the data is only in an Alluxio worker.
 */
@Test
public void readTest5() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
        AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
        FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
        URIStatus status = mFileSystem.getStatus(uri);
        InStreamOptions options = new InStreamOptions(status, ServerConfiguration.global());
        long blockId = status.getBlockIds().get(0);
        BlockInfo info = AlluxioBlockStore.create(FileSystemContext.create(ServerConfiguration.global())).getInfo(blockId);
        WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
        BlockInStream is = BlockInStream.create(mFsContext, options.getBlockInfo(blockId), workerAddr, BlockInStreamSource.REMOTE, options);
        byte[] ret = new byte[k];
        int read = is.read(ret);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(read, Arrays.copyOfRange(ret, 0, read)));
        is.close();
        FileSystemUtils.waitForAlluxioPercentage(mFileSystem, uri, 100);
    }
}
Also used : BlockInStream(alluxio.client.block.stream.BlockInStream) BlockInfo(alluxio.wire.BlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) InStreamOptions(alluxio.client.file.options.InStreamOptions) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 13 with InStreamOptions

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

the class MultiWorkerIntegrationTest method replicateFileBlocks.

private void replicateFileBlocks(AlluxioURI filePath) throws Exception {
    FileSystemContext fsContext = FileSystemContext.create(ServerConfiguration.global());
    AlluxioBlockStore store = AlluxioBlockStore.create(fsContext);
    URIStatus status = mResource.get().getClient().getStatus(filePath);
    List<FileBlockInfo> blocks = status.getFileBlockInfos();
    List<BlockWorkerInfo> workers = fsContext.getCachedWorkers();
    for (FileBlockInfo block : blocks) {
        BlockInfo blockInfo = block.getBlockInfo();
        WorkerNetAddress src = blockInfo.getLocations().get(0).getWorkerAddress();
        WorkerNetAddress dest = workers.stream().filter(candidate -> !candidate.getNetAddress().equals(src)).findFirst().get().getNetAddress();
        try (OutputStream outStream = store.getOutStream(blockInfo.getBlockId(), blockInfo.getLength(), dest, OutStreamOptions.defaults(fsContext.getClientContext()).setBlockSizeBytes(8 * Constants.MB).setWriteType(WriteType.MUST_CACHE))) {
            try (InputStream inStream = store.getInStream(blockInfo.getBlockId(), new InStreamOptions(status, ServerConfiguration.global()))) {
                ByteStreams.copy(inStream, outStream);
            }
        }
    }
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) BufferUtils(alluxio.util.io.BufferUtils) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileSystemTestUtils(alluxio.client.file.FileSystemTestUtils) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) FileSystem(alluxio.client.file.FileSystem) Constants(alluxio.Constants) AlluxioURI(alluxio.AlluxioURI) FileInStream(alluxio.client.file.FileInStream) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) StreamSupport(java.util.stream.StreamSupport) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) OutputStream(java.io.OutputStream) WritePType(alluxio.grpc.WritePType) ServerConfiguration(alluxio.conf.ServerConfiguration) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) InStreamOptions(alluxio.client.file.options.InStreamOptions) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Test(org.junit.Test) IOException(java.io.IOException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) IOUtils(org.apache.commons.io.IOUtils) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) FileSystemContext(alluxio.client.file.FileSystemContext) Rule(org.junit.Rule) ByteStreams(com.google.common.io.ByteStreams) WriteType(alluxio.client.WriteType) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore)

Example 14 with InStreamOptions

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

the class BlockWorkerDataReaderTest method before.

@Before
public void before() throws Exception {
    BlockMasterClient blockMasterClient = mock(BlockMasterClient.class);
    BlockMasterClientPool blockMasterClientPool = spy(new BlockMasterClientPool());
    when(blockMasterClientPool.createNewResource()).thenReturn(blockMasterClient);
    TieredBlockStore blockStore = new TieredBlockStore();
    FileSystemMasterClient fileSystemMasterClient = mock(FileSystemMasterClient.class);
    Sessions sessions = mock(Sessions.class);
    // Connect to the real UFS for UFS read testing
    UfsManager ufsManager = mock(UfsManager.class);
    mRootUfs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
    UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> UnderFileSystem.Factory.create(mRootUfs, UnderFileSystemConfiguration.defaults(ServerConfiguration.global())), new AlluxioURI(mRootUfs));
    when(ufsManager.get(anyLong())).thenReturn(ufsClient);
    mBlockWorker = new DefaultBlockWorker(blockMasterClientPool, fileSystemMasterClient, sessions, blockStore, ufsManager);
    URIStatus dummyStatus = new URIStatus(new FileInfo().setBlockIds(Collections.singletonList(BLOCK_ID)));
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(mConf), mConf);
    mDataReaderFactory = new BlockWorkerDataReader.Factory(mBlockWorker, BLOCK_ID, CHUNK_SIZE, options);
}
Also used : BlockMasterClientPool(alluxio.worker.block.BlockMasterClientPool) UfsManager(alluxio.underfs.UfsManager) Sessions(alluxio.Sessions) URIStatus(alluxio.client.file.URIStatus) TieredBlockStore(alluxio.worker.block.TieredBlockStore) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) FileSystemMasterClient(alluxio.worker.file.FileSystemMasterClient) FileInfo(alluxio.wire.FileInfo) BlockMasterClient(alluxio.worker.block.BlockMasterClient) DefaultBlockWorker(alluxio.worker.block.DefaultBlockWorker) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 15 with InStreamOptions

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

the class BlockWorkerDataReaderTest method readChunkUfs.

@Test
public void readChunkUfs() throws Exception {
    // Write an actual file to UFS
    String testFilePath = File.createTempFile("temp", null, new File(mRootUfs)).getAbsolutePath();
    byte[] buffer = BufferUtils.getIncreasingByteArray(CHUNK_SIZE * 5);
    BufferUtils.writeBufferToFile(testFilePath, buffer);
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE * 5);
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setUfsPath(testFilePath).setBlockIds(Collections.singletonList(BLOCK_ID)).setLength(CHUNK_SIZE * 5).setBlockSizeBytes(CHUNK_SIZE).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
    InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, mConf);
    BlockWorkerDataReader.Factory factory = new BlockWorkerDataReader.Factory(mBlockWorker, BLOCK_ID, CHUNK_SIZE, options);
    int len = CHUNK_SIZE * 3 / 2;
    try (DataReader dataReader = factory.create(0, len)) {
        validateBuffer(dataReader.readChunk(), 0, CHUNK_SIZE);
        assertEquals(CHUNK_SIZE, dataReader.pos());
        validateBuffer(dataReader.readChunk(), CHUNK_SIZE, len - CHUNK_SIZE);
        assertEquals(len, dataReader.pos());
    }
}
Also used : URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) DataReader(alluxio.client.block.stream.DataReader) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) File(java.io.File) 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