【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题

    在Hadoop Eclipse开发环境搭建这篇文章中,第15.)中提到权限相关的异常,如下:

复制代码
15/01/30 10:08:17 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
15/01/30 10:08:17 ERROR security.UserGroupInformation: PriviledgedActionException as:zhangchao3 cause:java.io.IOException: Failed to set permissions of path: \tmp\hadoop-zhangchao3\mapred\staging\zhangchao3502228304\.staging to 0700
Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-zhangchao3\mapred\staging\zhangchao3502228304\.staging to 0700
    at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:689)
    at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:662)
    at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:509)
    at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:344)
    at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:189)
    at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:116)
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:856)
    at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:850)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
    at org.apache.hadoop.examples.WordCount.main(WordCount.java:68)
复制代码

    根据提示信息,可以看到,这个异常是org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:689)行抛出来的,把这个位置的源代码贴出来,研究一下:

复制代码
private static void checkReturnValue(boolean rv, File p, 
                                       FsPermission permission
                                       ) throws IOException {
    if (!rv) {
      throw new IOException("Failed to set permissions of path: " + p + 
                            " to " + 
                            String.format("%04o", permission.toShort()));
    }
  }
复制代码

在上面的异常信息中,FileUtil.java:689行是 throw new IOException(“Failed to ….., 我直接将这个函数的if语句去掉,如下:

private static void checkReturnValue(boolean rv, File p, FsPermission permission)
    throws IOException
  {}

    这样,chekReturnValue成为一个空函数,这样就不会对权限进行检查,在/home/hadoop/hadoop-1.0.3/中执行, ant jar进行编译,编译中可能遇到的问题见:编译hadoop遇到maven timeout ,编译好了后,生成如下的文件:

image

    将编译好生成的hadoop-core-1.0.4-SNAPSHOT.jar文件拷贝到windows上,使用Java Decoder可以看到checkReturnValue已经被修改:

【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题_第1张图片

 

将hadoop-core-1.0.4-SNAPSHOT.jar,修改为hadoop-core-1.0.3.jar文件,覆盖eclipse工程中的hadoop-core-1.0.3.jar文件:

【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题_第2张图片       ------》    【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题_第3张图片

 

【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题_第4张图片

 

重新执行Run on hadoop,就可以成功的运行了。(如何执行Run on hadoop见:Hadoop Eclipse开发环境搭建 11节)

 

 

 

修改后的jar包下载地址:http://download.csdn.net/download/uestczhangchao/8420249 

你可能感兴趣的:(fileutil)