Search in sources :

Example 11 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class BlockInStream method create.

/**
 * Creates a {@link BlockInStream}.
 *
 * One of several read behaviors:
 *
 * 1. Domain socket - if the data source is the local worker and the local worker has a domain
 * socket server
 * 2. Short-Circuit - if the data source is the local worker
 * 3. Local Loopback Read - if the data source is the local worker and short circuit is disabled
 * 4. Read from remote worker - if the data source is a remote worker
 * 5. UFS Read from worker - if the data source is UFS, read from the UFS policy's designated
 * worker (ufs -> local or remote worker -> client)
 *
 * @param context the file system context
 * @param info the block info
 * @param dataSource the Alluxio worker which should read the data
 * @param dataSourceType the source location of the block
 * @param options the instream options
 * @return the {@link BlockInStream} object
 */
public static BlockInStream create(FileSystemContext context, BlockInfo info, WorkerNetAddress dataSource, BlockInStreamSource dataSourceType, InStreamOptions options) throws IOException {
    long blockId = info.getBlockId();
    long blockSize = info.getLength();
    if (dataSourceType == BlockInStreamSource.PROCESS_LOCAL) {
        // Interaction between the current client and the worker it embedded to should
        // go through worker internal communication directly without RPC involves
        LOG.debug("Creating worker process local input stream for block {} @ {}", blockId, dataSource);
        return createProcessLocalBlockInStream(context, dataSource, blockId, blockSize, options);
    }
    AlluxioConfiguration alluxioConf = context.getClusterConf();
    boolean shortCircuit = alluxioConf.getBoolean(PropertyKey.USER_SHORT_CIRCUIT_ENABLED);
    boolean shortCircuitPreferred = alluxioConf.getBoolean(PropertyKey.USER_SHORT_CIRCUIT_PREFERRED);
    boolean sourceSupportsDomainSocket = NettyUtils.isDomainSocketSupported(dataSource);
    boolean sourceIsLocal = dataSourceType == BlockInStreamSource.NODE_LOCAL;
    // OR alluxio.user.short.circuit.preferred is true
    if (sourceIsLocal && shortCircuit && (shortCircuitPreferred || !sourceSupportsDomainSocket)) {
        LOG.debug("Creating short circuit input stream for block {} @ {}", blockId, dataSource);
        try {
            return createLocalBlockInStream(context, dataSource, blockId, blockSize, options);
        } catch (NotFoundException e) {
            // Failed to do short circuit read because the block is not available in Alluxio.
            // We will try to read via gRPC. So this exception is ignored.
            LOG.warn("Failed to create short circuit input stream for block {} @ {}. Falling back to " + "network transfer", blockId, dataSource);
        }
    }
    // gRPC
    LOG.debug("Creating gRPC input stream for block {} @ {} from client {} reading through {} (" + "data locates in the local worker {}, shortCircuitEnabled {}, " + "shortCircuitPreferred {}, sourceSupportDomainSocket {})", blockId, dataSource, NetworkAddressUtils.getClientHostName(alluxioConf), dataSource, sourceIsLocal, shortCircuit, shortCircuitPreferred, sourceSupportsDomainSocket);
    return createGrpcBlockInStream(context, dataSource, dataSourceType, blockId, blockSize, options);
}
Also used : NotFoundException(alluxio.exception.status.NotFoundException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Example 12 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class BlockInStream method createGrpcBlockInStream.

/**
 * Creates a {@link BlockInStream} to read from a gRPC data server.
 *
 * @param context the file system context
 * @param address the address of the gRPC data server
 * @param blockSource the source location of the block
 * @param blockSize the block size
 * @param blockId the block id
 * @return the {@link BlockInStream} created
 */
private static BlockInStream createGrpcBlockInStream(FileSystemContext context, WorkerNetAddress address, BlockInStreamSource blockSource, long blockId, long blockSize, InStreamOptions options) {
    AlluxioConfiguration conf = context.getClusterConf();
    long chunkSize = conf.getBytes(PropertyKey.USER_STREAMING_READER_CHUNK_SIZE_BYTES);
    // Construct the partial read request
    ReadRequest.Builder builder = ReadRequest.newBuilder().setBlockId(blockId).setPromote(ReadType.fromProto(options.getOptions().getReadType()).isPromote()).setOpenUfsBlockOptions(// Add UFS fallback options
    options.getOpenUfsBlockOptions(blockId)).setPositionShort(options.getPositionShort()).setChunkSize(chunkSize);
    DataReader.Factory factory;
    if (context.getClusterConf().getBoolean(PropertyKey.FUSE_SHARED_CACHING_READER_ENABLED) && blockSize > chunkSize * 4) {
        // Heuristic to resolve issues/12146, guarded by alluxio.fuse.shared.caching.reader.enabled
        // GrpcDataReader instances are shared across FileInStreams to mitigate seek cost
        factory = new SharedGrpcDataReader.Factory(context, address, builder, blockSize);
    } else {
        factory = new GrpcDataReader.Factory(context, address, builder);
    }
    return new BlockInStream(factory, conf, address, blockSource, blockId, blockSize);
}
Also used : AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) ReadRequest(alluxio.grpc.ReadRequest)

