Search in sources :

Example 86 with HoodieCommitMetadata

use of org.apache.hudi.common.model.HoodieCommitMetadata in project hudi by apache.

the class HoodieTestTable method doRollbackWithExtraFiles.

public HoodieTestTable doRollbackWithExtraFiles(String commitTimeToRollback, String commitTime, Map<String, List<String>> extraFiles) 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());
    for (Map.Entry<String, List<String>> entry : partitionFiles.entrySet()) {
        deleteFilesInPartition(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, List<String>> entry : extraFiles.entrySet()) {
        if (partitionFiles.containsKey(entry.getKey())) {
            partitionFiles.get(entry.getKey()).addAll(entry.getValue());
        }
    }
    HoodieRollbackMetadata rollbackMetadata = getRollbackMetadata(commitTimeToRollback, partitionFiles);
    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 87 with HoodieCommitMetadata

use of org.apache.hudi.common.model.HoodieCommitMetadata in project hudi by apache.

the class HoodieTestTable method getMetadataForInstant.

private Option<HoodieCommitMetadata> getMetadataForInstant(String instantTime) {
    metaClient = HoodieTableMetaClient.reload(metaClient);
    Option<HoodieInstant> hoodieInstant = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants().filter(i -> i.getTimestamp().equals(instantTime)).firstInstant();
    try {
        if (hoodieInstant.isPresent()) {
            return getCommitMeta(hoodieInstant.get());
        } else {
            return Option.empty();
        }
    } catch (IOException io) {
        throw new HoodieIOException("Unable to read metadata for instant " + hoodieInstant.get(), io);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) Arrays(java.util.Arrays) REPLACE_COMMIT_ACTION(org.apache.hudi.common.table.timeline.HoodieTimeline.REPLACE_COMMIT_ACTION) FileSystem(org.apache.hadoop.fs.FileSystem) Date(java.util.Date) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) FileCreateUtils.createDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createDeltaCommit) Random(java.util.Random) FileCreateUtils.createRestoreFile(org.apache.hudi.common.testutils.FileCreateUtils.createRestoreFile) FileStatus(org.apache.hadoop.fs.FileStatus) FileCreateUtils.createMarkerFile(org.apache.hudi.common.testutils.FileCreateUtils.createMarkerFile) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata) Logger(org.apache.log4j.Logger) HoodieTableType(org.apache.hudi.common.model.HoodieTableType) CLEAN_ACTION(org.apache.hudi.common.table.timeline.HoodieTimeline.CLEAN_ACTION) FileCreateUtils.createInflightCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCommit) HoodieTableConfig(org.apache.hudi.common.table.HoodieTableConfig) CleanPlanV2MigrationHandler(org.apache.hudi.common.table.timeline.versioning.clean.CleanPlanV2MigrationHandler) Map(java.util.Map) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) Path(org.apache.hadoop.fs.Path) FileCreateUtils.createReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createReplaceCommit) FileCreateUtils.createInflightCompaction(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCompaction) FileCreateUtils.logFileName(org.apache.hudi.common.testutils.FileCreateUtils.logFileName) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) FileCreateUtils.createRequestedReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedReplaceCommit) ValidationUtils(org.apache.hudi.common.util.ValidationUtils) CollectionUtils.createImmutableMap(org.apache.hudi.common.util.CollectionUtils.createImmutableMap) CleanerUtils.convertCleanMetadata(org.apache.hudi.common.util.CleanerUtils.convertCleanMetadata) HoodieCleanerPlan(org.apache.hudi.avro.model.HoodieCleanerPlan) IOType(org.apache.hudi.common.model.IOType) TimelineMetadataUtils(org.apache.hudi.common.table.timeline.TimelineMetadataUtils) FileCreateUtils.createRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createRollbackFile) HoodieRollbackPlan(org.apache.hudi.avro.model.HoodieRollbackPlan) UUID(java.util.UUID) COMPACT(org.apache.hudi.common.model.WriteOperationType.COMPACT) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HoodieFileFormat(org.apache.hudi.common.model.HoodieFileFormat) List(java.util.List) Stream(java.util.stream.Stream) FileCreateUtils.createRequestedCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCommit) CommitUtils.getCommitActionType(org.apache.hudi.common.util.CommitUtils.getCommitActionType) HoodieWriteStat(org.apache.hudi.common.model.HoodieWriteStat) HoodieCompactionPlan(org.apache.hudi.avro.model.HoodieCompactionPlan) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) HoodieSavepointPartitionMetadata(org.apache.hudi.avro.model.HoodieSavepointPartitionMetadata) WriteOperationType(org.apache.hudi.common.model.WriteOperationType) FileCreateUtils.createRequestedCompaction(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCompaction) CompactionUtils(org.apache.hudi.common.util.CompactionUtils) IntStream(java.util.stream.IntStream) HoodieCleaningPolicy(org.apache.hudi.common.model.HoodieCleaningPolicy) FileCreateUtils.createInflightRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createInflightRollbackFile) FileCreateUtils.createInflightCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createInflightCleanFile) FileSlice(org.apache.hudi.common.model.FileSlice) FileCreateUtils.createRequestedDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedDeltaCommit) Option(org.apache.hudi.common.util.Option) HashMap(java.util.HashMap) FileCreateUtils.createRequestedCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedCleanFile) FileCreateUtils.baseFileName(org.apache.hudi.common.testutils.FileCreateUtils.baseFileName) ArrayList(java.util.ArrayList) FileCreateUtils.createInflightReplaceCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightReplaceCommit) FileCreateUtils.createInflightDeltaCommit(org.apache.hudi.common.testutils.FileCreateUtils.createInflightDeltaCommit) HoodieRequestedReplaceMetadata(org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata) HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieRollbackPartitionMetadata(org.apache.hudi.avro.model.HoodieRollbackPartitionMetadata) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) HoodieCleanStat(org.apache.hudi.common.HoodieCleanStat) SECONDS(java.time.temporal.ChronoUnit.SECONDS) CommitUtils.buildMetadata(org.apache.hudi.common.util.CommitUtils.buildMetadata) FileCreateUtils.createCleanFile(org.apache.hudi.common.testutils.FileCreateUtils.createCleanFile) Files(java.nio.file.Files) MERGE_ON_READ(org.apache.hudi.common.model.HoodieTableType.MERGE_ON_READ) EMPTY_STRING(org.apache.hudi.common.util.StringUtils.EMPTY_STRING) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) IOException(java.io.IOException) FileCreateUtils.createRequestedRollbackFile(org.apache.hudi.common.testutils.FileCreateUtils.createRequestedRollbackFile) HoodieInstantInfo(org.apache.hudi.avro.model.HoodieInstantInfo) HoodieActionInstant(org.apache.hudi.avro.model.HoodieActionInstant) HoodieReplaceCommitMetadata(org.apache.hudi.common.model.HoodieReplaceCommitMetadata) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) Paths(java.nio.file.Paths) HoodiePartitionMetadata(org.apache.hudi.common.model.HoodiePartitionMetadata) CLUSTER(org.apache.hudi.common.model.WriteOperationType.CLUSTER) FileCreateUtils.createCommit(org.apache.hudi.common.testutils.FileCreateUtils.createCommit) HoodieIOException(org.apache.hudi.exception.HoodieIOException) LogManager(org.apache.log4j.LogManager) Comparator(java.util.Comparator) Collections(java.util.Collections) UPSERT(org.apache.hudi.common.model.WriteOperationType.UPSERT) FSUtils(org.apache.hudi.common.fs.FSUtils) Pair(org.apache.hudi.common.util.collection.Pair) HoodieIOException(org.apache.hudi.exception.HoodieIOException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 88 with HoodieCommitMetadata

use of org.apache.hudi.common.model.HoodieCommitMetadata in project hudi by apache.

the class HoodieTestTable method doSavepoint.

public HoodieSavepointMetadata doSavepoint(String commitTime) throws IOException {
    Option<HoodieCommitMetadata> commitMetadata = getMetadataForInstant(commitTime);
    if (!commitMetadata.isPresent()) {
        throw new IllegalArgumentException("Instant to rollback not present in timeline: " + commitTime);
    }
    Map<String, List<String>> partitionFiles = getPartitionFiles(commitMetadata.get());
    HoodieSavepointMetadata savepointMetadata = getSavepointMetadata(commitTime, partitionFiles);
    for (Map.Entry<String, List<String>> entry : partitionFiles.entrySet()) {
        deleteFilesInPartition(entry.getKey(), entry.getValue());
    }
    return savepointMetadata;
}
Also used : HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) 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) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata)

