Search in sources :

Example 16 with FileBlockInfo

use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.

the class FileInStreamIntegrationTest method asyncCacheAfterSeek.

@Test(timeout = 10000)
public void asyncCacheAfterSeek() throws Exception {
    String filename = mTestPath + "/file_" + MAX_LEN + "_" + mWriteUnderStore.hashCode();
    AlluxioURI uri = new AlluxioURI(filename);
    for (ReadType readType : ReadType.values()) {
        mFileSystem.free(uri);
        CommonUtils.waitFor("No in-Alluxio data left from previous iteration.", () -> {
            try {
                URIStatus st = mFileSystem.getStatus(uri);
                return st.getInAlluxioPercentage() == 0;
            } catch (Exception e) {
                return false;
            }
        });
        FileInStream is = mFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(readType.toProto()).build());
        URIStatus status = mFileSystem.getStatus(uri);
        is.seek(status.getBlockSizeBytes() + 1);
        is.read();
        status = mFileSystem.getStatus(uri);
        Assert.assertEquals(0, status.getInAlluxioPercentage());
        is.close();
        if (readType.isCache()) {
            CommonUtils.waitFor("Second block to be cached.", () -> {
                try {
                    URIStatus st = mFileSystem.getStatus(uri);
                    boolean achieved = true;
                    // Expect only second block to be cached, other blocks should be empty in Alluxio
                    for (int i = 0; i < st.getFileBlockInfos().size(); i++) {
                        FileBlockInfo info = st.getFileBlockInfos().get(i);
                        if (i == 1) {
                            achieved = achieved && !info.getBlockInfo().getLocations().isEmpty();
                        } else {
                            achieved = achieved && info.getBlockInfo().getLocations().isEmpty();
                        }
                    }
                    return achieved;
                } catch (Exception e) {
                    return false;
                }
            });
        } else {
            Thread.sleep(1000);
            status = mFileSystem.getStatus(uri);
            Assert.assertEquals(0, status.getInAlluxioPercentage());
        }
    }
}
Also used : ReadType(alluxio.client.ReadType) FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) ExpectedException(org.junit.rules.ExpectedException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 17 with FileBlockInfo

use of alluxio.wire.FileBlockInfo 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 18 with FileBlockInfo

use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.

the class DefaultAsyncPersistHandlerTest method persistenceFileWithBlocksOnMultipleWorkers.

/**
 * Tests the persistence of file with block on multiple workers.
 */
@Test
public void persistenceFileWithBlocksOnMultipleWorkers() throws Exception {
    DefaultAsyncPersistHandler handler = new DefaultAsyncPersistHandler(new FileSystemMasterView(mFileSystemMaster));
    AlluxioURI path = new AlluxioURI("/test");
    List<FileBlockInfo> blockInfoList = new ArrayList<>();
    BlockLocation location1 = new BlockLocation().setWorkerId(1);
    blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setLocations(Lists.newArrayList(location1))));
    BlockLocation location2 = new BlockLocation().setWorkerId(2);
    blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setLocations(Lists.newArrayList(location2))));
    long fileId = 2;
    when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
    when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
    when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
    // no persist scheduled on any worker
    assertEquals(0, handler.pollFilesToPersist(1).size());
    assertEquals(0, handler.pollFilesToPersist(2).size());
}
Also used : FileSystemMasterView(alluxio.master.file.meta.FileSystemMasterView) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 19 with FileBlockInfo

use of alluxio.wire.FileBlockInfo 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)

Example 20 with FileBlockInfo

use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.

the class JobUtils method getWorkerWithMostBlocks.

/**
 * Returns whichever specified worker stores the most blocks from the block info list.
 *
 * @param workers a list of workers to consider
 * @param fileBlockInfos a list of file block information
 * @return a worker address storing the most blocks from the list
 */
public static BlockWorkerInfo getWorkerWithMostBlocks(List<BlockWorkerInfo> workers, List<FileBlockInfo> fileBlockInfos) {
    // Index workers by their addresses.
    IndexedSet<BlockWorkerInfo> addressIndexedWorkers = new IndexedSet<>(WORKER_ADDRESS_INDEX);
    addressIndexedWorkers.addAll(workers);
    // Use ConcurrentMap for putIfAbsent. A regular Map works in Java 8.
    ConcurrentMap<BlockWorkerInfo, Integer> blocksPerWorker = Maps.newConcurrentMap();
    int maxBlocks = 0;
    BlockWorkerInfo mostBlocksWorker = null;
    for (FileBlockInfo fileBlockInfo : fileBlockInfos) {
        for (BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) {
            BlockWorkerInfo worker = addressIndexedWorkers.getFirstByField(WORKER_ADDRESS_INDEX, location.getWorkerAddress());
            if (worker == null) {
                // We can only choose workers in the workers list.
                continue;
            }
            blocksPerWorker.putIfAbsent(worker, 0);
            int newBlockCount = blocksPerWorker.get(worker) + 1;
            blocksPerWorker.put(worker, newBlockCount);
            if (newBlockCount > maxBlocks) {
                maxBlocks = newBlockCount;
                mostBlocksWorker = worker;
            }
        }
    }
    return mostBlocksWorker;
}
Also used : IndexedSet(alluxio.collections.IndexedSet) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation)

Aggregations

FileBlockInfo (alluxio.wire.FileBlockInfo)42 URIStatus (alluxio.client.file.URIStatus)25 AlluxioURI (alluxio.AlluxioURI)23 FileInfo (alluxio.wire.FileInfo)23 BlockInfo (alluxio.wire.BlockInfo)22 Test (org.junit.Test)19 WorkerNetAddress (alluxio.wire.WorkerNetAddress)16 ArrayList (java.util.ArrayList)16 BlockLocation (alluxio.wire.BlockLocation)14 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)11 InStreamOptions (alluxio.client.file.options.InStreamOptions)10 IOException (java.io.IOException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Map (java.util.Map)8 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)7 PropertyKey (alluxio.conf.PropertyKey)7 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 UnavailableException (alluxio.exception.status.UnavailableException)7 Constants (alluxio.Constants)6 FileInStream (alluxio.client.file.FileInStream)6