Search in sources :

Example 6 with HoodieRollbackMetadata

use of org.apache.hudi.avro.model.HoodieRollbackMetadata in project hudi by apache.

the class HoodieTestTable method doRollback.

public HoodieTestTable doRollback(String commitTimeToRollback, String commitTime) throws Exception {
    metaClient = HoodieTableMetaClient.reload(metaClient);
    Option<HoodieCommitMetadata> commitMetadata = getMetadataForInstant(commitTimeToRollback);
    if (!commitMetadata.isPresent()) {
        throw new IllegalArgumentException("Instant to rollback not present in timeline: " + commitTimeToRollback);
    }
    Map<String, List<String>> partitionFiles = getPartitionFiles(commitMetadata.get());
    HoodieRollbackMetadata rollbackMetadata = getRollbackMetadata(commitTimeToRollback, partitionFiles);
    for (Map.Entry<String, List<String>> entry : partitionFiles.entrySet()) {
        deleteFilesInPartition(entry.getKey(), entry.getValue());
    }
    return addRollback(commitTime, rollbackMetadata);
}
Also used : HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) CollectionUtils.createImmutableMap(org.apache.hudi.common.util.CollectionUtils.createImmutableMap) HashMap(java.util.HashMap)

Example 7 with HoodieRollbackMetadata

use of org.apache.hudi.avro.model.HoodieRollbackMetadata in project hudi by apache.

the class RollbacksCommand method showRollback.

@CliCommand(value = "show rollback", help = "Show details of a rollback instant")
public String showRollback(@CliOption(key = { "instant" }, help = "Rollback instant", mandatory = true) String rollbackInstant, @CliOption(key = { "limit" }, help = "Limit  #rows to be displayed", unspecifiedDefaultValue = "10") Integer limit, @CliOption(key = { "sortBy" }, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = { "desc" }, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = { "headeronly" }, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException {
    HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient());
    final List<Comparable[]> rows = new ArrayList<>();
    HoodieRollbackMetadata metadata = TimelineMetadataUtils.deserializeAvroMetadata(activeTimeline.getInstantDetails(new HoodieInstant(State.COMPLETED, ROLLBACK_ACTION, rollbackInstant)).get(), HoodieRollbackMetadata.class);
    metadata.getPartitionMetadata().forEach((key, value) -> Stream.concat(value.getSuccessDeleteFiles().stream().map(f -> Pair.of(f, true)), value.getFailedDeleteFiles().stream().map(f -> Pair.of(f, false))).forEach(fileWithDeleteStatus -> {
        Comparable[] row = new Comparable[5];
        row[0] = metadata.getStartRollbackTime();
        row[1] = metadata.getCommitsRollback().toString();
        row[2] = key;
        row[3] = fileWithDeleteStatus.getLeft();
        row[4] = fileWithDeleteStatus.getRight();
        rows.add(row);
    }));
    TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT).addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT).addTableHeaderField(HoodieTableHeaderFields.HEADER_PARTITION).addTableHeaderField(HoodieTableHeaderFields.HEADER_DELETED_FILE).addTableHeaderField(HoodieTableHeaderFields.HEADER_SUCCEEDED);
    return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows);
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) CliCommand(org.springframework.shell.core.annotation.CliCommand) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) TableHeader(org.apache.hudi.cli.TableHeader) CollectionUtils(org.apache.hudi.common.util.CollectionUtils) HoodieTableHeaderFields(org.apache.hudi.cli.HoodieTableHeaderFields) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) CliOption(org.springframework.shell.core.annotation.CliOption) State(org.apache.hudi.common.table.timeline.HoodieInstant.State) ArrayList(java.util.ArrayList) HoodieCLI(org.apache.hudi.cli.HoodieCLI) Component(org.springframework.stereotype.Component) List(java.util.List) Stream(java.util.stream.Stream) HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) ROLLBACK_ACTION(org.apache.hudi.common.table.timeline.HoodieTimeline.ROLLBACK_ACTION) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodiePrintHelper(org.apache.hudi.cli.HoodiePrintHelper) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) Pair(org.apache.hudi.common.util.collection.Pair) CommandMarker(org.springframework.shell.core.CommandMarker) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) TableHeader(org.apache.hudi.cli.TableHeader) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) ArrayList(java.util.ArrayList) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 8 with HoodieRollbackMetadata

