Hadoop源码阅读-HDFS-day2
2016-03-28 23:30
435 查看
昨天看到了AbstractFileSystem,也知道应用访问文件是通过FileContext这个类,今天来看这个类的源代码,先看下这个类老长的注释说明
View Code
next 是一个一般的helper函数,需要被实例重写,从而在给定路径的文件系统上执行特定的操作,可能会抛UnresolvedLinkException异常
resolve 通过next执行特定的操作,反复的调用next函数,知道路径上所有的符号链接被解析
/** * Generic helper function overridden on instantiation to perform a * specific operation on the given file system using the given path * which may result in an UnresolvedLinkException. * @param fs AbstractFileSystem to perform the operation on. * @param p Path given the file system. * @return Generic type determined by the specific implementation. * @throws UnresolvedLinkException If symbolic link <code>path</code> could * not be resolved * @throws IOException an I/O error occurred */ abstract public T next(final AbstractFileSystem fs, final Path p) throws IOException, UnresolvedLinkException; /** * Performs the operation specified by the next function, calling it * repeatedly until all symlinks in the given path are resolved. * @param fc FileContext used to access file systems. * @param path The path to resolve symlinks on. * @return Generic type determined by the implementation of next. * @throws IOException */ public T resolve(final FileContext fc, final Path path) throws IOException { int count = 0; T in = null; Path p = path; // NB: More than one AbstractFileSystem can match a scheme, eg // "file" resolves to LocalFs but could have come by RawLocalFs. AbstractFileSystem fs = fc.getFSofPath(p); // Loop until all symlinks are resolved or the limit is reached for (boolean isLink = true; isLink;) { try { in = next(fs, p); isLink = false; } catch (UnresolvedLinkException e) { if (!fc.resolveSymlinks) { throw new IOException("Path " + path + " contains a symlink" + " and symlink resolution is disabled (" + CommonConfigurationKeys.FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_KEY + ").", e); } if (!FileSystem.areSymlinksEnabled()) { throw new IOException("Symlink resolution is disabled in" + " this version of Hadoop."); } if (count++ > FsConstants.MAX_PATH_LINKS) { throw new IOException("Possible cyclic loop while " + "following symbolic link " + path); } // Resolve the first unresolved path component p = qualifySymlinkTarget(fs.getUri(), p, fs.getLinkTarget(p)); fs = fc.getFSofPath(p); } } return in; }
View Code
next 是一个一般的helper函数,需要被实例重写,从而在给定路径的文件系统上执行特定的操作,可能会抛UnresolvedLinkException异常
resolve 通过next执行特定的操作,反复的调用next函数,知道路径上所有的符号链接被解析
相关文章推荐
- Linux下清理内存和Cache方法
- Shell颜色及显示git分支配置
- 《photoshop cc 新功能 生成图像资源》智能切图逆天啦!
- windows系统批处理脚本自动循环验证tomcat中startup.bat执行结束
- 基于UDP的Linux畅聊系统(ncurse库和json库)
- gentoo linux安装过程中出现的错误及解决方案
- shell脚本--部署应用到tomcat并启动tomcat
- tomcat 的 SSL 配置
- 利用shell输入整块文字
- 大型网站核心架构要素 之一(总览篇)
- discuz x3.2修改浏览器头部小图标,使网站看起来更专业
- linux kernel 中的链表(一)
- linux下安装JDK和tomcat以及遇到的误区
- Self-Paced Training (3) - Docker Operations
- CentOS7.2 Linux 内核版本查看简述
- Linux 线程同步的三种方法
- docker(2)
- POJ 3050(Hopscotch 穷竭搜索)
- 搭建6个节点的hadoop 1.2.1 集群
- MediaWiki安装及Wiki网站搭建