HDFS-10986. DFSAdmin should log detailed error message if any. Contributed by MingLiang Liu
This commit is contained in:
parent
d3c4465147
commit
0884c31aec
|
@ -908,8 +908,7 @@ public class DFSAdmin extends FsShell {
|
||||||
System.out.println("Balancer bandwidth is " + bandwidth
|
System.out.println("Balancer bandwidth is " + bandwidth
|
||||||
+ " bytes per second.");
|
+ " bytes per second.");
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.err.println("Datanode unreachable.");
|
throw new IOException("Datanode unreachable. " + ioe, ioe);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2075,7 +2074,7 @@ public class DFSAdmin extends FsShell {
|
||||||
dnProxy.evictWriters();
|
dnProxy.evictWriters();
|
||||||
System.out.println("Requested writer eviction to datanode " + dn);
|
System.out.println("Requested writer eviction to datanode " + dn);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
return -1;
|
throw new IOException("Datanode unreachable. " + ioe, ioe);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2086,8 +2085,7 @@ public class DFSAdmin extends FsShell {
|
||||||
DatanodeLocalInfo dnInfo = dnProxy.getDatanodeInfo();
|
DatanodeLocalInfo dnInfo = dnProxy.getDatanodeInfo();
|
||||||
System.out.println(dnInfo.getDatanodeLocalReport());
|
System.out.println(dnInfo.getDatanodeLocalReport());
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.err.println("Datanode unreachable.");
|
throw new IOException("Datanode unreachable. " + ioe, ioe);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs.tools;
|
package org.apache.hadoop.hdfs.tools;
|
||||||
|
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
|
||||||
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY;
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -68,6 +69,7 @@ public class TestDFSAdmin {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
conf = new Configuration();
|
conf = new Configuration();
|
||||||
|
conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 3);
|
||||||
restartCluster();
|
restartCluster();
|
||||||
|
|
||||||
admin = new DFSAdmin();
|
admin = new DFSAdmin();
|
||||||
|
@ -105,7 +107,7 @@ public class TestDFSAdmin {
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.shutdown();
|
cluster.shutdown();
|
||||||
}
|
}
|
||||||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
|
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
||||||
cluster.waitActive();
|
cluster.waitActive();
|
||||||
datanode = cluster.getDataNodes().get(0);
|
datanode = cluster.getDataNodes().get(0);
|
||||||
}
|
}
|
||||||
|
@ -135,66 +137,58 @@ public class TestDFSAdmin {
|
||||||
@Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
public void testGetDatanodeInfo() throws Exception {
|
public void testGetDatanodeInfo() throws Exception {
|
||||||
redirectStream();
|
redirectStream();
|
||||||
final Configuration dfsConf = new HdfsConfiguration();
|
final DFSAdmin dfsAdmin = new DFSAdmin(conf);
|
||||||
final int numDn = 2;
|
|
||||||
|
|
||||||
/* init cluster */
|
for (int i = 0; i < cluster.getDataNodes().size(); i++) {
|
||||||
try (MiniDFSCluster miniCluster = new MiniDFSCluster.Builder(dfsConf)
|
|
||||||
.numDataNodes(numDn).build()) {
|
|
||||||
|
|
||||||
miniCluster.waitActive();
|
|
||||||
assertEquals(numDn, miniCluster.getDataNodes().size());
|
|
||||||
final DFSAdmin dfsAdmin = new DFSAdmin(dfsConf);
|
|
||||||
|
|
||||||
/* init reused vars */
|
|
||||||
List<String> outs = null;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test erroneous run
|
|
||||||
*/
|
|
||||||
resetStream();
|
resetStream();
|
||||||
outs = Lists.newArrayList();
|
final DataNode dn = cluster.getDataNodes().get(i);
|
||||||
|
final String addr = String.format(
|
||||||
/* invoke getDatanodeInfo */
|
"%s:%d",
|
||||||
ret = ToolRunner.run(dfsAdmin,
|
dn.getXferAddress().getHostString(),
|
||||||
new String[] { "-getDatanodeInfo", "128.0.0.1:1234" });
|
dn.getIpcPort());
|
||||||
|
final int ret = ToolRunner.run(dfsAdmin,
|
||||||
|
new String[]{"-getDatanodeInfo", addr});
|
||||||
|
assertEquals(0, ret);
|
||||||
|
|
||||||
/* collect outputs */
|
/* collect outputs */
|
||||||
|
final List<String> outs = Lists.newArrayList();
|
||||||
scanIntoList(out, outs);
|
scanIntoList(out, outs);
|
||||||
|
|
||||||
/* verify results */
|
/* verify results */
|
||||||
|
assertEquals(
|
||||||
|
"One line per DataNode like: Uptime: XXX, Software version: x.y.z,"
|
||||||
|
+ " Config version: core-x.y.z,hdfs-x",
|
||||||
|
1, outs.size());
|
||||||
|
assertThat(outs.get(0),
|
||||||
|
is(allOf(containsString("Uptime:"),
|
||||||
|
containsString("Software version"),
|
||||||
|
containsString("Config version"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that if datanode is not reachable, some DFSAdmin commands will fail
|
||||||
|
* elegantly with non-zero ret error code along with exception error message.
|
||||||
|
*/
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testDFSAdminUnreachableDatanode() throws Exception {
|
||||||
|
redirectStream();
|
||||||
|
final DFSAdmin dfsAdmin = new DFSAdmin(conf);
|
||||||
|
for (String command : new String[]{"-getDatanodeInfo",
|
||||||
|
"-evictWriters", "-getBalancerBandwidth"}) {
|
||||||
|
// Connecting to Xfer port instead of IPC port will get
|
||||||
|
// Datanode unreachable. java.io.EOFException
|
||||||
|
final String dnDataAddr = datanode.getXferAddress().getHostString() + ":"
|
||||||
|
+ datanode.getXferPort();
|
||||||
|
resetStream();
|
||||||
|
final List<String> outs = Lists.newArrayList();
|
||||||
|
final int ret = ToolRunner.run(dfsAdmin,
|
||||||
|
new String[]{command, dnDataAddr});
|
||||||
assertEquals(-1, ret);
|
assertEquals(-1, ret);
|
||||||
assertTrue("Unexpected getDatanodeInfo stdout", outs.isEmpty());
|
|
||||||
|
|
||||||
/**
|
scanIntoList(out, outs);
|
||||||
* test normal run
|
assertTrue("Unexpected " + command + " stdout: " + out, outs.isEmpty());
|
||||||
*/
|
assertTrue("Unexpected " + command + " stderr: " + err,
|
||||||
for (int i = 0; i < numDn; i++) {
|
err.toString().contains("Exception"));
|
||||||
resetStream();
|
|
||||||
final DataNode dn = miniCluster.getDataNodes().get(i);
|
|
||||||
|
|
||||||
/* invoke getDatanodeInfo */
|
|
||||||
final String addr = String.format("%s:%d",
|
|
||||||
dn.getXferAddress().getHostString(), dn.getIpcPort());
|
|
||||||
ret = ToolRunner.run(dfsAdmin,
|
|
||||||
new String[] { "-getDatanodeInfo", addr });
|
|
||||||
|
|
||||||
/* collect outputs */
|
|
||||||
outs = Lists.newArrayList();
|
|
||||||
scanIntoList(out, outs);
|
|
||||||
|
|
||||||
/* verify results */
|
|
||||||
assertEquals(0, ret);
|
|
||||||
assertEquals(
|
|
||||||
"One line per DataNode like: Uptime: XXX, Software version: x.y.z,"
|
|
||||||
+ " Config version: core-x.y.z,hdfs-x",
|
|
||||||
1, outs.size());
|
|
||||||
assertThat(outs.get(0),
|
|
||||||
is(allOf(containsString("Uptime:"),
|
|
||||||
containsString("Software version"),
|
|
||||||
containsString("Config version"))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue