Search in sources :

Example 1 with AlluxioStatusException

use of alluxio.exception.status.AlluxioStatusException in project presto by prestodb.

the class AlluxioHiveMetastore method getPartitionStatistics.

@Override
public Map<String, PartitionStatistics> getPartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Set<String> partitionNames) {
    Table table = getTable(metastoreContext, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    Map<String, HiveBasicStatistics> partitionBasicStatistics = getPartitionsByNames(metastoreContext, databaseName, tableName, ImmutableList.copyOf(partitionNames)).entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(entry -> MetastoreUtil.makePartName(table.getPartitionColumns(), entry.getValue().get().getValues()), entry -> getHiveBasicStatistics(entry.getValue().get().getParameters())));
    Map<String, OptionalLong> partitionRowCounts = partitionBasicStatistics.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().getRowCount()));
    List<String> dataColumns = table.getDataColumns().stream().map(Column::getName).collect(toImmutableList());
    Map<String, List<ColumnStatisticsInfo>> columnStatisticss;
    try {
        columnStatisticss = client.getPartitionColumnStatistics(table.getDatabaseName(), table.getTableName(), partitionBasicStatistics.keySet().stream().collect(toImmutableList()), dataColumns);
    } catch (AlluxioStatusException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
    Map<String, Map<String, HiveColumnStatistics>> partitionColumnStatistics = columnStatisticss.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).collect(toImmutableMap(Map.Entry::getKey, entry -> groupStatisticsByColumn(metastoreContext, entry.getValue(), partitionRowCounts.getOrDefault(entry.getKey(), OptionalLong.empty()))));
    ImmutableMap.Builder<String, PartitionStatistics> result = ImmutableMap.builder();
    for (String partitionName : partitionBasicStatistics.keySet()) {
        HiveBasicStatistics basicStatistics = partitionBasicStatistics.get(partitionName);
        Map<String, HiveColumnStatistics> columnStatistics = partitionColumnStatistics.getOrDefault(partitionName, ImmutableMap.of());
        result.put(partitionName, new PartitionStatistics(basicStatistics, columnStatistics));
    }
    return result.build();
}
Also used : ColumnStatisticsInfo(alluxio.grpc.table.ColumnStatisticsInfo) Table(com.facebook.presto.hive.metastore.Table) NotFoundException(com.facebook.presto.spi.NotFoundException) Column(com.facebook.presto.hive.metastore.Column) Database(com.facebook.presto.hive.metastore.Database) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) HiveMetastore(com.facebook.presto.hive.metastore.thrift.HiveMetastore) PrestoPrincipal(com.facebook.presto.spi.security.PrestoPrincipal) Inject(com.google.inject.Inject) HiveType(com.facebook.presto.hive.HiveType) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) HiveColumnStatistics(com.facebook.presto.hive.metastore.HiveColumnStatistics) PrestoException(com.facebook.presto.spi.PrestoException) MetastoreUtil.convertPredicateToParts(com.facebook.presto.hive.metastore.MetastoreUtil.convertPredicateToParts) Function(java.util.function.Function) Partition(com.facebook.presto.hive.metastore.Partition) Duration(io.airlift.units.Duration) OptionalLong(java.util.OptionalLong) MetastoreUtil(com.facebook.presto.hive.metastore.MetastoreUtil) MetastoreUtil.getHiveBasicStatistics(com.facebook.presto.hive.metastore.MetastoreUtil.getHiveBasicStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HIVE_METASTORE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR) ImmutableList(com.google.common.collect.ImmutableList) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) TableMasterClient(alluxio.client.table.TableMasterClient) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Constraint(alluxio.grpc.table.Constraint) HiveBasicStatistics(com.facebook.presto.hive.HiveBasicStatistics) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) Type(com.facebook.presto.common.type.Type) PartitionNameWithVersion(com.facebook.presto.hive.metastore.PartitionNameWithVersion) ImmutableMap(com.google.common.collect.ImmutableMap) PrincipalPrivileges(com.facebook.presto.hive.metastore.PrincipalPrivileges) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Domain(com.facebook.presto.common.predicate.Domain) PartitionInfo(alluxio.grpc.table.layout.hive.PartitionInfo) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) RoleGrant(com.facebook.presto.spi.security.RoleGrant) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) Optional(java.util.Optional) HivePrivilegeInfo(com.facebook.presto.hive.metastore.HivePrivilegeInfo) Collections(java.util.Collections) Table(com.facebook.presto.hive.metastore.Table) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) PrestoException(com.facebook.presto.spi.PrestoException) HiveColumnStatistics(com.facebook.presto.hive.metastore.HiveColumnStatistics) MetastoreUtil.getHiveBasicStatistics(com.facebook.presto.hive.metastore.MetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(com.facebook.presto.hive.HiveBasicStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 2 with AlluxioStatusException

use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.

the class ClientMasterSync method loadConf.

/**
 * Loads configuration.
 *
 * @return true if successfully loaded configuration
 */
private boolean loadConf() {
    try {
        InetSocketAddress masterAddr = mInquireClient.getPrimaryRpcAddress();
        mContext.loadConf(masterAddr, true, false);
    } catch (UnavailableException e) {
        SAMPLING_LOG.error("Failed to get master address during initialization", e);
        return false;
    } catch (AlluxioStatusException ae) {
        SAMPLING_LOG.error("Failed to load configuration from meta master during initialization", ae);
        return false;
    }
    return true;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException)

Example 3 with AlluxioStatusException

use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.

the class AbstractClient method retryRPCInternal.

private synchronized <V> V retryRPCInternal(RetryPolicy retryPolicy, RpcCallable<V> rpc, Supplier<Void> onRetry) throws AlluxioStatusException {
    Exception ex = null;
    while (retryPolicy.attempt()) {
        if (mClosed) {
            throw new FailedPreconditionException("Client is closed");
        }
        connect();
        try {
            return rpc.call();
        } catch (StatusRuntimeException e) {
            AlluxioStatusException se = AlluxioStatusException.fromStatusRuntimeException(e);
            if (se.getStatusCode() == Status.Code.UNAVAILABLE || se.getStatusCode() == Status.Code.CANCELLED || se.getStatusCode() == Status.Code.UNAUTHENTICATED || e.getCause() instanceof UnresolvedAddressException) {
                ex = se;
            } else {
                throw se;
            }
        }
        LOG.debug("Rpc failed ({}): ", retryPolicy.getAttemptCount(), ex);
        onRetry.get();
        disconnect();
    }
    throw new UnavailableException("Failed after " + retryPolicy.getAttemptCount() + " attempts: " + ex.toString(), ex);
}
Also used : FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) StatusRuntimeException(io.grpc.StatusRuntimeException) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) StatusRuntimeException(io.grpc.StatusRuntimeException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 4 with AlluxioStatusException

use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.

the class RestUtils method createErrorResponse.

/**
 * Creates an error response using the given exception.
 *
 * @param e the exception to be converted into {@link ErrorResponse} and encoded into json
 * @return the response
 */
private static Response createErrorResponse(Exception e, AlluxioConfiguration alluxioConf) {
    AlluxioStatusException se = AlluxioStatusException.fromThrowable(e);
    ErrorResponse response = new ErrorResponse(se.getStatus().getCode(), se.getMessage());
    Response.ResponseBuilder rb = Response.serverError().entity(response);
    if (alluxioConf.getBoolean(PropertyKey.WEB_CORS_ENABLED)) {
        return makeCORS(rb).build();
    }
    return rb.build();
}
Also used : Response(javax.ws.rs.core.Response) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException)

