HDFS-5881. Fix skip() of the short-circuit local reader(legacy). Contributed by Kihwal Lee.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1565310 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kihwal Lee 2014-02-06 15:45:47 +00:00
parent 24775c10ef
commit ab96a0838d
3 changed files with 13 additions and 3 deletions

View File

@ -337,6 +337,8 @@ Release 2.4.0 - UNRELEASED
HDFS-5709. Improve NameNode upgrade with existing reserved paths and path
components. (Andrew Wang via atm)
HDFS-5881. Fix skip() of the short-circuit local reader(legacy). (kihwal)
Release 2.3.0 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -629,7 +629,7 @@ public synchronized long skip(long n) throws IOException {
skipBuf = new byte[bytesPerChecksum];
}
int ret = read(skipBuf, 0, (int)(n - remaining));
return ret;
return (remaining + ret);
}
// optimize for big gap: discard the current buffer, skip to
@ -660,9 +660,9 @@ public synchronized long skip(long n) throws IOException {
int ret = read(skipBuf, 0, myOffsetFromChunkBoundary);
if (ret == -1) { // EOS
return toskip;
return (toskip + remaining);
} else {
return (toskip + ret);
return (toskip + remaining + ret);
}
}

View File

@ -1345,6 +1345,14 @@ public synchronized void seek(long targetPos) throws IOException {
pos += blockReader.skip(diff);
if (pos == targetPos) {
done = true;
} else {
// The range was already checked. If the block reader returns
// something unexpected instead of throwing an exception, it is
// most likely a bug.
String errMsg = "BlockReader failed to seek to " +
targetPos + ". Instead, it seeked to " + pos + ".";
DFSClient.LOG.warn(errMsg);
throw new IOException(errMsg);
}
} catch (IOException e) {//make following read to retry
if(DFSClient.LOG.isDebugEnabled()) {