Search in sources :

Example 1 with BlockLocationInfo

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

the class BaseFileSystem method getBlockLocations.

@Override
public List<BlockLocationInfo> getBlockLocations(AlluxioURI path) throws IOException, AlluxioException {
    List<BlockLocationInfo> blockLocations = new ArrayList<>();
    // Don't need to checkUri here because we call other client operations
    List<FileBlockInfo> blocks = getStatus(path).getFileBlockInfos();
    for (FileBlockInfo fileBlockInfo : blocks) {
        // add the existing in-Alluxio block locations
        List<WorkerNetAddress> locations = fileBlockInfo.getBlockInfo().getLocations().stream().map(BlockLocation::getWorkerAddress).collect(toList());
        if (locations.isEmpty()) {
            // No in-Alluxio location
            if (!fileBlockInfo.getUfsLocations().isEmpty()) {
                // Case 1: Fallback to use under file system locations with co-located workers.
                // This maps UFS locations to a worker which is co-located.
                Map<String, WorkerNetAddress> finalWorkerHosts = getHostWorkerMap();
                locations = fileBlockInfo.getUfsLocations().stream().map(location -> finalWorkerHosts.get(HostAndPort.fromString(location).getHost())).filter(Objects::nonNull).collect(toList());
            }
            if (locations.isEmpty() && mFsContext.getPathConf(path).getBoolean(PropertyKey.USER_UFS_BLOCK_LOCATION_ALL_FALLBACK_ENABLED)) {
                // Case 2: Fallback to add all workers to locations so some apps (Impala) won't panic.
                locations.addAll(getHostWorkerMap().values());
                Collections.shuffle(locations);
            }
        }
        blockLocations.add(new BlockLocationInfo(fileBlockInfo, locations));
    }
    return blockLocations;
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) LoggerFactory(org.slf4j.LoggerFactory) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) FreePOptions(alluxio.grpc.FreePOptions) InvalidPathException(alluxio.exception.InvalidPathException) Collectors.toMap(java.util.stream.Collectors.toMap) CloseableResource(alluxio.resource.CloseableResource) SetAclPOptions(alluxio.grpc.SetAclPOptions) SyncPointInfo(alluxio.wire.SyncPointInfo) Map(java.util.Map) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) ExistsPOptions(alluxio.grpc.ExistsPOptions) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) AlluxioException(alluxio.exception.AlluxioException) Bits(alluxio.grpc.Bits) ThreadSafe(javax.annotation.concurrent.ThreadSafe) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) Objects(java.util.Objects) List(java.util.List) UnmountPOptions(alluxio.grpc.UnmountPOptions) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LoadMetadataPType(alluxio.grpc.LoadMetadataPType) CheckAccessPOptions(alluxio.grpc.CheckAccessPOptions) UnavailableException(alluxio.exception.status.UnavailableException) MountPointInfo(alluxio.wire.MountPointInfo) AlreadyExistsException(alluxio.exception.status.AlreadyExistsException) Authority(alluxio.uri.Authority) SetAclAction(alluxio.grpc.SetAclAction) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) GetStatusPOptions(alluxio.grpc.GetStatusPOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) ArrayList(java.util.ArrayList) DeletePOptions(alluxio.grpc.DeletePOptions) ReinitBlockerResource(alluxio.client.file.FileSystemContextReinitializer.ReinitBlockerResource) Constants(alluxio.Constants) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) Closer(com.google.common.io.Closer) AlluxioURI(alluxio.AlluxioURI) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) MountPOptions(alluxio.grpc.MountPOptions) RenamePOptions(alluxio.grpc.RenamePOptions) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) Logger(org.slf4j.Logger) InStreamOptions(alluxio.client.file.options.InStreamOptions) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) ScheduleAsyncPersistencePOptions(alluxio.grpc.ScheduleAsyncPersistencePOptions) IOException(java.io.IOException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) NotFoundException(alluxio.exception.status.NotFoundException) HostAndPort(com.google.common.net.HostAndPort) FileIncompleteException(alluxio.exception.FileIncompleteException) Consumer(java.util.function.Consumer) BlockLocation(alluxio.wire.BlockLocation) Collectors.toList(java.util.stream.Collectors.toList) MasterInquireClient(alluxio.master.MasterInquireClient) OpenDirectoryException(alluxio.exception.OpenDirectoryException) Preconditions(com.google.common.base.Preconditions) AclEntry(alluxio.security.authorization.AclEntry) BlockLocationInfo(alluxio.wire.BlockLocationInfo) Collections(java.util.Collections) FileSystemOptions(alluxio.util.FileSystemOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArrayList(java.util.ArrayList) Objects(java.util.Objects) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocationInfo(alluxio.wire.BlockLocationInfo)

Example 2 with BlockLocationInfo

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

the class FileSystemIntegrationTest method getBlockLocations.

@Test
public void getBlockLocations() throws Exception {
    // Test not in alluxio
    AlluxioURI testFile = new AlluxioURI("/test1");
    FileSystemTestUtils.createByteFile(mFileSystem, testFile, CreateFilePOptions.newBuilder().setWriteType(WritePType.THROUGH).setBlockSizeBytes(4).build(), 100);
    List<BlockLocationInfo> locations = mFileSystem.getBlockLocations(testFile);
    assertEquals("should have 25 blocks", 25, locations.size());
    long lastOffset = -1;
    for (BlockLocationInfo location : locations) {
        assertEquals("block " + location.getBlockInfo() + " should have single worker", 1, location.getLocations().size());
        assertTrue("block " + location.getBlockInfo() + " should have offset larger than " + lastOffset, location.getBlockInfo().getOffset() > lastOffset);
        lastOffset = location.getBlockInfo().getOffset();
    }
    // Test in alluxio
    testFile = new AlluxioURI("/test2");
    FileSystemTestUtils.createByteFile(mFileSystem, testFile, CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setBlockSizeBytes(100).build(), 500);
    locations = mFileSystem.getBlockLocations(testFile);
    assertEquals("Should have 5 blocks", 5, locations.size());
    lastOffset = -1;
    for (BlockLocationInfo location : locations) {
        assertEquals("block " + location.getBlockInfo() + " should have single worker", 1, location.getLocations().size());
        assertTrue("block " + location.getBlockInfo() + " should have offset larger than " + lastOffset, location.getBlockInfo().getOffset() > lastOffset);
        lastOffset = location.getBlockInfo().getOffset();
    }
}
Also used : BlockLocationInfo(alluxio.wire.BlockLocationInfo) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 3 with BlockLocationInfo

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

Aggregations

AlluxioURI (alluxio.AlluxioURI)3 BlockLocationInfo (alluxio.wire.BlockLocationInfo)3 Constants (alluxio.Constants)2 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)2 PropertyKey (alluxio.conf.PropertyKey)2 AlluxioException (alluxio.exception.AlluxioException)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 CheckAccessPOptions (alluxio.grpc.CheckAccessPOptions)2 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)2 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)2 DeletePOptions (alluxio.grpc.DeletePOptions)2 ClientContext (alluxio.ClientContext)1 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 FileOutStream (alluxio.client.file.FileOutStream)1 FileSystem (alluxio.client.file.FileSystem)1 ReinitBlockerResource (alluxio.client.file.FileSystemContextReinitializer.ReinitBlockerResource)1 URIStatus (alluxio.client.file.URIStatus)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1