Hdfs的rename问题

来源:互联网 发布:淘宝不是卖家怎么贷款 编辑:程序博客网 时间:2024/04/28 17:21

公司之前有些人使用hadoop的原生api的rename方法。因为他只返回true或者false 并不报错。所以当在无法rename的时候不知道问题在哪 就怪我们搭建平台的人


所以我被去要求研究下问题所在


调研了hadoop的源代码 发现rename的方法上有这几段注释


 /**   * Renames Path src to Path dst   * <ul>   * <li   * <li>Fails if src is a file and dst is a directory.   * <li>Fails if src is a directory and dst is a file.   * <li>Fails if the parent of dst does not exist or is a file.   * </ul>   * <p>   * If OVERWRITE option is not passed as an argument, rename fails   * if the dst already exists.   * <p>   * If OVERWRITE option is passed as an argument, rename overwrites   * the dst if it is a file or an empty directory. Rename fails if dst is   * a non-empty directory.   * <p>   * Note that atomicity of rename is dependent on the file system   * implementation. Please refer to the file system documentation for   * details. This default implementation is non atomic.   * <p>   * This method is deprecated since it is a temporary method added to    * support the transition from FileSystem to FileContext for user    * applications.   * 


这些都是出现错误的原因:

1 源文件是文件 但目标文件是目录

2 源文件是目录 但目标文件是文件

3 目标文件的父目录不存在

4 ..

5 ..

因为测试到第3步的时候就发现了他们的问题 所以后面的没有继续研究

他们有对源文件的父目录进行判断 但是没有对目标文件的父目录进行判断

所以最后的解决办法是:

首先代码里最好要标出  源文件和目标文件的具体目录 然后

例如/apps/cal/normal/input/2/201601/123456.txt    也可以手动去判断/apps/cal/normal/input/2/201601/ 这个目录是否存在


因为好几次的问题 都是因为coder自己觉得没问题  但是目标文件的父目录是不存在的 

经过排查后 该问题解决




0 0