Example 5 with AlluxioStatusException

use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.

the class FileSystemContext method reinit.

/**
 * Closes the context, updates configuration from meta master, then re-initializes the context.
 *
 * The reinitializer is not closed, which means the heartbeat thread inside it is not stopped.
 * The reinitializer will be reset with the updated context if reinitialization succeeds,
 * otherwise, the reinitializer is not reset.
 *
 * Blocks until there is no active RPCs.
 *
 * @param updateClusterConf whether cluster level configuration should be updated
 * @param updatePathConf whether path level configuration should be updated
 * @throws UnavailableException when failed to load configuration from master
 * @throws IOException when failed to close the context
 */
public void reinit(boolean updateClusterConf, boolean updatePathConf) throws UnavailableException, IOException {
    try (Closeable r = mReinitializer.allow()) {
        InetSocketAddress masterAddr;
        try {
            masterAddr = getMasterAddress();
        } catch (IOException e) {
            throw new UnavailableException("Failed to get master address during reinitialization", e);
        }
        try {
            getClientContext().loadConf(masterAddr, updateClusterConf, updatePathConf);
        } catch (AlluxioStatusException e) {
            // will try to reinitialize in the next heartbeat.
            throw new UnavailableException(String.format("Failed to load configuration from " + "meta master (%s) during reinitialization", masterAddr), e);
        }
        LOG.debug("Reinitializing FileSystemContext: update cluster conf: {}, update path conf:" + " {}", updateClusterConf, updateClusterConf);
        closeContext();
        ReconfigurableRegistry.update();
        initContext(getClientContext(), MasterInquireClient.Factory.create(getClusterConf(), getClientContext().getUserState()));
        LOG.debug("FileSystemContext re-initialized");
        mReinitializer.onSuccess();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Closeable(java.io.Closeable) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) IOException(java.io.IOException)

Aggregations

AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)20 UnavailableException (alluxio.exception.status.UnavailableException)9 IOException (java.io.IOException)5 TableMasterClient (alluxio.client.table.TableMasterClient)3 UnauthenticatedException (alluxio.exception.status.UnauthenticatedException)3 ColumnStatisticsInfo (alluxio.grpc.table.ColumnStatisticsInfo)3 Constraint (alluxio.grpc.table.Constraint)3 PartitionInfo (alluxio.grpc.table.layout.hive.PartitionInfo)3 RetryPolicy (alluxio.retry.RetryPolicy)3 Domain (com.facebook.presto.common.predicate.Domain)3 Type (com.facebook.presto.common.type.Type)3 HiveBasicStatistics (com.facebook.presto.hive.HiveBasicStatistics)3 HIVE_METASTORE_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR)3 HiveType (com.facebook.presto.hive.HiveType)3 Column (com.facebook.presto.hive.metastore.Column)3 Database (com.facebook.presto.hive.metastore.Database)3 ExtendedHiveMetastore (com.facebook.presto.hive.metastore.ExtendedHiveMetastore)3 HiveColumnStatistics (com.facebook.presto.hive.metastore.HiveColumnStatistics)3 HivePrivilegeInfo (com.facebook.presto.hive.metastore.HivePrivilegeInfo)3 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)3