HADOOP-6177. FSInputChecker.getPos() would return position greater than the file size. Contributed by Hong Tang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@803190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hairong Kuang 2009-08-11 16:26:55 +00:00
parent 5fe6906f2a
commit d70dd1a2df
4 changed files with 17 additions and 8 deletions

View File

@ -502,6 +502,9 @@ Trunk (unreleased changes)
HADOOP-5638. More improvement on block placement performance. (hairong) HADOOP-5638. More improvement on block placement performance. (hairong)
HADOOP-6180. NameNode slowed down when many files with same filename
were moved to Trash. (Boris Shkolnik via hairong)
BUG FIXES BUG FIXES
HADOOP-5379. CBZip2InputStream to throw IOException on data crc error. HADOOP-5379. CBZip2InputStream to throw IOException on data crc error.
@ -908,6 +911,9 @@ Trunk (unreleased changes)
HADOOP-6124. Fix javac warning detection in test-patch.sh. (Giridharan HADOOP-6124. Fix javac warning detection in test-patch.sh. (Giridharan
Kesavan via szetszwo) Kesavan via szetszwo)
HADOOP-6177. FSInputChecker.getPos() would return position greater
than the file size. (Hong Tang via hairong)
Release 0.20.1 - Unreleased Release 0.20.1 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES
@ -4466,9 +4472,6 @@ Release 0.17.0 - 2008-05-18
exponentially increasing number of records (up to 10,000 exponentially increasing number of records (up to 10,000
records/log). (Zheng Shao via omalley) records/log). (Zheng Shao via omalley)
HADOOP-6180. NameNode slowed down when many files with same filename
were moved to Trash. (Boris Shkolnik via hairong)
BUG FIXES BUG FIXES
HADOOP-2195. '-mkdir' behaviour is now closer to Linux shell in case of HADOOP-2195. '-mkdir' behaviour is now closer to Linux shell in case of

View File

@ -174,6 +174,7 @@ abstract public class FSInputChecker extends FSInputStream {
assert(pos>=count); assert(pos>=count);
// fill internal buffer // fill internal buffer
count = readChecksumChunk(buf, 0, buf.length); count = readChecksumChunk(buf, 0, buf.length);
if (count < 0) count = 0;
} }
/* /*

View File

@ -54,6 +54,10 @@ public class TestChecksumFileSystem extends TestCase {
fout.write("testing you".getBytes()); fout.write("testing you".getBytes());
fout.close(); fout.close();
TestLocalFileSystem.readFile(localFs, testPath, 128);
TestLocalFileSystem.readFile(localFs, testPath, 512);
TestLocalFileSystem.readFile(localFs, testPath, 1024);
localFs.delete(localFs.getChecksumFile(testPath), true); localFs.delete(localFs.getChecksumFile(testPath), true);
assertTrue("checksum deleted", !localFs.exists(localFs.getChecksumFile(testPath))); assertTrue("checksum deleted", !localFs.exists(localFs.getChecksumFile(testPath)));
@ -64,7 +68,7 @@ public class TestChecksumFileSystem extends TestCase {
boolean errorRead = false; boolean errorRead = false;
try { try {
TestLocalFileSystem.readFile(localFs, testPath); TestLocalFileSystem.readFile(localFs, testPath, 1024);
}catch(ChecksumException ie) { }catch(ChecksumException ie) {
errorRead = true; errorRead = true;
} }
@ -72,7 +76,7 @@ public class TestChecksumFileSystem extends TestCase {
//now setting verify false, the read should succeed //now setting verify false, the read should succeed
localFs.setVerifyChecksum(false); localFs.setVerifyChecksum(false);
String str = TestLocalFileSystem.readFile(localFs, testPath); String str = TestLocalFileSystem.readFile(localFs, testPath, 1024);
assertTrue("read", "testing".equals(str)); assertTrue("read", "testing".equals(str));
} }

View File

@ -35,13 +35,14 @@ public class TestLocalFileSystem extends TestCase {
stm.close(); stm.close();
} }
static String readFile(FileSystem fs, Path name) throws IOException { static String readFile(FileSystem fs, Path name, int buflen) throws IOException {
byte[] b = new byte[1024]; byte[] b = new byte[buflen];
int offset = 0; int offset = 0;
FSDataInputStream in = fs.open(name); FSDataInputStream in = fs.open(name);
for(int remaining, n; for(int remaining, n;
(remaining = b.length - offset) > 0 && (n = in.read(b, offset, remaining)) != -1; (remaining = b.length - offset) > 0 && (n = in.read(b, offset, remaining)) != -1;
offset += n); offset += n);
assertEquals(offset, Math.min(b.length, in.getPos()));
in.close(); in.close();
String s = new String(b, 0, offset); String s = new String(b, 0, offset);