use of org.apache.hudi.avro.model.HoodieRollbackMetadata in project hudi by apache.

the class HoodieBackedTableMetadata method getRollbackedCommits.

/**
 * Returns a list of commits which were rolled back as part of a Rollback or Restore operation.
 *
 * @param instant  The Rollback operation to read
 * @param timeline instant of timeline from dataset.
 */
private List<String> getRollbackedCommits(HoodieInstant instant, HoodieActiveTimeline timeline) {
    try {
        if (instant.getAction().equals(HoodieTimeline.ROLLBACK_ACTION)) {
            HoodieRollbackMetadata rollbackMetadata = TimelineMetadataUtils.deserializeHoodieRollbackMetadata(timeline.getInstantDetails(instant).get());
            return rollbackMetadata.getCommitsRollback();
        }
        List<String> rollbackedCommits = new LinkedList<>();
        if (instant.getAction().equals(HoodieTimeline.RESTORE_ACTION)) {
            // Restore is made up of several rollbacks
            HoodieRestoreMetadata restoreMetadata = TimelineMetadataUtils.deserializeHoodieRestoreMetadata(timeline.getInstantDetails(instant).get());
            restoreMetadata.getHoodieRestoreMetadata().values().forEach(rms -> {
                rms.forEach(rm -> rollbackedCommits.addAll(rm.getCommitsRollback()));
            });
        }
        return rollbackedCommits;
    } catch (IOException e) {
        throw new HoodieMetadataException("Error retrieving rollback commits for instant " + instant, e);
    }
}
Also used : HoodieMetadataException(org.apache.hudi.exception.HoodieMetadataException) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) LinkedList(java.util.LinkedList)

Example 9 with HoodieRollbackMetadata

use of org.apache.hudi.avro.model.HoodieRollbackMetadata in project hudi by apache.

the class BaseRestoreActionExecutor method execute.

@Override
public HoodieRestoreMetadata execute() {
    HoodieTimer restoreTimer = new HoodieTimer();
    restoreTimer.startTimer();
    Option<HoodieInstant> restoreInstant = table.getRestoreTimeline().filterInflightsAndRequested().filter(instant -> instant.getTimestamp().equals(instantTime)).firstInstant();
    if (!restoreInstant.isPresent()) {
        throw new HoodieRollbackException("No pending restore instants found to execute restore");
    }
    try {
        List<HoodieInstant> instantsToRollback = getInstantsToRollback(restoreInstant.get());
        ValidationUtils.checkArgument(restoreInstant.get().getState().equals(HoodieInstant.State.REQUESTED) || restoreInstant.get().getState().equals(HoodieInstant.State.INFLIGHT));
        Map<String, List<HoodieRollbackMetadata>> instantToMetadata = new HashMap<>();
        if (restoreInstant.get().isRequested()) {
            table.getActiveTimeline().transitionRestoreRequestedToInflight(restoreInstant.get());
        }
        instantsToRollback.forEach(instant -> {
            instantToMetadata.put(instant.getTimestamp(), Collections.singletonList(rollbackInstant(instant)));
            LOG.info("Deleted instant " + instant);
        });
        return finishRestore(instantToMetadata, instantsToRollback, restoreTimer.endTimer());
    } catch (IOException io) {
        throw new HoodieRestoreException("unable to Restore instant " + restoreInstant.get(), io);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieTable(org.apache.hudi.table.HoodieTable) BaseActionExecutor(org.apache.hudi.table.action.BaseActionExecutor) HoodieRestorePlan(org.apache.hudi.avro.model.HoodieRestorePlan) HoodieRestoreException(org.apache.hudi.exception.HoodieRestoreException) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) Option(org.apache.hudi.common.util.Option) HashMap(java.util.HashMap) HoodieEngineContext(org.apache.hudi.common.engine.HoodieEngineContext) TransactionManager(org.apache.hudi.client.transaction.TransactionManager) HoodieTimer(org.apache.hudi.common.util.HoodieTimer) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) Map(java.util.Map) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) ValidationUtils(org.apache.hudi.common.util.ValidationUtils) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HoodieInstantInfo(org.apache.hudi.avro.model.HoodieInstantInfo) HoodieRecordPayload(org.apache.hudi.common.model.HoodieRecordPayload) List(java.util.List) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) LogManager(org.apache.log4j.LogManager) Collections(java.util.Collections) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HashMap(java.util.HashMap) HoodieTimer(org.apache.hudi.common.util.HoodieTimer) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HoodieRestoreException(org.apache.hudi.exception.HoodieRestoreException)

