1

我正在尝试在 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 错误https://issues.apache.org/jira/browse/HDFS-2556 。

由于我无法更改我正在使用的 hadoop 版本,有没有办法强制 hadoop 接受这些权限?

我试过: System.setProperty("dfs.datanode.data.dir.perm", "775"); 但是 hadoop 忽略了它们。

此外,我无法手动更改权限,似乎迷你集群每次运行都会重新创建它们。

有没有办法在不修改 hadoop 或更改版本的情况下克服这个问题?谢谢。

4

1 回答 1

0

您可以使用此处提供的解决方法, 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);
    }
于 2014-08-11T21:21:43.283 回答