Example 13 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class ConfigurationUtils method getPathConf.

/**
 * Loads the path level configuration from the get configuration response.
 *
 * Only client scope properties will be loaded.
 *
 * @param response the get configuration RPC response
 * @param clusterConf cluster level configuration
 * @return the loaded path level configuration
 */
public static PathConfiguration getPathConf(GetConfigurationPResponse response, AlluxioConfiguration clusterConf) {
    String clientVersion = clusterConf.getString(PropertyKey.VERSION);
    LOG.debug("Alluxio client (version {}) is trying to load path level configurations", clientVersion);
    Map<String, AlluxioConfiguration> pathConfs = new HashMap<>();
    response.getPathConfigsMap().forEach((path, conf) -> {
        Properties props = filterAndLoadProperties(conf.getPropertiesList(), Scope.CLIENT, (key, value) -> String.format("Loading property: %s (%s) -> %s for path %s", key, key.getScope(), value, path));
        AlluxioProperties properties = new AlluxioProperties();
        properties.merge(props, Source.PATH_DEFAULT);
        pathConfs.put(path, new InstancedConfiguration(properties, true));
    });
    LOG.debug("Alluxio client has loaded path level configurations");
    return PathConfiguration.create(pathConfs);
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) AlluxioProperties(alluxio.conf.AlluxioProperties) HashMap(java.util.HashMap) AlluxioProperties(alluxio.conf.AlluxioProperties) Properties(java.util.Properties) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Example 14 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class ConfigurationUtils method getConfiguration.

/**
 * Gets all configuration properties filtered by the specified scope.
 *
 * @param conf the configuration to use
 * @param scope the scope to filter by
 * @return the properties
 */
