Search in sources :

Example 1 with IOType

use of org.apache.hudi.common.model.IOType 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)

Aggregations

IOException (java.io.IOException)1 Path (org.apache.hadoop.fs.Path)1 HoodieRollbackRequest (org.apache.hudi.avro.model.HoodieRollbackRequest)1 IOType (org.apache.hudi.common.model.IOType)1 HoodieRollbackException (org.apache.hudi.exception.HoodieRollbackException)1