Search in sources :

Example 6 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException in project hudi by apache.

the class ListingBasedRollbackStrategy method getRollbackRequests.

@Override
public List<HoodieRollbackRequest> getRollbackRequests(HoodieInstant instantToRollback) {
    try {
        List<ListingBasedRollbackRequest> rollbackRequests = null;
        if (table.getMetaClient().getTableType() == HoodieTableType.COPY_ON_WRITE) {
            rollbackRequests = RollbackUtils.generateRollbackRequestsByListingCOW(context, table.getMetaClient().getBasePath());
        } else {
            rollbackRequests = RollbackUtils.generateRollbackRequestsUsingFileListingMOR(instantToRollback, table, context);
        }
        List<HoodieRollbackRequest> listingBasedRollbackRequests = new ListingBasedRollbackHelper(table.getMetaClient(), config).getRollbackRequestsForRollbackPlan(context, instantToRollback, rollbackRequests);
        return listingBasedRollbackRequests;
    } catch (IOException e) {
        LOG.error("Generating rollback requests failed for " + instantToRollback.getTimestamp(), e);
        throw new HoodieRollbackException("Generating rollback requests failed for " + instantToRollback.getTimestamp(), e);
    }
}
Also used : HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) IOException(java.io.IOException) HoodieRollbackRequest(org.apache.hudi.avro.model.HoodieRollbackRequest)

Example 7 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException in project hudi by apache.

the class SavepointHelpers method validateSavepointPresence.

