From e32af6034bb07c654c3a6762a4e478f5d60ecc8a Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Sun, 7 Oct 2012 21:16:08 +0000 Subject: [PATCH] HDFS-3682. MiniDFSCluster#init should provide more info when it fails. Contributed by Todd Lipcon git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1395385 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../apache/hadoop/hdfs/MiniDFSCluster.java | 39 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index ecfc996d11..3aa7c25db8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -262,6 +262,9 @@ Release 2.0.3-alpha - Unreleased HDFS-3483. Better error message when hdfs fsck is run against a ViewFS config. (Stephen Fritz via atm) + HDFS-3682. MiniDFSCluster#init should provide more info when it fails. + (todd via eli) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java index 3bb65c3331..0c238581ba 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java @@ -624,14 +624,20 @@ private void initMiniDFSCluster( } federation = nnTopology.isFederated(); - createNameNodesAndSetConf( - nnTopology, manageNameDfsDirs, manageNameDfsSharedDirs, - enableManagedDfsDirsRedundancy, - format, operation, clusterId, conf); - + try { + createNameNodesAndSetConf( + nnTopology, manageNameDfsDirs, manageNameDfsSharedDirs, + enableManagedDfsDirsRedundancy, + format, operation, clusterId, conf); + } catch (IOException ioe) { + LOG.error("IOE creating namenodes. Permissions dump:\n" + + createPermissionsDiagnosisString(data_dir)); + throw ioe; + } if (format) { if (data_dir.exists() && !FileUtil.fullyDelete(data_dir)) { - throw new IOException("Cannot remove data directory: " + data_dir); + throw new IOException("Cannot remove data directory: " + data_dir + + createPermissionsDiagnosisString(data_dir)); } } @@ -647,6 +653,27 @@ private void initMiniDFSCluster( ProxyUsers.refreshSuperUserGroupsConfiguration(conf); } + /** + * @return a debug string which can help diagnose an error of why + * a given directory might have a permissions error in the context + * of a test case + */ + private String createPermissionsDiagnosisString(File path) { + StringBuilder sb = new StringBuilder(); + while (path != null) { + sb.append("path '" + path + "': ").append("\n"); + sb.append("\tabsolute:").append(path.getAbsolutePath()).append("\n"); + sb.append("\tpermissions: "); + sb.append(path.isDirectory() ? "d": "-"); + sb.append(path.canRead() ? "r" : "-"); + sb.append(path.canWrite() ? "w" : "-"); + sb.append(path.canExecute() ? "x" : "-"); + sb.append("\n"); + path = path.getParentFile(); + } + return sb.toString(); + } + private void createNameNodesAndSetConf(MiniDFSNNTopology nnTopology, boolean manageNameDfsDirs, boolean manageNameDfsSharedDirs, boolean enableManagedDfsDirsRedundancy, boolean format,