Skip to content

Commit

Permalink
fix synchronizatio bug and stream position bug in HdfsFileInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingfei committed Dec 29, 2014
1 parent 12dfb49 commit 5bd78fb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/tachyon/hadoop/HdfsFileInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public int read(byte[] b, int off, int len) throws IOException {
* number of bytes read. This does not change the current offset of a file, and is thread-safe.
*/
@Override
public int read(long position, byte[] buffer, int offset, int length) throws IOException {
public synchronized int read(long position, byte[] buffer, int offset, int length)
throws IOException {
int ret = -1;
long oldPos = getPos();
if ((position < 0) || (position >= mTachyonFile.length())) {
Expand All @@ -174,6 +175,7 @@ public int read(long position, byte[] buffer, int offset, int length) throws IOE
try {
seek(position);
ret = mTachyonFileInputStream.read(buffer, offset, length);
mCurrentPosition += ret;
return ret;
} finally {
seek(oldPos);
Expand All @@ -184,6 +186,7 @@ public int read(long position, byte[] buffer, int offset, int length) throws IOE
try {
mHdfsInputStream.seek(position);
ret = mHdfsInputStream.read(buffer, offset, length);
mCurrentPosition += ret;
return ret;
} finally {
mHdfsInputStream.seek(oldPos);
Expand Down

0 comments on commit 5bd78fb

Please sign in to comment.