hadoop git commit: HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or setReadahead is called (cmccabe)
Repository: hadoop Updated Branches: refs/heads/branch-2 cc0668ebe - 1465393d1 HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or setReadahead is called (cmccabe) (cherry picked from commit a9dc5cd7069f721e8c55794b877026ba02537167) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/1465393d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/1465393d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/1465393d Branch: refs/heads/branch-2 Commit: 1465393d14b6d41c81d9913929d3f4a549cd3293 Parents: cc0668e Author: Colin Patrick Mccabe cmcc...@cloudera.com Authored: Mon Feb 9 20:16:41 2015 -0800 Committer: Colin Patrick Mccabe cmcc...@cloudera.com Committed: Mon Feb 9 20:19:48 2015 -0800 -- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../org/apache/hadoop/hdfs/DFSInputStream.java | 11 ++- .../server/datanode/TestCachingStrategy.java| 30 3 files changed, 36 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/1465393d/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 8d49f3c..eb1637c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -590,6 +590,9 @@ Release 2.7.0 - UNRELEASED HDFS-7756. Restore method signature for LocatedBlock#getLocations(). (Ted Yu via yliu) +HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or +setReadahead is called (cmccabe) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/1465393d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java -- 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 9e75333..618f040 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 @@ -580,10 +580,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, } // Will be getting a new BlockReader. -if (blockReader != null) { - blockReader.close(); - blockReader = null; -} +closeCurrentBlockReader(); // // Connect to best DataNode for desired Block, with potential offset @@ -686,10 +683,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, unreleased ByteBuffers allocated by read(). + Please release + builder.toString() + .); } -if (blockReader != null) { - blockReader.close(); - blockReader = null; -} +closeCurrentBlockReader(); super.close(); } @@ -1649,6 +1643,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, DFSClient.LOG.error(error closing blockReader, e); } blockReader = null; +blockEnd = -1; } @Override http://git-wip-us.apache.org/repos/asf/hadoop/blob/1465393d/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java index b1df8ad..709554a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java @@ -369,4 +369,34 @@ public class TestCachingStrategy { } } } + + @Test(timeout=12) + public void testSeekAfterSetDropBehind() throws Exception { +// start a cluster +LOG.info(testSeekAfterSetDropBehind); +Configuration conf = new HdfsConfiguration(); +MiniDFSCluster cluster = null; +String TEST_PATH = /test; +int TEST_PATH_LEN = MAX_TEST_FILE_LEN; +try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) + .build(); + cluster.waitActive(); + FileSystem fs = cluster.getFileSystem(); + createHdfsFile(fs, new Path(TEST_PATH), TEST_PATH_LEN, false); + // verify that we can seek after setDropBehind + FSDataInputStream fis = fs.open(new Path(TEST_PATH)); + try { +
hadoop git commit: HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or setReadahead is called (cmccabe)
Repository: hadoop Updated Branches: refs/heads/trunk 260b5e32c - a9dc5cd70 HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or setReadahead is called (cmccabe) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a9dc5cd7 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a9dc5cd7 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a9dc5cd7 Branch: refs/heads/trunk Commit: a9dc5cd7069f721e8c55794b877026ba02537167 Parents: 260b5e3 Author: Colin Patrick Mccabe cmcc...@cloudera.com Authored: Mon Feb 9 20:16:41 2015 -0800 Committer: Colin Patrick Mccabe cmcc...@cloudera.com Committed: Mon Feb 9 20:16:41 2015 -0800 -- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../org/apache/hadoop/hdfs/DFSInputStream.java | 11 ++- .../server/datanode/TestCachingStrategy.java| 30 3 files changed, 36 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9dc5cd7/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index a841c7e..446c6a3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -890,6 +890,9 @@ Release 2.7.0 - UNRELEASED HDFS-7756. Restore method signature for LocatedBlock#getLocations(). (Ted Yu via yliu) +HDFS-7744. Fix potential NPE in DFSInputStream after setDropBehind or +setReadahead is called (cmccabe) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9dc5cd7/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java -- 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 9e75333..618f040 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 @@ -580,10 +580,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, } // Will be getting a new BlockReader. -if (blockReader != null) { - blockReader.close(); - blockReader = null; -} +closeCurrentBlockReader(); // // Connect to best DataNode for desired Block, with potential offset @@ -686,10 +683,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, unreleased ByteBuffers allocated by read(). + Please release + builder.toString() + .); } -if (blockReader != null) { - blockReader.close(); - blockReader = null; -} +closeCurrentBlockReader(); super.close(); } @@ -1649,6 +1643,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, DFSClient.LOG.error(error closing blockReader, e); } blockReader = null; +blockEnd = -1; } @Override http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9dc5cd7/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java index b1df8ad..709554a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestCachingStrategy.java @@ -369,4 +369,34 @@ public class TestCachingStrategy { } } } + + @Test(timeout=12) + public void testSeekAfterSetDropBehind() throws Exception { +// start a cluster +LOG.info(testSeekAfterSetDropBehind); +Configuration conf = new HdfsConfiguration(); +MiniDFSCluster cluster = null; +String TEST_PATH = /test; +int TEST_PATH_LEN = MAX_TEST_FILE_LEN; +try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) + .build(); + cluster.waitActive(); + FileSystem fs = cluster.getFileSystem(); + createHdfsFile(fs, new Path(TEST_PATH), TEST_PATH_LEN, false); + // verify that we can seek after setDropBehind + FSDataInputStream fis = fs.open(new Path(TEST_PATH)); + try { +Assert.assertTrue(fis.read() != -1); // create BlockReader +