Search in sources :

Example 1 with HoodiePendingRollbackInfo

use of org.apache.hudi.common.HoodiePendingRollbackInfo in project hudi by apache.

the class BaseHoodieWriteClient method rollback.

/**
 * @Deprecated
 * Rollback the inflight record changes with the given commit time. This
 * will be removed in future in favor of {@link BaseHoodieWriteClient#restoreToInstant(String)}
 *
 * @param commitInstantTime Instant time of the commit
 * @param pendingRollbackInfo pending rollback instant and plan if rollback failed from previous attempt.
 * @param skipLocking if this is triggered by another parent transaction, locking can be skipped.
 * @throws HoodieRollbackException if rollback cannot be performed successfully
 */
@Deprecated
public boolean rollback(final String commitInstantTime, Option<HoodiePendingRollbackInfo> pendingRollbackInfo, boolean skipLocking) throws HoodieRollbackException {
    LOG.info("Begin rollback of instant " + commitInstantTime);
    final String rollbackInstantTime = pendingRollbackInfo.map(entry -> entry.getRollbackInstant().getTimestamp()).orElse(HoodieActiveTimeline.createNewInstantTime());
    final Timer.Context timerContext = this.metrics.getRollbackCtx();
    try {
        HoodieTable<T, I, K, O> table = createTable(config, hadoopConf);
        Option<HoodieInstant> commitInstantOpt = Option.fromJavaOptional(table.getActiveTimeline().getCommitsTimeline().getInstants().filter(instant -> HoodieActiveTimeline.EQUALS.test(instant.getTimestamp(), commitInstantTime)).findFirst());
        if (commitInstantOpt.isPresent()) {
            LOG.info("Scheduling Rollback at instant time :" + rollbackInstantTime);
            Option<HoodieRollbackPlan> rollbackPlanOption = pendingRollbackInfo.map(entry -> Option.of(entry.getRollbackPlan())).orElseGet(() -> table.scheduleRollback(context, rollbackInstantTime, commitInstantOpt.get(), false, config.shouldRollbackUsingMarkers()));
            if (rollbackPlanOption.isPresent()) {
                // execute rollback
                HoodieRollbackMetadata rollbackMetadata = table.rollback(context, rollbackInstantTime, commitInstantOpt.get(), true, skipLocking);
                if (timerContext != null) {
                    long durationInMs = metrics.getDurationInMs(timerContext.stop());
                    metrics.updateRollbackMetrics(durationInMs, rollbackMetadata.getTotalFilesDeleted());
                }
                return true;
            } else {
                throw new HoodieRollbackException("Failed to rollback " + config.getBasePath() + " commits " + commitInstantTime);
            }
        } else {
            LOG.warn("Cannot find instant " + commitInstantTime + " in the timeline, for rollback");
            return false;
        }
    } catch (Exception e) {
        throw new HoodieRollbackException("Failed to rollback " + config.getBasePath() + " commits " + commitInstantTime, e);
    }
}
Also used : HoodieTable(org.apache.hudi.table.HoodieTable) HoodieRestorePlan(org.apache.hudi.avro.model.HoodieRestorePlan) HoodieFailedWritesCleaningPolicy(org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieException(org.apache.hudi.exception.HoodieException) HoodiePendingRollbackInfo(org.apache.hudi.common.HoodiePendingRollbackInfo) TransactionManager(org.apache.hudi.client.transaction.TransactionManager) Logger(org.apache.log4j.Logger) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) ParseException(java.text.ParseException) HoodieWriteMetadata(org.apache.hudi.table.action.HoodieWriteMetadata) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) SupportsUpgradeDowngrade(org.apache.hudi.table.upgrade.SupportsUpgradeDowngrade) ValidationUtils(org.apache.hudi.common.util.ValidationUtils) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) TableServiceType(org.apache.hudi.common.model.TableServiceType) HoodieMetrics(org.apache.hudi.metrics.HoodieMetrics) RollbackUtils(org.apache.hudi.table.action.rollback.RollbackUtils) HoodieCleanerPlan(org.apache.hudi.avro.model.HoodieCleanerPlan) Collection(java.util.Collection) HoodieClusteringPlan(org.apache.hudi.avro.model.HoodieClusteringPlan) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) Collectors(java.util.stream.Collectors) HoodieIndex(org.apache.hudi.index.HoodieIndex) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) SavepointHelpers(org.apache.hudi.table.action.savepoint.SavepointHelpers) Stream(java.util.stream.Stream) EmbeddedTimelineService(org.apache.hudi.client.embedded.EmbeddedTimelineService) HoodieWriteStat(org.apache.hudi.common.model.HoodieWriteStat) ClusteringUtils(org.apache.hudi.common.util.ClusteringUtils) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) Timer(com.codahale.metrics.Timer) WriteOperationType(org.apache.hudi.common.model.WriteOperationType) HoodieWriteCommitCallbackMessage(org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage) HoodieRestoreException(org.apache.hudi.exception.HoodieRestoreException) Option(org.apache.hudi.common.util.Option) HoodieCommitException(org.apache.hudi.exception.HoodieCommitException) HashMap(java.util.HashMap) HoodieEngineContext(org.apache.hudi.common.engine.HoodieEngineContext) CommitUtils(org.apache.hudi.common.util.CommitUtils) State(org.apache.hudi.common.table.timeline.HoodieInstant.State) AsyncCleanerService(org.apache.hudi.async.AsyncCleanerService) LinkedHashMap(java.util.LinkedHashMap) CleanerUtils(org.apache.hudi.common.util.CleanerUtils) BulkInsertPartitioner(org.apache.hudi.table.BulkInsertPartitioner) HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) UpgradeDowngrade(org.apache.hudi.table.upgrade.UpgradeDowngrade) AsyncArchiveService(org.apache.hudi.async.AsyncArchiveService) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) WriteMarkersFactory(org.apache.hudi.table.marker.WriteMarkersFactory) HoodieSavepointException(org.apache.hudi.exception.HoodieSavepointException) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) IOException(java.io.IOException) HoodieTableVersion(org.apache.hudi.common.table.HoodieTableVersion) TransactionUtils(org.apache.hudi.client.utils.TransactionUtils) HoodieCompactionConfig(org.apache.hudi.config.HoodieCompactionConfig) HoodieRecordPayload(org.apache.hudi.common.model.HoodieRecordPayload) HeartbeatUtils(org.apache.hudi.client.heartbeat.HeartbeatUtils) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) HoodieWriteCommitCallback(org.apache.hudi.callback.HoodieWriteCommitCallback) HoodieCommitCallbackFactory(org.apache.hudi.callback.util.HoodieCommitCallbackFactory) HoodieKey(org.apache.hudi.common.model.HoodieKey) HoodieTableMetadataWriter(org.apache.hudi.metadata.HoodieTableMetadataWriter) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieClusteringConfig(org.apache.hudi.config.HoodieClusteringConfig) LogManager(org.apache.log4j.LogManager) Collections(java.util.Collections) Pair(org.apache.hudi.common.util.collection.Pair) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) HoodieException(org.apache.hudi.exception.HoodieException) ParseException(java.text.ParseException) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HoodieRestoreException(org.apache.hudi.exception.HoodieRestoreException) HoodieCommitException(org.apache.hudi.exception.HoodieCommitException) HoodieSavepointException(org.apache.hudi.exception.HoodieSavepointException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) Timer(com.codahale.metrics.Timer)

