Search in sources :

Example 1 with TimelineDiffResult

use of org.apache.hudi.common.table.timeline.TimelineDiffHelper.TimelineDiffResult in project hudi by apache.

the class IncrementalTimelineSyncFileSystemView method runSync.

@Override
protected void runSync(HoodieTimeline oldTimeline, HoodieTimeline newTimeline) {
    try {
        if (incrementalTimelineSyncEnabled) {
            TimelineDiffResult diffResult = TimelineDiffHelper.getNewInstantsForIncrementalSync(oldTimeline, newTimeline);
            if (diffResult.canSyncIncrementally()) {
                LOG.info("Doing incremental sync");
                runIncrementalSync(newTimeline, diffResult);
                LOG.info("Finished incremental sync");
                // Reset timeline to latest
                refreshTimeline(newTimeline);
                return;
            }
        }
    } catch (Exception ioe) {
        LOG.error("Got exception trying to perform incremental sync. Reverting to complete sync", ioe);
    }
    super.runSync(oldTimeline, newTimeline);
}
Also used : TimelineDiffResult(org.apache.hudi.common.table.timeline.TimelineDiffHelper.TimelineDiffResult) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException)

Example 2 with TimelineDiffResult

use of org.apache.hudi.common.table.timeline.TimelineDiffHelper.TimelineDiffResult in project hudi by apache.

the class IncrementalTimelineSyncFileSystemView method runIncrementalSync.

/**
 * Run incremental sync based on the diff result produced.
 *
 * @param timeline New Timeline
 * @param diffResult Timeline Diff Result
 */
private void runIncrementalSync(HoodieTimeline timeline, TimelineDiffResult diffResult) {
    LOG.info("Timeline Diff Result is :" + diffResult);
    // First remove pending compaction instants which were completed
    diffResult.getFinishedCompactionInstants().stream().forEach(instant -> {
        try {
            removePendingCompactionInstant(timeline, instant);
        } catch (IOException e) {
            throw new HoodieException(e);
        }
    });
    // Add new completed instants found in the latest timeline
    diffResult.getNewlySeenInstants().stream().filter(instant -> instant.isCompleted() || instant.getAction().equals(HoodieTimeline.COMPACTION_ACTION)).forEach(instant -> {
        try {
            if (instant.getAction().equals(HoodieTimeline.COMMIT_ACTION) || instant.getAction().equals(HoodieTimeline.DELTA_COMMIT_ACTION)) {
                addCommitInstant(timeline, instant);
            } else if (instant.getAction().equals(HoodieTimeline.RESTORE_ACTION)) {
                addRestoreInstant(timeline, instant);
            } else if (instant.getAction().equals(HoodieTimeline.CLEAN_ACTION)) {
                addCleanInstant(timeline, instant);
            } else if (instant.getAction().equals(HoodieTimeline.COMPACTION_ACTION)) {
                addPendingCompactionInstant(timeline, instant);
            } else if (instant.getAction().equals(HoodieTimeline.ROLLBACK_ACTION)) {
                addRollbackInstant(timeline, instant);
            } else if (instant.getAction().equals(HoodieTimeline.REPLACE_COMMIT_ACTION)) {
                addReplaceInstant(timeline, instant);
            }
        } catch (IOException ioe) {
            throw new HoodieException(ioe);
        }
    });
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) FileSlice(org.apache.hudi.common.model.FileSlice) TimelineDiffHelper(org.apache.hudi.common.table.timeline.TimelineDiffHelper) HoodieException(org.apache.hudi.exception.HoodieException) Option(org.apache.hudi.common.util.Option) FileStatus(org.apache.hadoop.fs.FileStatus) Logger(org.apache.log4j.Logger) HoodieFileGroup(org.apache.hudi.common.model.HoodieFileGroup) CleanerUtils(org.apache.hudi.common.util.CleanerUtils) Map(java.util.Map) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) Path(org.apache.hadoop.fs.Path) HoodieLogFile(org.apache.hudi.common.model.HoodieLogFile) HoodieFileGroupId(org.apache.hudi.common.model.HoodieFileGroupId) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) Set(java.util.Set) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) CompactionOperation(org.apache.hudi.common.model.CompactionOperation) HoodieReplaceCommitMetadata(org.apache.hudi.common.model.HoodieReplaceCommitMetadata) HoodieBaseFile(org.apache.hudi.common.model.HoodieBaseFile) List(java.util.List) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) TimelineDiffResult(org.apache.hudi.common.table.timeline.TimelineDiffHelper.TimelineDiffResult) HoodieWriteStat(org.apache.hudi.common.model.HoodieWriteStat) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) LogManager(org.apache.log4j.LogManager) FSUtils(org.apache.hudi.common.fs.FSUtils) CompactionUtils(org.apache.hudi.common.util.CompactionUtils) Pair(org.apache.hudi.common.util.collection.Pair) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 TimelineDiffResult (org.apache.hudi.common.table.timeline.TimelineDiffHelper.TimelineDiffResult)2 HoodieException (org.apache.hudi.exception.HoodieException)2 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1 HoodieCleanMetadata (org.apache.hudi.avro.model.HoodieCleanMetadata)1 HoodieCompactionPlan (org.apache.hudi.avro.model.HoodieCompactionPlan)1 HoodieRestoreMetadata (org.apache.hudi.avro.model.HoodieRestoreMetadata)1 HoodieRollbackMetadata (org.apache.hudi.avro.model.HoodieRollbackMetadata)1 FSUtils (org.apache.hudi.common.fs.FSUtils)1 CompactionOperation (org.apache.hudi.common.model.CompactionOperation)1 FileSlice (org.apache.hudi.common.model.FileSlice)1 HoodieBaseFile (org.apache.hudi.common.model.HoodieBaseFile)1 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)1 HoodieFileGroup (org.apache.hudi.common.model.HoodieFileGroup)1 HoodieFileGroupId (org.apache.hudi.common.model.HoodieFileGroupId)1