Search in sources :

Example 56 with HoodieException

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

the class TableSchemaResolver method getLatestCommitMetadata.

/**
 * Get Last commit's Metadata.
 */
public Option<HoodieCommitMetadata> getLatestCommitMetadata() {
    try {
        HoodieTimeline timeline = metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants();
        if (timeline.lastInstant().isPresent()) {
            HoodieInstant instant = timeline.lastInstant().get();
            byte[] data = timeline.getInstantDetails(instant).get();
            return Option.of(HoodieCommitMetadata.fromBytes(data, HoodieCommitMetadata.class));
        } else {
            return Option.empty();
        }
    } catch (Exception e) {
        throw new HoodieException("Failed to get commit metadata", e);
    }
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieCommitMetadata(org.apache.hudi.common.model.HoodieCommitMetadata) HoodieTimeline(org.apache.hudi.common.table.timeline.HoodieTimeline) HoodieException(org.apache.hudi.exception.HoodieException) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException) InvalidTableException(org.apache.hudi.exception.InvalidTableException)

Example 57 with HoodieException

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

the class FSUtils method processFiles.

/**
 * Recursively processes all files in the base-path. If excludeMetaFolder is set, the meta-folder and all its subdirs
 * are skipped
 *
 * @param fs File System
 * @param basePathStr Base-Path
 * @param consumer Callback for processing
 * @param excludeMetaFolder Exclude .hoodie folder
 * @throws IOException -
 */
public static void processFiles(FileSystem fs, String basePathStr, Function<FileStatus, Boolean> consumer, boolean excludeMetaFolder) throws IOException {
    PathFilter pathFilter = excludeMetaFolder ? getExcludeMetaPathFilter() : ALLOW_ALL_FILTER;
    FileStatus[] topLevelStatuses = fs.listStatus(new Path(basePathStr));
    for (FileStatus child : topLevelStatuses) {
        if (child.isFile()) {
            boolean success = consumer.apply(child);
            if (!success) {
                throw new HoodieException("Failed to process file-status=" + child);
            }
        } else if (pathFilter.accept(child.getPath())) {
            RemoteIterator<LocatedFileStatus> itr = fs.listFiles(child.getPath(), true);
            while (itr.hasNext()) {
                FileStatus status = itr.next();
                boolean success = consumer.apply(status);
                if (!success) {
                    throw new HoodieException("Failed to process file-status=" + status);
                }
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) RemoteIterator(org.apache.hadoop.fs.RemoteIterator) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) HoodieException(org.apache.hudi.exception.HoodieException)

Example 58 with HoodieException

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

the class HoodieWrapperFileSystem method concat.

@Override
public void concat(Path trg, Path[] psrcs) throws IOException {
    Path[] psrcsNew = convertDefaults(psrcs);
    fileSystem.concat(convertToDefaultPath(trg), psrcsNew);
    try {
        consistencyGuard.waitTillFileAppears(convertToDefaultPath(trg));
    } catch (TimeoutException e) {
        throw new HoodieException("Timed out waiting for " + trg + " to appear", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNameCachingPath(org.apache.hudi.hadoop.FileNameCachingPath) HoodieException(org.apache.hudi.exception.HoodieException) TimeoutException(java.util.concurrent.TimeoutException)

Example 59 with HoodieException

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

the class SizeAwareFSDataOutputStream method close.

@Override
public void close() throws IOException {
    super.close();
    try {
        consistencyGuard.waitTillFileAppears(path);
    } catch (TimeoutException e) {
        throw new HoodieException(e);
    }
    closeCallback.run();
}
Also used : HoodieException(org.apache.hudi.exception.HoodieException) TimeoutException(java.util.concurrent.TimeoutException)

Example 60 with HoodieException

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

the class HoodiePartitionMetadata method readFromFS.

/**
 * Read out the metadata for this partition.
 */
public void readFromFS() throws IOException {
    FSDataInputStream is = null;
    try {
        Path metaFile = new Path(partitionPath, HOODIE_PARTITION_METAFILE);
        is = fs.open(metaFile);
        props.load(is);
    } catch (IOException ioe) {
        throw new HoodieException("Error reading Hoodie partition metadata for " + partitionPath, ioe);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) HoodieException(org.apache.hudi.exception.HoodieException) IOException(java.io.IOException)

Aggregations

HoodieException (org.apache.hudi.exception.HoodieException)171 IOException (java.io.IOException)87 Path (org.apache.hadoop.fs.Path)45 Schema (org.apache.avro.Schema)35 HoodieIOException (org.apache.hudi.exception.HoodieIOException)35 List (java.util.List)30 ArrayList (java.util.ArrayList)27 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)23 Collectors (java.util.stream.Collectors)21 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)19 Option (org.apache.hudi.common.util.Option)19 HoodieTimeline (org.apache.hudi.common.table.timeline.HoodieTimeline)18 Map (java.util.Map)16 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)16 GenericRecord (org.apache.avro.generic.GenericRecord)15 Arrays (java.util.Arrays)14 HoodieLogFile (org.apache.hudi.common.model.HoodieLogFile)14 Logger (org.apache.log4j.Logger)14 FileStatus (org.apache.hadoop.fs.FileStatus)13 HoodieCommitMetadata (org.apache.hudi.common.model.HoodieCommitMetadata)13