Search in sources :

Example 26 with FileBlockInfo

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

the class AbstractFileSystem method getFileBlockLocations.

@Nullable
@Override
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException {
    LOG.debug("getFileBlockLocations({}, {}, {})", (file == null) ? null : file.getPath().getName(), start, len);
    if (file == null) {
        LOG.debug("getFileBlockLocations({}, {}, {}) returned null", null, start, len);
        return null;
    }
    if (mStatistics != null) {
        mStatistics.incrementReadOps(1);
    }
    List<BlockLocation> blockLocations = new ArrayList<>();
    AlluxioURI path = getAlluxioPath(file.getPath());
    try {
        List<BlockLocationInfo> locations = mFileSystem.getBlockLocations(path);
        locations.forEach(location -> {
            FileBlockInfo info = location.getBlockInfo();
            List<WorkerNetAddress> workers = location.getLocations();
            long offset = location.getBlockInfo().getOffset();
            long end = offset + info.getBlockInfo().getLength();
            if (end >= start && offset <= start + len) {
                List<HostAndPort> addresses = workers.stream().map(worker -> HostAndPort.fromParts(worker.getHost(), worker.getDataPort())).collect(toList());
                String[] names = addresses.stream().map(HostAndPort::toString).toArray(String[]::new);
                String[] hosts = addresses.stream().map(HostAndPort::getHost).toArray(String[]::new);
                blockLocations.add(new BlockLocation(names, hosts, offset, info.getBlockInfo().getLength()));
            }
        });
        BlockLocation[] ret = blockLocations.toArray(new BlockLocation[blockLocations.size()]);
        if (LOG.isDebugEnabled()) {
            LOG.debug("getFileBlockLocations({}, {}, {}) returned {}", file.getPath().getName(), start, len, Arrays.toString(ret));
        }
        return ret;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AccessControlContext(java.security.AccessControlContext) Arrays(java.util.Arrays) Progressable(org.apache.hadoop.util.Progressable) BlockLocation(org.apache.hadoop.fs.BlockLocation) LoggerFactory(org.slf4j.LoggerFactory) FileBlockInfo(alluxio.wire.FileBlockInfo) FileStatus(org.apache.hadoop.fs.FileStatus) PropertyKey(alluxio.conf.PropertyKey) FsPermission(org.apache.hadoop.fs.permission.FsPermission) FileSystem(alluxio.client.file.FileSystem) InvalidPathException(alluxio.exception.InvalidPathException) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) Factory(alluxio.master.MasterInquireClient.Factory) Path(org.apache.hadoop.fs.Path) URI(java.net.URI) ClientContext(alluxio.ClientContext) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) AlluxioException(alluxio.exception.AlluxioException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AlluxioProperties(alluxio.conf.AlluxioProperties) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Source(alluxio.conf.Source) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AccessController(java.security.AccessController) InstancedConfiguration(alluxio.conf.InstancedConfiguration) CheckAccessPOptions(alluxio.grpc.CheckAccessPOptions) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) FileOutStream(alluxio.client.file.FileOutStream) Mode(alluxio.security.authorization.Mode) FsAction(org.apache.hadoop.fs.permission.FsAction) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DeletePOptions(alluxio.grpc.DeletePOptions) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Constants(alluxio.Constants) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AlluxioURI(alluxio.AlluxioURI) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) Nullable(javax.annotation.Nullable) CurrentUser(alluxio.security.CurrentUser) Logger(org.slf4j.Logger) ExceptionMessage(alluxio.exception.ExceptionMessage) IOException(java.io.IOException) ConfigurationUtils(alluxio.util.ConfigurationUtils) HostAndPort(com.google.common.net.HostAndPort) Subject(javax.security.auth.Subject) Collectors.toList(java.util.stream.Collectors.toList) URIStatus(alluxio.client.file.URIStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BlockLocationInfo(alluxio.wire.BlockLocationInfo) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BlockLocation(org.apache.hadoop.fs.BlockLocation) FileBlockInfo(alluxio.wire.FileBlockInfo) HostAndPort(com.google.common.net.HostAndPort) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockLocationInfo(alluxio.wire.BlockLocationInfo) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException) Nullable(javax.annotation.Nullable)

Example 27 with FileBlockInfo

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