Example 10 with HoodieRollbackMetadata

use of org.apache.hudi.avro.model.HoodieRollbackMetadata in project hudi by apache.

the class BaseRollbackActionExecutor method execute.

@Override
public HoodieRollbackMetadata execute() {
    table.getMetaClient().reloadActiveTimeline();
    Option<HoodieInstant> rollbackInstant = table.getRollbackTimeline().filterInflightsAndRequested().filter(instant -> instant.getTimestamp().equals(instantTime)).firstInstant();
    if (!rollbackInstant.isPresent()) {
        throw new HoodieRollbackException("No pending rollback instants found to execute rollback");
    }
    try {
        HoodieRollbackPlan rollbackPlan = RollbackUtils.getRollbackPlan(table.getMetaClient(), rollbackInstant.get());
        return runRollback(table, rollbackInstant.get(), rollbackPlan);
    } catch (IOException e) {
        throw new HoodieIOException("Failed to fetch rollback plan for commit " + instantTime, e);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieTable(org.apache.hudi.table.HoodieTable) BaseActionExecutor(org.apache.hudi.table.action.BaseActionExecutor) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) Option(org.apache.hudi.common.util.Option) HoodieEngineContext(org.apache.hudi.common.engine.HoodieEngineContext) TransactionManager(org.apache.hudi.client.transaction.TransactionManager) HoodieTimer(org.apache.hudi.common.util.HoodieTimer) Logger(org.apache.log4j.Logger) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) ValidationUtils(org.apache.hudi.common.util.ValidationUtils) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) BootstrapIndex(org.apache.hudi.common.bootstrap.index.BootstrapIndex) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) WriteMarkersFactory(org.apache.hudi.table.marker.WriteMarkersFactory) HoodieHeartbeatClient(org.apache.hudi.client.heartbeat.HoodieHeartbeatClient) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) IOException(java.io.IOException) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HoodieRecordPayload(org.apache.hudi.common.model.HoodieRecordPayload) List(java.util.List) ClusteringUtils(org.apache.hudi.common.util.ClusteringUtils) HoodieIOException(org.apache.hudi.exception.HoodieIOException) LogManager(org.apache.log4j.LogManager) HoodieRollbackStat(org.apache.hudi.common.HoodieRollbackStat) Collections(java.util.Collections) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Aggregations

HoodieRollbackMetadata (org.apache.hudi.avro.model.HoodieRollbackMetadata)23 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 IOException (java.io.IOException)12 HashMap (java.util.HashMap)12 HoodieActiveTimeline (org.apache.hudi.common.table.timeline.HoodieActiveTimeline)12 Map (java.util.Map)10 HoodieRestoreMetadata (org.apache.hudi.avro.model.HoodieRestoreMetadata)8 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)8 Collections (java.util.Collections)7 Collectors (java.util.stream.Collectors)7 Option (org.apache.hudi.common.util.Option)7 ValidationUtils (org.apache.hudi.common.util.ValidationUtils)7 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)7 Logger (org.apache.log4j.Logger)7 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)6 LogManager (org.apache.log4j.LogManager)6 HoodieCleanMetadata (org.apache.hudi.avro.model.HoodieCleanMetadata)5 HoodieInstantInfo (org.apache.hudi.avro.model.HoodieInstantInfo)5