Search in sources :

Example 1 with HoodieWriteCommitCallbackMessage

use of org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage in project hudi by apache.

the class BaseHoodieWriteClient method commitStats.

public boolean commitStats(String instantTime, List<HoodieWriteStat> stats, Option<Map<String, String>> extraMetadata, String commitActionType, Map<String, List<String>> partitionToReplaceFileIds) {
    // Skip the empty commit if not allowed
    if (!config.allowEmptyCommit() && stats.isEmpty()) {
        return true;
    }
    LOG.info("Committing " + instantTime + " action " + commitActionType);
    // Create a Hoodie table which encapsulated the commits and files visible
    HoodieTable table = createTable(config, hadoopConf);
    HoodieCommitMetadata metadata = CommitUtils.buildMetadata(stats, partitionToReplaceFileIds, extraMetadata, operationType, config.getWriteSchema(), commitActionType);
    HoodieInstant inflightInstant = new HoodieInstant(State.INFLIGHT, table.getMetaClient().getCommitActionType(), instantTime);
    HeartbeatUtils.abortIfHeartbeatExpired(instantTime, table, heartbeatClient, config);
    this.txnManager.beginTransaction(Option.of(inflightInstant), lastCompletedTxnAndMetadata.isPresent() ? Option.of(lastCompletedTxnAndMetadata.get().getLeft()) : Option.empty());
    try {
        preCommit(inflightInstant, metadata);
        commit(table, commitActionType, instantTime, metadata, stats);
        postCommit(table, metadata, instantTime, extraMetadata);
        LOG.info("Committed " + instantTime);
        releaseResources();
    } catch (IOException e) {
        throw new HoodieCommitException("Failed to complete commit " + config.getBasePath() + " at time " + instantTime, e);
    } finally {
        this.txnManager.endTransaction(Option.of(inflightInstant));
    }
    // do this outside of lock since compaction, clustering can be time taking and we don't need a lock for the entire execution period
    runTableServicesInline(table, metadata, extraMetadata);
    emitCommitMetrics(instantTime, metadata, commitActionType);
    // callback if needed.
    if (config.writeCommitCallbackOn()) {
        if (null == commitCallback) {
            commitCallback = HoodieCommitCallbackFactory.create(config);
        }
        commitCallback.call(new HoodieWriteCommitCallbackMessage(instantTime, config.getTableName(), config.getBasePath(), stats));
    }
    return true;
}
Also used : HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieCommitException(org.apache.hudi.exception.HoodieCommitException) HoodieWriteCommitCallbackMessage(org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage) HoodieTable(org.apache.hudi.table.HoodieTable) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Aggregations

IOException (java.io.IOException)1 HoodieWriteCommitCallbackMessage (org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage)1 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)1 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)1 HoodieCommitException (org.apache.hudi.exception.HoodieCommitException)1 HoodieIOException (org.apache.hudi.exception.HoodieIOException)1 HoodieTable (org.apache.hudi.table.HoodieTable)1