the class AbstractFileSystemTest method verifyBlockLocations.

void verifyBlockLocations(List<WorkerNetAddress> blockWorkers, List<String> ufsLocations, List<WorkerNetAddress> allWorkers, List<WorkerNetAddress> expectedWorkers) throws Exception {
    FileBlockInfo blockInfo = new FileBlockInfo().setBlockInfo(new BlockInfo().setLocations(blockWorkers.stream().map(addr -> new alluxio.wire.BlockLocation().setWorkerAddress(addr)).collect(toList()))).setUfsLocations(ufsLocations);
    FileInfo fileInfo = new FileInfo().setLastModificationTimeMs(111L).setLastAccessTimeMs(123L).setFolder(false).setOwner("user1").setGroup("group1").setMode(00755).setFileBlockInfos(Arrays.asList(blockInfo));
    Path path = new Path("/dir/file");
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    AlluxioBlockStore blockStore = mock(AlluxioBlockStore.class);
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    PowerMockito.when(AlluxioBlockStore.create(any(FileSystemContext.class))).thenReturn(blockStore);
    FileSystemContext fsContext = mock(FileSystemContext.class);
    when(fsContext.getClientContext()).thenReturn(ClientContext.create(mConfiguration));
    when(fsContext.getClusterConf()).thenReturn(mConfiguration);
    when(fsContext.getPathConf(any(AlluxioURI.class))).thenReturn(mConfiguration);
    alluxio.client.file.FileSystem fs = alluxio.client.file.FileSystem.Factory.create(fsContext);
    alluxio.client.file.FileSystem spyFs = spy(fs);
    doReturn(new URIStatus(fileInfo)).when(spyFs).getStatus(uri);
    List<BlockWorkerInfo> eligibleWorkerInfos = allWorkers.stream().map(worker -> new BlockWorkerInfo(worker, 0, 0)).collect(toList());
    when(fsContext.getCachedWorkers()).thenReturn(eligibleWorkerInfos);
    List<HostAndPort> expectedWorkerNames = expectedWorkers.stream().map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort())).collect(toList());
    FileSystem alluxioHadoopFs = new FileSystem(spyFs);
    FileStatus file = new FileStatus(0, false, 0, 0, 0, 0, null, null, null, path);
    long start = 0;
    long len = 100;
    BlockLocation[] locations = alluxioHadoopFs.getFileBlockLocations(file, start, len);
    assertEquals(1, locations.length);
    Collections.sort(expectedWorkerNames, (x, y) -> x.toString().compareTo(y.toString()));
    String[] actualNames = locations[0].getNames();
    String[] actualHosts = locations[0].getHosts();
    Arrays.sort(actualNames);
    Arrays.sort(actualHosts);
    assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::toString).toArray(), actualNames);
    assertArrayEquals(expectedWorkerNames.stream().map(HostAndPort::getHost).toArray(), actualHosts);
    alluxioHadoopFs.close();
}
Also used : Path(org.apache.hadoop.fs.Path) Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) BlockLocation(org.apache.hadoop.fs.BlockLocation) LoggerFactory(org.slf4j.LoggerFactory) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) FileStatus(org.apache.hadoop.fs.FileStatus) PropertyKey(alluxio.conf.PropertyKey) Configuration(org.apache.hadoop.conf.Configuration) After(org.junit.After) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ClientContext(alluxio.ClientContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertThrows(org.junit.Assert.assertThrows) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ConfigurationRule(alluxio.ConfigurationRule) Constants(alluxio.Constants) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Before(org.junit.Before) Logger(org.slf4j.Logger) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigurationUtils(alluxio.util.ConfigurationUtils) HostAndPort(com.google.common.net.HostAndPort) Collectors.toList(java.util.stream.Collectors.toList) URIStatus(alluxio.client.file.URIStatus) FileSystemContext(alluxio.client.file.FileSystemContext) FileInfo(alluxio.wire.FileInfo) Closeable(java.io.Closeable) SystemPropertyRule(alluxio.SystemPropertyRule) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FileStatus(org.apache.hadoop.fs.FileStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(org.apache.hadoop.fs.BlockLocation) URIStatus(alluxio.client.file.URIStatus) HostAndPort(com.google.common.net.HostAndPort) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) AlluxioURI(alluxio.AlluxioURI)

Example 28 with FileBlockInfo

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

the class DefaultAsyncPersistHandlerTest method scheduleAsyncPersist.

@Test
public void scheduleAsyncPersist() throws Exception {
    DefaultAsyncPersistHandler handler = new DefaultAsyncPersistHandler(new FileSystemMasterView(mFileSystemMaster));
    AlluxioURI path = new AlluxioURI("/test");
    long blockId = 0;
    long workerId = 1;
    long fileId = 2;
    List<FileBlockInfo> blockInfoList = new ArrayList<>();
    BlockLocation location = new BlockLocation().setWorkerId(workerId);
    blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setBlockId(blockId).setLocations(Lists.newArrayList(location))));
    when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
    when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
    when(mFileSystemMaster.getPath(fileId)).thenReturn(path);
    when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
    handler.scheduleAsyncPersistence(path);
    List<PersistFile> persistFiles = handler.pollFilesToPersist(workerId);
    assertEquals(1, persistFiles.size());
    assertEquals(Lists.newArrayList(blockId), persistFiles.get(0).getBlockIds());
}
Also used : PersistFile(alluxio.wire.PersistFile) 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 29 with FileBlockInfo

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

