Skip to content

Commit

Permalink
HDFS-8463. Calling DFSInputStream.seekToNewSource just after stream c…
Browse files Browse the repository at this point in the history
…reation causes NullPointerException. Contributed by Masatake Iwasaki.
  • Loading branch information
kihwal committed Jun 4, 2015
1 parent ebd797c commit ade6d9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,9 @@ private boolean seekToBlockSource(long targetPos)
*/
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +30,7 @@
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;
Expand Down Expand Up @@ -111,4 +114,26 @@ public void testSkipWithLocalBlockReader() throws IOException {
}
}

@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();
}
}
}

0 comments on commit ade6d9a

Please sign in to comment.