hdfs-2556:单元测试目录和权限

2nc8po8w  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(287)

我正在尝试对hadoop进行junit测试,我编写了一个测试用例,使用minidfscluster、minimrcluster和junit在本地mini-hadoop环境中运行。
但是我得到了这个错误:

WARNING: Metrics system not started: Cannot locate configuration: tried hadoop-metrics2-datanode.properties, hadoop-metrics2.properties
Dec 18, 2012 4:42:29 PM org.apache.hadoop.hdfs.server.datanode.DataNode makeInstance
WARNING: Invalid directory in dfs.data.dir: Incorrect permission for build/test/data/dfs/data/data1, expected: rwxr-xr-x, while actual: rwxrwxr-x
Dec 18, 2012 4:42:29 PM org.apache.hadoop.hdfs.server.datanode.DataNode makeInstance
WARNING: Invalid directory in dfs.data.dir: Incorrect permission for build/test/data/dfs/data/data2, expected: rwxr-xr-x, while actual: rwxrwxr-x
Dec 18, 2012 4:42:29 PM org.apache.hadoop.hdfs.server.datanode.DataNode makeInstance
SEVERE: All directories in dfs.data.dir are invalid.

这看起来像是hdfs的bughttps://issues.apache.org/jira/browse/hdfs-2556 这仍然悬而未决。
既然我不能更改我正在使用的hadoop版本,有没有办法强制hadoop接受这些权限?
我试过:system.setproperty(“dfs.datanode.data.dir.perm”,“775”);但是hadoop忽略了它们。
而且,我不能手动更改权限,似乎小集群每次运行都会重新创建权限。
有没有一种不用修改hadoop或者改变版本就能克服这个问题的方法?谢谢。

jgwigjjp

jgwigjjp1#

你可以使用这里提供的解决方法,https://www.mail-archive.com/issues@hbase.apache.org/msg52961.html
更新:链接中的代码片段(以防链接中断)

try {
        Process process = Runtime.getRuntime().exec("/bin/sh -c umask");
        BufferedReader br = new BufferedReader(new
                InputStreamReader(process.getInputStream()));
        int rc = process.waitFor();
        if (rc == 0) {
            String umask = br.readLine();

            int umaskBits = Integer.parseInt(umask, 8);
            int permBits = 0777 & ~umaskBits;
            String perms = Integer.toString(permBits, 8);

            log.info("Setting dfs.datanode.data.dir.perm to " + perms);
            hBaseTestingUtility.getConfiguration().set("dfs.datanode.data.dir.perm", perms);
        } else {
            log.warn("Failed running umask command in a shell, nonzero return value ");
        }
    } catch (Exception e) {
        // ignore errors, we might not be running on POSIX, or "sh" might not be on the path
        log.warn("Couldn't get umask", e);
    }

相关问题