the class DefaultAsyncPersistHandlerTest method persistenceFileAfterDeletion.

/**
 * Tests persistence after deletion of files.
 */
@Test
public void persistenceFileAfterDeletion() throws Exception {
    DefaultAsyncPersistHandler handler = new DefaultAsyncPersistHandler(new FileSystemMasterView(mFileSystemMaster));
    AlluxioURI path = new AlluxioURI("/test");
    long blockId = 0;
    long workerId = 1;
    long fileId = 2;
    List<FileBlockInfo> blockInfoList = new ArrayList<>();
    BlockLocation location = new BlockLocation().setWorkerId(workerId);
    blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setBlockId(blockId).setLocations(Lists.newArrayList(location))));
    when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
    when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
    when(mFileSystemMaster.getPath(fileId)).thenReturn(path);
    when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
    handler.scheduleAsyncPersistence(path);
    when(mFileSystemMaster.getFileInfo(fileId)).thenThrow(new FileDoesNotExistException("no file"));
    List<PersistFile> persistFiles = handler.pollFilesToPersist(workerId);
    assertEquals(0, persistFiles.size());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileSystemMasterView(alluxio.master.file.meta.FileSystemMasterView) ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) PersistFile(alluxio.wire.PersistFile) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 30 with FileBlockInfo

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

the class ReplicateDefinitionTest method before.

@Before
public void before() throws Exception {
    mMockFileSystemContext = PowerMockito.mock(FileSystemContext.class);
    when(mMockFileSystemContext.getClientContext()).thenReturn(ClientContext.create(ServerConfiguration.global()));
    when(mMockFileSystemContext.getClusterConf()).thenReturn(ServerConfiguration.global());
    mMockBlockStore = PowerMockito.mock(AlluxioBlockStore.class);
    mMockFileSystem = mock(FileSystem.class);
    mMockUfsManager = mock(UfsManager.class);
    mMockJobServerContext = new JobServerContext(mMockFileSystem, mMockFileSystemContext, mMockUfsManager);
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    when(AlluxioBlockStore.create(mMockFileSystemContext)).thenReturn(mMockBlockStore);
    mTestBlockInfo = new BlockInfo().setBlockId(TEST_BLOCK_ID).setLength(TEST_BLOCK_SIZE);
    when(mMockBlockStore.getInfo(TEST_BLOCK_ID)).thenReturn(mTestBlockInfo);
    mTestStatus = new URIStatus(new FileInfo().setPath(TEST_PATH).setBlockIds(Lists.newArrayList(TEST_BLOCK_ID)).setPersisted(true).setFileBlockInfos(Lists.newArrayList(new FileBlockInfo().setBlockInfo(mTestBlockInfo))));
}
Also used : JobServerContext(alluxio.job.JobServerContext) UfsManager(alluxio.underfs.UfsManager) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) FileSystem(alluxio.client.file.FileSystem) FileSystemContext(alluxio.client.file.FileSystemContext) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) Before(org.junit.Before)

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