public static void validateSavepointPresence(HoodieTable table, String savepointTime) {
    HoodieInstant savePoint = new HoodieInstant(false, HoodieTimeline.SAVEPOINT_ACTION, savepointTime);
    boolean isSavepointPresent = table.getCompletedSavepointTimeline().containsInstant(savePoint);
    if (!isSavepointPresent) {
        throw new HoodieRollbackException("No savepoint for instantTime " + savepointTime);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException)

Example 8 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException in project hudi by apache.

the class ZeroToOneUpgradeHandler method recreateMarkers.

/**
 * Recreate markers in new format.
 * Step1: Delete existing markers
 * Step2: Collect all rollback file info.
 * Step3: recreate markers for all interested files.
 *
 * @param commitInstantTime instant of interest for which markers need to be recreated.
 * @param table             instance of {@link HoodieTable} to use
 * @param context           instance of {@link HoodieEngineContext} to use
 * @throws HoodieRollbackException on any exception during upgrade.
 */
protected void recreateMarkers(final String commitInstantTime, HoodieTable table, HoodieEngineContext context, int parallelism) throws HoodieRollbackException {
    try {
        // fetch hoodie instant
        Option<HoodieInstant> commitInstantOpt = Option.fromJavaOptional(table.getActiveTimeline().getCommitsTimeline().getInstants().filter(instant -> HoodieActiveTimeline.EQUALS.test(instant.getTimestamp(), commitInstantTime)).findFirst());
        if (commitInstantOpt.isPresent()) {
            // delete existing markers
            WriteMarkers writeMarkers = WriteMarkersFactory.get(MarkerType.DIRECT, table, commitInstantTime);
            writeMarkers.quietDeleteMarkerDir(context, parallelism);
            // generate rollback stats
            List<ListingBasedRollbackRequest> rollbackRequests;
            if (table.getMetaClient().getTableType() == HoodieTableType.COPY_ON_WRITE) {
                rollbackRequests = RollbackUtils.generateRollbackRequestsByListingCOW(context, table.getMetaClient().getBasePath());
            } else {
                rollbackRequests = RollbackUtils.generateRollbackRequestsUsingFileListingMOR(commitInstantOpt.get(), table, context);
            }
            List<HoodieRollbackStat> rollbackStats = getListBasedRollBackStats(table.getMetaClient(), table.getConfig(), context, commitInstantOpt, rollbackRequests);
            // recreate markers adhering to marker based rollback
            for (HoodieRollbackStat rollbackStat : rollbackStats) {
                for (String path : rollbackStat.getSuccessDeleteFiles()) {
                    String dataFileName = path.substring(path.lastIndexOf("/") + 1);
                    // not feasible to differentiate MERGE from CREATE. hence creating with MERGE IOType for all base files.
                    writeMarkers.create(rollbackStat.getPartitionPath(), dataFileName, IOType.MERGE);
                }
                for (FileStatus fileStatus : rollbackStat.getCommandBlocksCount().keySet()) {
                    writeMarkers.create(rollbackStat.getPartitionPath(), getFileNameForMarkerFromLogFile(fileStatus.getPath().toString(), table), IOType.APPEND);
                }
            }
        }
    } catch (Exception e) {
        throw new HoodieRollbackException("Exception thrown while upgrading Hoodie Table from version 0 to 1", e);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackStat(org.apache.hudi.common.HoodieRollbackStat) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) FileStatus(org.apache.hadoop.fs.FileStatus) WriteMarkers(org.apache.hudi.table.marker.WriteMarkers) ListingBasedRollbackRequest(org.apache.hudi.table.action.rollback.ListingBasedRollbackRequest) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException)

Example 9 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException in project hudi by apache.

the class MarkerBasedRollbackStrategy method getRollbackRequests.

@Override
public List<HoodieRollbackRequest> getRollbackRequests(HoodieInstant instantToRollback) {
    try {
        List<String> markerPaths = MarkerBasedRollbackUtils.getAllMarkerPaths(table, context, instantToRollback.getTimestamp(), config.getRollbackParallelism());
        int parallelism = Math.max(Math.min(markerPaths.size(), config.getRollbackParallelism()), 1);
        return context.map(markerPaths, markerFilePath -> {
            String typeStr = markerFilePath.substring(markerFilePath.lastIndexOf(".") + 1);
            IOType type = IOType.valueOf(typeStr);
            switch(type) {
                case MERGE:
                case CREATE:
                    String fileToDelete = WriteMarkers.stripMarkerSuffix(markerFilePath);
                    Path fullDeletePath = new Path(basePath, fileToDelete);
                    String partitionPath = FSUtils.getRelativePartitionPath(new Path(basePath), fullDeletePath.getParent());
                    return new HoodieRollbackRequest(partitionPath, EMPTY_STRING, EMPTY_STRING, Collections.singletonList(fullDeletePath.toString()), Collections.emptyMap());
                case APPEND:
                    // - Partition path
                    return getRollbackRequestForAppend(WriteMarkers.stripMarkerSuffix(markerFilePath));
                default:
                    throw new HoodieRollbackException("Unknown marker type, during rollback of " + instantToRollback);
            }
        }, parallelism);
    } catch (Exception e) {
        throw new HoodieRollbackException("Error rolling back using marker files written for " + instantToRollback, e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) IOType(org.apache.hudi.common.model.IOType) HoodieRollbackRequest(org.apache.hudi.avro.model.HoodieRollbackRequest) HoodieRollbackException(org.apache.hudi.exception.HoodieRollbackException) IOException(java.io.IOException)

Example 10 with HoodieRollbackException

use of org.apache.hudi.exception.HoodieRollbackException 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)

Aggregations

HoodieRollbackException (org.apache.hudi.exception.HoodieRollbackException)11 IOException (java.io.IOException)7 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)5 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 HoodieEngineContext (org.apache.hudi.common.engine.HoodieEngineContext)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 HoodieRollbackMetadata (org.apache.hudi.avro.model.HoodieRollbackMetadata)3 HoodieRollbackRequest (org.apache.hudi.avro.model.HoodieRollbackRequest)3 TransactionManager (org.apache.hudi.client.transaction.TransactionManager)3 HoodieRollbackStat (org.apache.hudi.common.HoodieRollbackStat)3 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)3 HoodieIOException (org.apache.hudi.exception.HoodieIOException)3 LogManager (org.apache.log4j.LogManager)3 Logger (org.apache.log4j.Logger)3 ArrayList (java.util.ArrayList)2