diff --git a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java index 8107f862..662f6982 100644 --- a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java +++ b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java @@ -67,8 +67,15 @@ public GlusterFileSystem(){ log.info("GIT INFO="+v); log.info("GIT_TAG="+v.getTag()); } - - public GlusterFileSystem(FileSystem rawLocalFileSystem){ + + /** + * An internal constructor for creating FlusterFileSystem from a rawlocal fs. + * Example usage: + * + * FileSystem fs = new GlusterFileSystem(new GlusterVolume()); + * + */ + protected GlusterFileSystem(FileSystem rawLocalFileSystem){ super(rawLocalFileSystem); rfs=rawLocalFileSystem; } @@ -113,6 +120,11 @@ public void copyToLocalFile(boolean delSrc,Path src,Path dst) throws IOException FileUtil.copy(srcFs, src, dstFs, dst, delSrc, getConf()); } + @Override + protected void checkPath(Path path){ + Util.checkPath(this, path); + } + public String toString(){ return "Gluster File System, no CRC."; } diff --git a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystemCRC.java b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystemCRC.java index 2739a77d..84944222 100644 --- a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystemCRC.java +++ b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystemCRC.java @@ -71,6 +71,12 @@ public void copyToLocalFile(boolean delSrc, Path src, Path dst) throws IOExcepti FileUtil.copy(srcFs, src, dstFs, dst, delSrc, getConf()); } + + @Override + protected void checkPath(Path path){ + Util.checkPath(this, path); + } + public String toString(){ return "Gluster File System - CRC Enabled"; } diff --git a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java index ea2699cf..010136ad 100644 --- a/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java +++ b/src/main/java/org/apache/hadoop/fs/glusterfs/GlusterVolume.java @@ -35,6 +35,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * + */ public class GlusterVolume extends RawLocalFileSystem{ static final Logger log = LoggerFactory.getLogger(GlusterFileSystemCRC.class); @@ -53,7 +56,7 @@ public GlusterVolume(Configuration conf){ public URI getUri() { return NAME; } public void setConf(Configuration conf){ - log.info("Initializing gluster volume.."); + log.info("Initializing gluster volume: " + conf.toString()); super.setConf(conf); String getfattrcmd = null; if(conf!=null){ @@ -154,13 +157,25 @@ public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len result=attr.getPathInfo(f.getPath(), start, len); if(result==null){ - log.info("Problem getting destination host for file "+f.getPath()); + log.info("Problem getting destination host for file "+f.getPath() + " start=" + start + " len=" + len) ; return null; } return result; } + + @Override + protected void checkPath(Path path){ + Util.checkPath(this, path); + } + /** + * May revert to include this at some point. + * protected void checkPath(Path arg0){ + * super.checkPath(arg0); + * } + */ + public String toString(){ return "Gluster Volume mounted at: " + root; } diff --git a/src/main/java/org/apache/hadoop/fs/glusterfs/Util.java b/src/main/java/org/apache/hadoop/fs/glusterfs/Util.java index 6c26be5b..9ea36c03 100644 --- a/src/main/java/org/apache/hadoop/fs/glusterfs/Util.java +++ b/src/main/java/org/apache/hadoop/fs/glusterfs/Util.java @@ -26,7 +26,9 @@ import java.io.File; import java.io.IOException; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.util.Shell; public class Util{ @@ -50,4 +52,34 @@ public static String[] getGET_PERMISSION_COMMAND(){ public static final boolean WINDOWS /* borrowed from Path.WINDOWS */ =System.getProperty("os.name").startsWith("Windows"); // / loads permissions, owner, and group from `ls -ld` + + /** + * Check that a Path belongs to this FileSystem. + * lenient : doesn't check authority. This might be temporary ~ + * there could be a better long term implementation. + * Having custom implementation here is critical for debugging, because + * existing checkPath in hadoop doesn't print all the scheme/auth values. + * */ + public static void checkPath(FileSystem fs, Path path) { + String thisScheme = fs.getUri().getScheme(); + String thisAuthority = fs.getUri().getAuthority(); + + String thatScheme = path.toUri().getScheme(); + String thatAuthority = path.toUri().getAuthority(); + + //String debugInfo="GV: checking path " +path+ " scheme=" + thisScheme+" auth="+thisAuthority + " vs scheme=" + thatScheme +" auth=" + thatAuthority; + //log.info(debugInfo); + //log.warn("Not validating authority"); + //now the exception will be traceable in the logs above . + try{ + //super.checkPath(path); + if(thisScheme.equals(thatScheme) || (thatScheme==null && thatAuthority==null)) + return ; + else + throw new RuntimeException("Schemes dont match: expecting :" + thisScheme + " but input path is :" + thatScheme); + } + catch(Throwable t){ + throw new RuntimeException("ERROR matching schemes/auths: " + thisScheme +" ~ " + thisAuthority + " : " + thatScheme + " ~ " + thatAuthority ); + } + } }