Example 89 with HoodieCommitMetadata

use of org.apache.hudi.common.model.HoodieCommitMetadata in project hudi by apache.

the class HoodieTestTable method doCompaction.

public HoodieCommitMetadata doCompaction(String commitTime, List<String> partitions, boolean inflight) throws Exception {
    this.currentInstantTime = commitTime;
    if (partitions.isEmpty()) {
        partitions = Collections.singletonList(EMPTY_STRING);
    }
    HoodieTestTableState testTableState = getTestTableStateWithPartitionFileInfo(COMPACT, metaClient.getTableType(), commitTime, partitions, 1);
    HoodieCommitMetadata commitMetadata = createCommitMetadata(COMPACT, commitTime, testTableState);
    for (String partition : partitions) {
        this.withBaseFilesInPartition(partition, testTableState.getPartitionToBaseFileInfoMap(commitTime).get(partition));
    }
    if (inflight) {
        this.addInflightCompaction(commitTime, commitMetadata);
    } else {
        this.addCompaction(commitTime, commitMetadata);
    }
    return commitMetadata;
}
Also used : HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata)

Example 90 with HoodieCommitMetadata

use of org.apache.hudi.common.model.HoodieCommitMetadata in project hudi by apache.

the class HoodieTestTable method doRestore.