Example 2 with HoodiePendingRollbackInfo

use of org.apache.hudi.common.HoodiePendingRollbackInfo in project hudi by apache.

the class BaseHoodieWriteClient method getPendingRollbackInfos.

/**
 * Fetch map of pending commits to be rolled-back to {@link HoodiePendingRollbackInfo}.
 * @param metaClient instance of {@link HoodieTableMetaClient} to use.
 * @return map of pending commits to be rolled-back instants to Rollback Instant and Rollback plan Pair.
 */
protected Map<String, Option<HoodiePendingRollbackInfo>> getPendingRollbackInfos(HoodieTableMetaClient metaClient, boolean ignoreCompactionAndClusteringInstants) {
    List<HoodieInstant> instants = metaClient.getActiveTimeline().filterPendingRollbackTimeline().getInstants().collect(Collectors.toList());
    Map<String, Option<HoodiePendingRollbackInfo>> infoMap = new HashMap<>();
    for (HoodieInstant instant : instants) {
        try {
            HoodieRollbackPlan rollbackPlan = RollbackUtils.getRollbackPlan(metaClient, instant);
            String action = rollbackPlan.getInstantToRollback().getAction();
            if (ignoreCompactionAndClusteringInstants) {
                if (!HoodieTimeline.COMPACTION_ACTION.equals(action)) {
                    boolean isClustering = HoodieTimeline.REPLACE_COMMIT_ACTION.equals(action) && ClusteringUtils.getClusteringPlan(metaClient, new HoodieInstant(true, rollbackPlan.getInstantToRollback().getAction(), rollbackPlan.getInstantToRollback().getCommitTime())).isPresent();
                    if (!isClustering) {
                        String instantToRollback = rollbackPlan.getInstantToRollback().getCommitTime();
                        infoMap.putIfAbsent(instantToRollback, Option.of(new HoodiePendingRollbackInfo(instant, rollbackPlan)));
                    }
                }
            } else {
                infoMap.putIfAbsent(rollbackPlan.getInstantToRollback().getCommitTime(), Option.of(new HoodiePendingRollbackInfo(instant, rollbackPlan)));
            }
        } catch (IOException e) {
            LOG.warn("Fetching rollback plan failed for " + infoMap + ", skip the plan", e);
        }
    }
    return infoMap;
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Option(org.apache.hudi.common.util.Option) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodiePendingRollbackInfo(org.apache.hudi.common.HoodiePendingRollbackInfo)

Aggregations

IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 HoodieRollbackPlan (org.apache.hudi.avro.model.HoodieRollbackPlan)2 HoodiePendingRollbackInfo (org.apache.hudi.common.HoodiePendingRollbackInfo)2 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)2 Option (org.apache.hudi.common.util.Option)2 HoodieIOException (org.apache.hudi.exception.HoodieIOException)2 Timer (com.codahale.metrics.Timer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Configuration (org.apache.hadoop.conf.Configuration)1 AsyncArchiveService (org.apache.hudi.async.AsyncArchiveService)1 AsyncCleanerService (org.apache.hudi.async.AsyncCleanerService)1