• 修改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: 	mphadoop-zhangchao3mapredstagingzhangchao3502228304.staging to 0700
    Exception in thread "main" java.io.IOException: Failed to set permissions of path: 	mphadoop-zhangchao3mapredstagingzhangchao3502228304.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已经被修改:

    image

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

    image       ------》    image

    image

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

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

     

     

  • 相关阅读:
    git使用
    onethink常用标签的使用示例
    thinkphp中 select() 和find() 方法的区别
    CSS3Ps -Photoshop图层特效转CSS3代码
    普通公司网站代码片段合辑
    IE hack大全
    PHP四种基础算法详解:冒泡,选择,插入和快速排序法
    PHP编程效率的20个要点
    php实现AES/CBC/PKCS5Padding加密解密(又叫:对称加密)
    浏览器桌面提醒,适用于网站“新消息提醒”
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4261970.html
Copyright © 2020-2023  润新知