HDFS-7681. Change ReplicaInputStreams constructor to take InputStream(s) instead of FileDescriptor(s). Contributed by Joe Pallas

This commit is contained in:
Tsz-Wo Nicholas Sze 2015-01-28 15:59:33 -08:00
parent cff05bff1f
commit 5a0051f4da
4 changed files with 15 additions and 6 deletions

View File

@ -141,6 +141,9 @@ Trunk (Unreleased)
HDFS-7430. Rewrite the BlockScanner to use O(1) memory and use multiple
threads (cmccabe)
HDFS-7681. Change ReplicaInputStreams constructor to take InputStream(s)
instead of FileDescriptor(s). (Joe Pallas via szetszwo)
OPTIMIZATIONS
BUG FIXES

View File

@ -33,11 +33,11 @@ public class ReplicaInputStreams implements Closeable {
private final FsVolumeReference volumeRef;
/** Create an object with a data input stream and a checksum input stream. */
public ReplicaInputStreams(FileDescriptor dataFd, FileDescriptor checksumFd,
public ReplicaInputStreams(InputStream dataStream, InputStream checksumStream,
FsVolumeReference volumeRef) {
this.volumeRef = volumeRef;
this.dataIn = new FileInputStream(dataFd);
this.checksumIn = new FileInputStream(checksumFd);
this.dataIn = dataStream;
this.checksumIn = checksumStream;
}
/** @return the data input stream. */

View File

@ -642,8 +642,14 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
if (ckoff > 0) {
metaInFile.seek(ckoff);
}
return new ReplicaInputStreams(
blockInFile.getFD(), metaInFile.getFD(), ref);
InputStream blockInStream = new FileInputStream(blockInFile.getFD());
try {
InputStream metaInStream = new FileInputStream(metaInFile.getFD());
return new ReplicaInputStreams(blockInStream, metaInStream, ref);
} catch (IOException e) {
IOUtils.cleanup(null, blockInStream);
throw e;
}
} catch (IOException e) {
IOUtils.cleanup(null, ref);
throw e;

View File

@ -137,7 +137,7 @@ public class ExternalDatasetImpl implements FsDatasetSpi<ExternalVolumeImpl> {
@Override
public ReplicaInputStreams getTmpInputStreams(ExtendedBlock b, long blkoff,
long ckoff) throws IOException {
return new ReplicaInputStreams(FileDescriptor.in, FileDescriptor.in, null);
return new ReplicaInputStreams(null, null, null);
}
@Override