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();
}
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;
}
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);
}
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();
}
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();
}
}
Aggregations