Search in sources :

Example 1 with MetacatUpdateIcebergTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateIcebergTablePostEvent in project metacat by Netflix.

the class TableServiceImpl method updateAndReturn.

/**
 * {@inheritDoc}
 */
@Override
public TableDto updateAndReturn(final QualifiedName name, final TableDto tableDto) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final TableDto oldTable = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElseThrow(() -> new TableNotFoundException(name));
    eventBus.post(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, oldTable, tableDto));
    // 
    // Check if the table schema info is provided. If provided, we should continue calling the update on the table
    // schema. Uri may exist in the serde when updating data metadata for a table.
    // 
    boolean ignoreErrorsAfterUpdate = false;
    if (isTableInfoProvided(tableDto, oldTable)) {
        ignoreErrorsAfterUpdate = connectorTableServiceProxy.update(name, converterUtil.fromTableDto(tableDto));
    }
    try {
        // Merge in metadata if the user sent any
        if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
            log.info("Saving user metadata for table {}", name);
            final long start = registry.clock().wallTime();
            userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
            final long duration = registry.clock().wallTime() - start;
            log.info("Time taken to save user metadata for table {} is {} ms", name, duration);
            registry.timer(registry.createId(Metrics.TimerSaveTableMetadata.getMetricName()).withTags(name.parts())).record(duration, TimeUnit.MILLISECONDS);
        }
    } catch (Exception e) {
        handleException(name, ignoreErrorsAfterUpdate, "saveMetadata", e);
    }
    // ignoreErrorsAfterUpdate is currently set only for iceberg tables
    if (config.isUpdateIcebergTableAsyncPostEventEnabled() && ignoreErrorsAfterUpdate) {
        eventBus.post(new MetacatUpdateIcebergTablePostEvent(name, metacatRequestContext, this, oldTable, tableDto));
        return tableDto;
    } else {
        TableDto updatedDto = tableDto;
        try {
            updatedDto = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElse(tableDto);
        } catch (Exception e) {
            handleException(name, ignoreErrorsAfterUpdate, "getTable", e);
        }
        try {
            eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto, updatedDto != tableDto));
        } catch (Exception e) {
            handleException(name, ignoreErrorsAfterUpdate, "postEvent", e);
        }
        return updatedDto;
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatUpdateIcebergTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateIcebergTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)1 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 MetacatUpdateIcebergTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateIcebergTablePostEvent)1 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)1 MetacatUpdateTablePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)1