Repository: hadoop Updated Branches: refs/heads/trunk ebd797c48 -> ade6d9a61
HDFS-8463. Calling DFSInputStream.seekToNewSource just after stream creation causes NullPointerException. Contributed by Masatake Iwasaki. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ade6d9a6 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ade6d9a6 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ade6d9a6 Branch: refs/heads/trunk Commit: ade6d9a61eb2e57a975f0efcdf8828d51ffec5fd Parents: ebd797c Author: Kihwal Lee <kih...@apache.org> Authored: Thu Jun 4 12:51:00 2015 -0500 Committer: Kihwal Lee <kih...@apache.org> Committed: Thu Jun 4 12:51:00 2015 -0500 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../org/apache/hadoop/hdfs/DFSInputStream.java | 3 +++ .../apache/hadoop/hdfs/TestDFSInputStream.java | 25 ++++++++++++++++++++ 3 files changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/ade6d9a6/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 d65e513..bb65105 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -846,6 +846,9 @@ Release 2.8.0 - UNRELEASED HDFS-3716. Purger should remove stale fsimage ckpt files (J.Andreina via vinayakumarb) + HDFS-8463. Calling DFSInputStream.seekToNewSource just after stream creation + causes NullPointerException (Masatake Iwasaki via kihwal) + Release 2.7.1 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/ade6d9a6/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 8a3f730..6563d7b 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 @@ -1533,6 +1533,9 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, */ @Override public synchronized boolean seekToNewSource(long targetPos) throws IOException { + if (currentNode == null) { + return seekToBlockSource(targetPos); + } boolean markedDead = deadNodes.containsKey(currentNode); addToDeadNodes(currentNode); DatanodeInfo oldNode = currentNode; http://git-wip-us.apache.org/repos/asf/hadoop/blob/ade6d9a6/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInputStream.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInputStream.java index b9ec2ce..26412c8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSInputStream.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hdfs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.hamcrest.CoreMatchers.equalTo; import java.io.File; @@ -28,6 +30,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; +import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.net.unix.DomainSocket; import org.apache.hadoop.net.unix.TemporarySocketDirectory; import org.junit.Assume; @@ -111,4 +114,26 @@ public class TestDFSInputStream { } } + @Test(timeout=60000) + public void testSeekToNewSource() throws IOException { + Configuration conf = new Configuration(); + MiniDFSCluster cluster = + new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); + DistributedFileSystem fs = cluster.getFileSystem(); + Path path = new Path("/testfile"); + DFSTestUtil.createFile(fs, path, 1024, (short) 3, 0); + DFSInputStream fin = fs.dfs.open("/testfile"); + try { + fin.seekToNewSource(100); + assertEquals(100, fin.getPos()); + DatanodeInfo firstNode = fin.getCurrentDatanode(); + assertNotNull(firstNode); + fin.seekToNewSource(100); + assertEquals(100, fin.getPos()); + assertFalse(firstNode.equals(fin.getCurrentDatanode())); + } finally { + fin.close(); + cluster.shutdown(); + } + } }