Search in sources :

Example 1 with HoodieSavepointException

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

the class SparkMain method createSavepoint.

private static int createSavepoint(JavaSparkContext jsc, String commitTime, String user, String comments, String basePath) throws Exception {
    SparkRDDWriteClient client = createHoodieClient(jsc, basePath);
    try {
        client.savepoint(commitTime, user, comments);
        LOG.info(String.format("The commit \"%s\" has been savepointed.", commitTime));
        return 0;
    } catch (HoodieSavepointException se) {
        LOG.warn(String.format("Failed: Could not create savepoint \"%s\".", commitTime));
        return -1;
    }
}
Also used : SparkRDDWriteClient(org.apache.hudi.client.SparkRDDWriteClient) HoodieSavepointException(org.apache.hudi.exception.HoodieSavepointException)

Example 2 with HoodieSavepointException

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

the class SavepointActionExecutor method execute.

@Override
public HoodieSavepointMetadata execute() {
    Option<HoodieInstant> cleanInstant = table.getCompletedCleanTimeline().lastInstant();
    if (!table.getCompletedCommitsTimeline().containsInstant(instantTime)) {
        throw new HoodieSavepointException("Could not savepoint non-existing commit " + instantTime);
    }
    try {
        // Check the last commit that was not cleaned and check if savepoint time is > that commit
        String lastCommitRetained;
        if (cleanInstant.isPresent()) {
            HoodieCleanMetadata cleanMetadata = TimelineMetadataUtils.deserializeHoodieCleanMetadata(table.getActiveTimeline().getInstantDetails(cleanInstant.get()).get());
            lastCommitRetained = cleanMetadata.getEarliestCommitToRetain();
        } else {
            lastCommitRetained = table.getCompletedCommitsTimeline().firstInstant().get().getTimestamp();
        }
        // Cannot allow savepoint time on a commit that could have been cleaned
        ValidationUtils.checkArgument(HoodieTimeline.compareTimestamps(instantTime, HoodieTimeline.GREATER_THAN_OR_EQUALS, lastCommitRetained), "Could not savepoint commit " + instantTime + " as this is beyond the lookup window " + lastCommitRetained);
        context.setJobStatus(this.getClass().getSimpleName(), "Collecting latest files for savepoint " + instantTime);
        List<String> partitions = FSUtils.getAllPartitionPaths(context, config.getMetadataConfig(), table.getMetaClient().getBasePath());
        Map<String, List<String>> latestFilesMap = context.mapToPair(partitions, partitionPath -> {
            // Scan all partitions files with this commit time
            LOG.info("Collecting latest files in partition path " + partitionPath);
            TableFileSystemView.BaseFileOnlyView view = table.getBaseFileOnlyView();
            List<String> latestFiles = view.getLatestBaseFilesBeforeOrOn(partitionPath, instantTime).map(HoodieBaseFile::getFileName).collect(Collectors.toList());
            return new ImmutablePair<>(partitionPath, latestFiles);
        }, null);
        HoodieSavepointMetadata metadata = TimelineMetadataUtils.convertSavepointMetadata(user, comment, latestFilesMap);
        // Nothing to save in the savepoint
        table.getActiveTimeline().createNewInstant(new HoodieInstant(true, HoodieTimeline.SAVEPOINT_ACTION, instantTime));
        table.getActiveTimeline().saveAsComplete(new HoodieInstant(true, HoodieTimeline.SAVEPOINT_ACTION, instantTime), TimelineMetadataUtils.serializeSavepointMetadata(metadata));
        LOG.info("Savepoint " + instantTime + " created");
        return metadata;
    } catch (IOException e) {
        throw new HoodieSavepointException("Failed to savepoint " + instantTime, e);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) IOException(java.io.IOException) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata) HoodieSavepointException(org.apache.hudi.exception.HoodieSavepointException) ImmutablePair(org.apache.hudi.common.util.collection.ImmutablePair) List(java.util.List) TableFileSystemView(org.apache.hudi.common.table.view.TableFileSystemView)

Example 3 with HoodieSavepointException

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

the class CleanPlanner method getSavepointedDataFiles.

/**
 * Get the list of data file names savepointed.
 */
public Stream<String> getSavepointedDataFiles(String savepointTime) {
    if (!hoodieTable.getSavepoints().contains(savepointTime)) {
        throw new HoodieSavepointException("Could not get data files for savepoint " + savepointTime + ". No such savepoint.");
    }
    HoodieInstant instant = new HoodieInstant(false, HoodieTimeline.SAVEPOINT_ACTION, savepointTime);
    HoodieSavepointMetadata metadata;
    try {
        metadata = TimelineMetadataUtils.deserializeHoodieSavepointMetadata(hoodieTable.getActiveTimeline().getInstantDetails(instant).get());
    } catch (IOException e) {
        throw new HoodieSavepointException("Could not get savepointed data files for savepoint " + savepointTime, e);
    }
    return metadata.getPartitionMetadata().values().stream().flatMap(s -> s.getSavepointDataFile().stream());
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieSavepointException(org.apache.hudi.exception.HoodieSavepointException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata)

Aggregations

HoodieSavepointException (org.apache.hudi.exception.HoodieSavepointException)3 IOException (java.io.IOException)2 HoodieSavepointMetadata (org.apache.hudi.avro.model.HoodieSavepointMetadata)2 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)2 List (java.util.List)1 HoodieCleanMetadata (org.apache.hudi.avro.model.HoodieCleanMetadata)1 SparkRDDWriteClient (org.apache.hudi.client.SparkRDDWriteClient)1 TableFileSystemView (org.apache.hudi.common.table.view.TableFileSystemView)1 ImmutablePair (org.apache.hudi.common.util.collection.ImmutablePair)1 HoodieIOException (org.apache.hudi.exception.HoodieIOException)1