Search in sources :

Example 6 with HoodieSavepointMetadata

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

the class ExportCommand method copyNonArchivedInstants.

private int copyNonArchivedInstants(List<HoodieInstant> instants, int limit, String localFolder) throws Exception {
    int copyCount = 0;
    if (instants.isEmpty()) {
        return limit;
    }
    final Logger LOG = LogManager.getLogger(ExportCommand.class);
    final HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
    final HoodieActiveTimeline timeline = metaClient.getActiveTimeline();
    for (HoodieInstant instant : instants) {
        String localPath = localFolder + Path.SEPARATOR + instant.getFileName();
        byte[] data = null;
        switch(instant.getAction()) {
            case HoodieTimeline.CLEAN_ACTION:
                {
                    HoodieCleanMetadata metadata = TimelineMetadataUtils.deserializeHoodieCleanMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            case HoodieTimeline.DELTA_COMMIT_ACTION:
            case HoodieTimeline.COMMIT_ACTION:
            case HoodieTimeline.COMPACTION_ACTION:
                {
                    // Already in json format
                    data = timeline.getInstantDetails(instant).get();
                    break;
                }
            case HoodieTimeline.ROLLBACK_ACTION:
                {
                    HoodieRollbackMetadata metadata = TimelineMetadataUtils.deserializeHoodieRollbackMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            case HoodieTimeline.SAVEPOINT_ACTION:
                {
                    HoodieSavepointMetadata metadata = TimelineMetadataUtils.deserializeHoodieSavepointMetadata(timeline.getInstantDetails(instant).get());
                    data = HoodieAvroUtils.avroToJson(metadata, true);
                    break;
                }
            default:
                {
                    throw new HoodieException("Unknown type of action " + instant.getAction());
                }
        }
        if (data != null) {
            writeToFile(localPath, data);
        }
    }
    return copyCount;
}
Also used : HoodieTableMetaClient(org.apache.hudi.common.table.HoodieTableMetaClient) HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieRollbackMetadata(org.apache.hudi.avro.model.HoodieRollbackMetadata) HoodieActiveTimeline(org.apache.hudi.common.table.timeline.HoodieActiveTimeline) HoodieCleanMetadata(org.apache.hudi.avro.model.HoodieCleanMetadata) HoodieException(org.apache.hudi.exception.HoodieException) Logger(org.apache.log4j.Logger) HoodieSavepointMetadata(org.apache.hudi.avro.model.HoodieSavepointMetadata)

Aggregations

HoodieSavepointMetadata (org.apache.hudi.avro.model.HoodieSavepointMetadata)6 List (java.util.List)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HoodieCleanMetadata (org.apache.hudi.avro.model.HoodieCleanMetadata)2 HoodieSavepointPartitionMetadata (org.apache.hudi.avro.model.HoodieSavepointPartitionMetadata)2 CollectionUtils.createImmutableMap (org.apache.hudi.common.util.CollectionUtils.createImmutableMap)2 HoodieSavepointException (org.apache.hudi.exception.HoodieSavepointException)2 HoodieRollbackMetadata (org.apache.hudi.avro.model.HoodieRollbackMetadata)1 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)1 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)1 HoodieActiveTimeline (org.apache.hudi.common.table.timeline.HoodieActiveTimeline)1 TableFileSystemView (org.apache.hudi.common.table.view.TableFileSystemView)1 ImmutablePair (org.apache.hudi.common.util.collection.ImmutablePair)1 HoodieException (org.apache.hudi.exception.HoodieException)1 HoodieIOException (org.apache.hudi.exception.HoodieIOException)1 Logger (org.apache.log4j.Logger)1