From 71aa608b84afcbe19dc38ca7c43c6e750d5df97a Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Mon, 28 Apr 2014 20:20:10 +0000 Subject: [PATCH] HDFS-6288. DFSInputStream Pread doesn't update ReadStatistics. Contributed by Juan Yu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1590776 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../org/apache/hadoop/hdfs/DFSInputStream.java | 2 ++ .../java/org/apache/hadoop/hdfs/TestPread.java | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7adbd42477..6fc1882e9d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -412,6 +412,9 @@ Release 2.5.0 - UNRELEASED HDFS-6218. Audit log should use true client IP for proxied webhdfs operations. (daryn via kihwal) + HDFS-6288. DFSInputStream Pread doesn't update ReadStatistics. + (Juan Yu via wang) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index 2239de08aa..1750aa7a30 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -1038,6 +1038,8 @@ private void actualGetFromOneDataNode(final DNAddrPair datanode, setConfiguration(dfsClient.getConfiguration()). build(); int nread = reader.readAll(buf, offset, len); + updateReadStatistics(readStatistics, nread, reader); + if (nread != len) { throw new IOException("truncated return from reader.read(): " + "excpected " + len + ", got " + nread); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java index 65eaf67bcb..a1596bfb82 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java @@ -88,11 +88,25 @@ private void checkAndEraseData(byte[] actual, int from, byte[] expected, String private void doPread(FSDataInputStream stm, long position, byte[] buffer, int offset, int length) throws IOException { int nread = 0; + long totalRead = 0; + DFSInputStream dfstm = null; + + if (stm.getWrappedStream() instanceof DFSInputStream) { + dfstm = (DFSInputStream) (stm.getWrappedStream()); + totalRead = dfstm.getReadStatistics().getTotalBytesRead(); + } + while (nread < length) { - int nbytes = stm.read(position+nread, buffer, offset+nread, length-nread); + int nbytes = + stm.read(position + nread, buffer, offset + nread, length - nread); assertTrue("Error in pread", nbytes > 0); nread += nbytes; } + + if (dfstm != null) { + assertEquals("Expected read statistic to be incremented", length, dfstm + .getReadStatistics().getTotalBytesRead() - totalRead); + } } private void pReadFile(FileSystem fileSys, Path name) throws IOException {