Skip to content

GlusterVolume modification to wrap getPos() functionality in underlying ... #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.BufferedFSInputStream;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RawLocalFileSystem;
Expand Down Expand Up @@ -176,5 +178,37 @@ public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len
public String toString(){
return "Gluster Volume mounted at: " + root;
}


/**
* An FS DataInputStream that guards against the underlying exception
*/
@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
return new WrappedFSDataInputStream(super.open(f, bufferSize));
}


public static class WrappedFSDataInputStream extends FSDataInputStream{
public WrappedFSDataInputStream(FSDataInputStream in) throws IOException {
super(in);
}
long lastPos=0;
@Override
public long getPos() throws IOException {
try{
//Try to call the underlying get pos, but if it fails,
//just return the last valid read. This should be
//correct if the underlying call fails, it will be because
//the stream has been closed (assuming that the last read ended
//at the final position in the stream, and no reads occured after that).
lastPos= ((BufferedFSInputStream)in).getPos();
}
catch(Throwable t){
log.error("Wrapped exception in getPos() : We will return the last valid pos." + t.getMessage());
}
return lastPos;
}
}

}