Search in sources :

Example 1 with ThrottledInputStream

use of org.apache.hadoop.tools.util.ThrottledInputStream in project hadoop by apache.

the class RetriableFileCopyCommand method copyBytes.

@VisibleForTesting
long copyBytes(CopyListingFileStatus source2, long sourceOffset, OutputStream outStream, int bufferSize, Mapper.Context context) throws IOException {
    Path source = source2.getPath();
    byte[] buf = new byte[bufferSize];
    ThrottledInputStream inStream = null;
    long totalBytesRead = 0;
    try {
        inStream = getInputStream(source, context.getConfiguration());
        int bytesRead = readBytes(inStream, buf, sourceOffset);
        while (bytesRead >= 0) {
            totalBytesRead += bytesRead;
            if (action == FileAction.APPEND) {
                sourceOffset += bytesRead;
            }
            outStream.write(buf, 0, bytesRead);
            updateContextStatus(totalBytesRead, context, source2);
            bytesRead = readBytes(inStream, buf, sourceOffset);
        }
        outStream.close();
        outStream = null;
    } finally {
        IOUtils.cleanup(LOG, outStream, inStream);
    }
    return totalBytesRead;
}
Also used : Path(org.apache.hadoop.fs.Path) ThrottledInputStream(org.apache.hadoop.tools.util.ThrottledInputStream) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ThrottledInputStream

use of org.apache.hadoop.tools.util.ThrottledInputStream in project hadoop by apache.

the class RetriableFileCopyCommand method getInputStream.

private static ThrottledInputStream getInputStream(Path path, Configuration conf) throws IOException {
    try {
        FileSystem fs = path.getFileSystem(conf);
        float bandwidthMB = conf.getFloat(DistCpConstants.CONF_LABEL_BANDWIDTH_MB, DistCpConstants.DEFAULT_BANDWIDTH_MB);
        FSDataInputStream in = fs.open(path);
        return new ThrottledInputStream(in, bandwidthMB * 1024 * 1024);
    } catch (IOException e) {
        throw new CopyReadException(e);
    }
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) ThrottledInputStream(org.apache.hadoop.tools.util.ThrottledInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Aggregations

ThrottledInputStream (org.apache.hadoop.tools.util.ThrottledInputStream)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1