public HoodieTestTable doRestore(String commitToRestoreTo, String restoreTime) throws Exception {
    metaClient = HoodieTableMetaClient.reload(metaClient);
    List<HoodieInstant> commitsToRollback = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants().findInstantsAfter(commitToRestoreTo).getReverseOrderedInstants().collect(Collectors.toList());
    Map<String, List<HoodieRollbackMetadata>> rollbackMetadataMap = new HashMap<>();
    for (HoodieInstant commitInstantToRollback : commitsToRollback) {
        Option<HoodieCommitMetadata> commitMetadata = getCommitMeta(commitInstantToRollback);
        if (!commitMetadata.isPresent()) {
            throw new IllegalArgumentException("Instant to rollback not present in timeline: " + commitInstantToRollback.getTimestamp());
        }
        Map<String, List<String>> partitionFiles = getPartitionFiles(commitMetadata.get());
        rollbackMetadataMap.put(commitInstantToRollback.getTimestamp(), Collections.singletonList(getRollbackMetadata(commitInstantToRollback.getTimestamp(), partitionFiles)));
        for (Map.Entry<String, List<String>> entry : partitionFiles.entrySet()) {
            deleteFilesInPartition(entry.getKey(), entry.getValue());
        }
    }
    HoodieRestoreMetadata restoreMetadata = TimelineMetadataUtils.convertRestoreMetadata(restoreTime, 1000L, commitsToRollback, rollbackMetadataMap);
    return addRestore(restoreTime, restoreMetadata);
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HashMap(java.util.HashMap) HoodieRestoreMetadata(org.apache.hudi.avro.model.HoodieRestoreMetadata) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) 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)

Aggregations

HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)139 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)64 ArrayList (java.util.ArrayList)54 HashMap (java.util.HashMap)49 List (java.util.List)48 HoodieWriteStat (org.apache.hudi.common.model.HoodieWriteStat)44 IOException (java.io.IOException)42 Test (org.junit.jupiter.api.Test)41 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)40 Map (java.util.Map)38 Path (org.apache.hadoop.fs.Path)36 HoodieActiveTimeline (org.apache.hudi.common.table.timeline.HoodieActiveTimeline)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 File (java.io.File)26 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)26 Option (org.apache.hudi.common.util.Option)25 Schema (org.apache.avro.Schema)22 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)21 Collectors (java.util.stream.Collectors)20 HoodieLogFile (org.apache.hudi.common.model.HoodieLogFile)20