public static List<ConfigProperty> getConfiguration(AlluxioConfiguration conf, Scope scope) {
    ConfigurationValueOptions useRawDisplayValue = ConfigurationValueOptions.defaults().useDisplayValue(true);
    List<ConfigProperty> configs = new ArrayList<>();
    List<PropertyKey> selectedKeys = conf.keySet().stream().filter(key -> GrpcUtils.contains(key.getScope(), scope)).filter(key -> key.isValid(key.getName())).collect(toList());
    for (PropertyKey key : selectedKeys) {
        ConfigProperty.Builder configProp = ConfigProperty.newBuilder().setName(key.getName()).setSource(conf.getSource(key).toString());
        if (conf.isSet(key)) {
            configProp.setValue(String.valueOf(conf.get(key, useRawDisplayValue)));
        }
        configs.add(configProp.build());
    }
    return configs;
}
Also used : Arrays(java.util.Arrays) URL(java.net.URL) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) PropertyKey(alluxio.conf.PropertyKey) MetaMasterConfigurationServiceGrpc(alluxio.grpc.MetaMasterConfigurationServiceGrpc) GrpcChannel(alluxio.grpc.GrpcChannel) Map(java.util.Map) Splitter(com.google.common.base.Splitter) ServiceType(alluxio.util.network.NetworkAddressUtils.ServiceType) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) GrpcServerAddress(alluxio.grpc.GrpcServerAddress) CommandUtils(alluxio.cli.CommandUtils) Set(java.util.Set) ConfigProperty(alluxio.grpc.ConfigProperty) GuardedBy(javax.annotation.concurrent.GuardedBy) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) AlluxioProperties(alluxio.conf.AlluxioProperties) Sets(com.google.common.collect.Sets) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Source(alluxio.conf.Source) InstancedConfiguration(alluxio.conf.InstancedConfiguration) RuntimeConstants(alluxio.RuntimeConstants) UnavailableException(alluxio.exception.status.UnavailableException) GetConfigurationPOptions(alluxio.grpc.GetConfigurationPOptions) HashMap(java.util.HashMap) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) Scope(alluxio.grpc.Scope) ArrayList(java.util.ArrayList) PathUtils(alluxio.util.io.PathUtils) GetConfigurationPResponse(alluxio.grpc.GetConfigurationPResponse) Lists(com.google.common.collect.Lists) Constants(alluxio.Constants) GrpcUtils(alluxio.grpc.GrpcUtils) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) Nullable(javax.annotation.Nullable) ConfigurationValueOptions(alluxio.conf.ConfigurationValueOptions) Logger(org.slf4j.Logger) Properties(java.util.Properties) PathConfiguration(alluxio.conf.path.PathConfiguration) ExceptionMessage(alluxio.exception.ExceptionMessage) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors.toList(java.util.stream.Collectors.toList) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Preconditions(com.google.common.base.Preconditions) InputStream(java.io.InputStream) ConfigurationValueOptions(alluxio.conf.ConfigurationValueOptions) ConfigProperty(alluxio.grpc.ConfigProperty) ArrayList(java.util.ArrayList) PropertyKey(alluxio.conf.PropertyKey)

Example 15 with AlluxioConfiguration

use of alluxio.conf.AlluxioConfiguration in project alluxio by Alluxio.

the class MetricsSystem method constructSourceName.

/**
 * Constructs the source name of metrics in this {@link MetricsSystem}.
 */
private static String constructSourceName() {
    PropertyKey sourceKey = null;
    switch(CommonUtils.PROCESS_TYPE.get()) {
        case MASTER:
            sourceKey = PropertyKey.MASTER_HOSTNAME;
            break;
        case WORKER:
            sourceKey = PropertyKey.WORKER_HOSTNAME;
            break;
        case CLIENT:
            sourceKey = PropertyKey.USER_APP_ID;
            break;
        case JOB_MASTER:
            sourceKey = PropertyKey.JOB_MASTER_HOSTNAME;
            break;
        case JOB_WORKER:
            sourceKey = PropertyKey.JOB_WORKER_HOSTNAME;
            break;
        default:
            break;
    }
    AlluxioConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
    if (sourceKey != null && conf.isSet(sourceKey)) {
        return conf.getString(sourceKey);
    }
    String hostName;
    // is not resolved on metrics reporting
    try {
        hostName = NetworkAddressUtils.getLocalHostMetricName(sResolveTimeout);
    } catch (RuntimeException e) {
        hostName = "unknown";
        LOG.error("Can't find local host name", e);
    }
    return hostName;
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) PropertyKey(alluxio.conf.PropertyKey) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Aggregations

AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)62 Test (org.junit.Test)20 InstancedConfiguration (alluxio.conf.InstancedConfiguration)17 IOException (java.io.IOException)11 AlluxioURI (alluxio.AlluxioURI)7 UnderFileSystemFactory (alluxio.underfs.UnderFileSystemFactory)7 ArrayList (java.util.ArrayList)7 AlluxioProperties (alluxio.conf.AlluxioProperties)5 PropertyKey (alluxio.conf.PropertyKey)5 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)5 HealthCheckClient (alluxio.HealthCheckClient)4 FileSystemContext (alluxio.client.file.FileSystemContext)4 InStreamOptions (alluxio.client.file.options.InStreamOptions)4 InetSocketAddress (java.net.InetSocketAddress)4 Constants (alluxio.Constants)3 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)3 FileSystem (alluxio.client.file.FileSystem)3 URIStatus (alluxio.client.file.URIStatus)3 ReadRequest (alluxio.grpc.ReadRequest)3 InputStream (java.io.InputStream)3