Search in sources :

Example 1 with TablePreconditionFailedException

use of com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException in project metacat by Netflix.

the class HiveConnectorFastTableService method update.

/**
 * Update a table with the given metadata.
 *
 * If table is an iceberg table, then lock the table for update so that no other request can update it. If the meta
 * information is invalid, then throw an error.
 * If table is not an iceberg table, then do a regular table update.
 *
 * @param requestContext The request context
 * @param tableInfo      The resource metadata
 */
@Override
public void update(final ConnectorRequestContext requestContext, final TableInfo tableInfo) {
    if (isIcebergTable(tableInfo)) {
        final QualifiedName tableName = tableInfo.getName();
        final Long tableId = directSqlTable.getTableId(tableName);
        try {
            log.debug("Locking Iceberg table {}", tableName);
            directSqlTable.lockIcebergTable(tableId, tableName);
            try {
                final TableInfo existingTableInfo = get(requestContext, tableInfo.getName());
                validateIcebergUpdate(existingTableInfo, tableInfo);
                final Table existingTable = getHiveMetacatConverters().fromTableInfo(existingTableInfo);
                super.update(requestContext, existingTable, tableInfo);
            } finally {
                directSqlTable.unlockIcebergTable(tableId);
                log.debug("Unlocked Iceberg table {}", tableName);
            }
        } catch (IllegalStateException e) {
            throw new TablePreconditionFailedException(tableName, e.getMessage());
        }
    } else {
        super.update(requestContext, tableInfo);
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) QualifiedName(com.netflix.metacat.common.QualifiedName) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo)

Example 2 with TablePreconditionFailedException

use of com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException in project metacat by Netflix.

the class RequestWrapper method processRequest.

/**
 * Request wrapper to to process request.
 *
 * @param name                name
 * @param resourceRequestName request name
 * @param supplier            supplier
 * @param <R>                 response
 * @return response of supplier
 */
public <R> R processRequest(final QualifiedName name, final String resourceRequestName, final Supplier<R> supplier) {
    final long start = registry.clock().wallTime();
    final Map<String, String> tags = new HashMap<>(name.parts());
    tags.put("request", resourceRequestName);
    registry.counter(requestCounterId.withTags(tags)).increment();
    try {
        log.info("### Calling method: {} for {}", resourceRequestName, name);
        return supplier.get();
    } catch (UnsupportedOperationException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatNotSupportedException("Catalog does not support the operation");
    } catch (DatabaseAlreadyExistsException | TableAlreadyExistsException | PartitionAlreadyExistsException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatAlreadyExistsException(e.getMessage());
    } catch (NotFoundException | MetacatNotFoundException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
    } catch (InvalidMetaException | IllegalArgumentException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (TablePreconditionFailedException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatPreconditionFailedException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (ConnectorException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        throw new MetacatException(message, e);
    } catch (UserMetadataServiceException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s usermetadata operation failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        throw new MetacatUserMetadataException(message);
    } catch (Exception e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        throw new MetacatException(message, e);
    } finally {
        final long duration = registry.clock().wallTime() - start;
        log.info("### Time taken to complete {} for {} is {} ms", resourceRequestName, name, duration);
        this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
    }
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) HashMap(java.util.HashMap) MetacatException(com.netflix.metacat.common.exception.MetacatException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) MetacatPreconditionFailedException(com.netflix.metacat.common.exception.MetacatPreconditionFailedException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) MetacatException(com.netflix.metacat.common.exception.MetacatException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatPreconditionFailedException(com.netflix.metacat.common.exception.MetacatPreconditionFailedException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException)

Aggregations

TablePreconditionFailedException (com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException)2 QualifiedName (com.netflix.metacat.common.QualifiedName)1 MetacatAlreadyExistsException (com.netflix.metacat.common.exception.MetacatAlreadyExistsException)1 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)1 MetacatException (com.netflix.metacat.common.exception.MetacatException)1 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 MetacatPreconditionFailedException (com.netflix.metacat.common.exception.MetacatPreconditionFailedException)1 MetacatUserMetadataException (com.netflix.metacat.common.exception.MetacatUserMetadataException)1 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)1 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)1 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)1 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)1 PartitionAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)1 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)1 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)1 UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)1 HashMap (java.util.HashMap)1 Table (org.apache.hadoop.hive.metastore.api.Table)1