HADOOP-9692. Improving log message when SequenceFile reader throws EOFException on zero-length file. (Zhe Zhang and Chu Tong via ozawa)
This commit is contained in:
parent
039a1f9e96
commit
513ec3de19
|
@ -902,6 +902,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
|
|
||||||
HADOOP-10406. TestIPC.testIpcWithReaderQueuing may fail. (Xiao Chen via wang)
|
HADOOP-10406. TestIPC.testIpcWithReaderQueuing may fail. (Xiao Chen via wang)
|
||||||
|
|
||||||
|
HADOOP-9692. Improving log message when SequenceFile reader throws
|
||||||
|
EOFException on zero-length file. (Zhe Zhang and Chu Tong via ozawa)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-11785. Reduce the number of listStatus operation in distcp
|
HADOOP-11785. Reduce the number of listStatus operation in distcp
|
||||||
|
|
|
@ -1912,17 +1912,26 @@ public class SequenceFile {
|
||||||
*/
|
*/
|
||||||
private void init(boolean tempReader) throws IOException {
|
private void init(boolean tempReader) throws IOException {
|
||||||
byte[] versionBlock = new byte[VERSION.length];
|
byte[] versionBlock = new byte[VERSION.length];
|
||||||
|
String exceptionMsg = this + " not a SequenceFile";
|
||||||
|
|
||||||
|
// Try to read sequence file header.
|
||||||
|
try {
|
||||||
in.readFully(versionBlock);
|
in.readFully(versionBlock);
|
||||||
|
} catch (EOFException e) {
|
||||||
|
throw new EOFException(exceptionMsg);
|
||||||
|
}
|
||||||
|
|
||||||
if ((versionBlock[0] != VERSION[0]) ||
|
if ((versionBlock[0] != VERSION[0]) ||
|
||||||
(versionBlock[1] != VERSION[1]) ||
|
(versionBlock[1] != VERSION[1]) ||
|
||||||
(versionBlock[2] != VERSION[2]))
|
(versionBlock[2] != VERSION[2])) {
|
||||||
throw new IOException(this + " not a SequenceFile");
|
throw new IOException(this + " not a SequenceFile");
|
||||||
|
}
|
||||||
|
|
||||||
// Set 'version'
|
// Set 'version'
|
||||||
version = versionBlock[3];
|
version = versionBlock[3];
|
||||||
if (version > VERSION[3])
|
if (version > VERSION[3]) {
|
||||||
throw new VersionMismatchException(VERSION[3], version);
|
throw new VersionMismatchException(VERSION[3], version);
|
||||||
|
}
|
||||||
|
|
||||||
if (version < BLOCK_COMPRESS_VERSION) {
|
if (version < BLOCK_COMPRESS_VERSION) {
|
||||||
UTF8 className = new UTF8();
|
UTF8 className = new UTF8();
|
||||||
|
|
|
@ -522,6 +522,27 @@ public class TestSequenceFile extends TestCase {
|
||||||
assertTrue("InputStream for " + path + " should have been closed.", openedFile[0].isClosed());
|
assertTrue("InputStream for " + path + " should have been closed.", openedFile[0].isClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to makes sure zero length sequence file is handled properly while
|
||||||
|
* initializing.
|
||||||
|
*/
|
||||||
|
public void testInitZeroLengthSequenceFile() throws IOException {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
LocalFileSystem fs = FileSystem.getLocal(conf);
|
||||||
|
|
||||||
|
// create an empty file (which is not a valid sequence file)
|
||||||
|
Path path = new Path(System.getProperty("test.build.data", ".") +
|
||||||
|
"/zerolength.seq");
|
||||||
|
fs.create(path).close();
|
||||||
|
|
||||||
|
try {
|
||||||
|
new SequenceFile.Reader(conf, SequenceFile.Reader.file(path));
|
||||||
|
fail("IOException expected.");
|
||||||
|
} catch (IOException expected) {
|
||||||
|
assertTrue(expected instanceof EOFException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that makes sure createWriter succeeds on a file that was
|
* Test that makes sure createWriter succeeds on a file that was
|
||||||
* already created
|
* already created
|
||||||
|
|
Loading…
Reference in New Issue