From 9a151d2e73457de02e914e8f1d4da0f8cc9d2432 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Tue, 25 Jun 2013 17:46:51 +0000 Subject: [PATCH] HBASE-8800 Return non-zero exit codes when a region server aborts git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1496559 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/master/HMasterCommandLine.java | 22 ++++++------ .../HRegionServerCommandLine.java | 34 ++++++++++++------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java index 194065b0f43..1cff2aea734 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java @@ -84,7 +84,7 @@ public class HMasterCommandLine extends ServerCommandLine { } catch (ParseException e) { LOG.error("Could not parse: ", e); usage(null); - return -1; + return 1; } @@ -125,7 +125,7 @@ public class HMasterCommandLine extends ServerCommandLine { List remainingArgs = cmd.getArgList(); if (remainingArgs.size() != 1) { usage(null); - return -1; + return 1; } String command = remainingArgs.get(0); @@ -135,10 +135,10 @@ public class HMasterCommandLine extends ServerCommandLine { } else if ("stop".equals(command)) { return stopMaster(); } else if ("clear".equals(command)) { - return (ZNodeClearer.clear(getConf()) ? 0 : -1); + return (ZNodeClearer.clear(getConf()) ? 0 : 1); } else { usage("Invalid command: " + command); - return -1; + return 1; } } @@ -183,7 +183,7 @@ public class HMasterCommandLine extends ServerCommandLine { HMaster master = HMaster.constructMaster(masterClass, conf); if (master.isStopped()) { LOG.info("Won't bring the Master up as a shutdown is requested"); - return -1; + return 1; } master.start(); master.join(); @@ -191,8 +191,8 @@ public class HMasterCommandLine extends ServerCommandLine { throw new RuntimeException("HMaster Aborted"); } } catch (Throwable t) { - LOG.error("Failed to start master", t); - return -1; + LOG.error("Master exiting", t); + return 1; } return 0; } @@ -206,19 +206,19 @@ public class HMasterCommandLine extends ServerCommandLine { adm = new HBaseAdmin(getConf()); } catch (MasterNotRunningException e) { LOG.error("Master not running"); - return -1; + return 1; } catch (ZooKeeperConnectionException e) { LOG.error("ZooKeeper not available"); - return -1; + return 1; } catch (IOException e) { LOG.error("Got IOException: " +e.getMessage(), e); - return -1; + return 1; } try { adm.shutdown(); } catch (Throwable t) { LOG.error("Failed to stop master", t); - return -1; + return 1; } return 0; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java index 7290b647203..1ad7773d7b2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServerCommandLine.java @@ -50,16 +50,26 @@ public class HRegionServerCommandLine extends ServerCommandLine { private int start() throws Exception { Configuration conf = getConf(); + try { + // If 'local', don't start a region server here. Defer to + // LocalHBaseCluster. It manages 'local' clusters. + if (LocalHBaseCluster.isLocal(conf)) { + LOG.warn("Not starting a distinct region server because " + + HConstants.CLUSTER_DISTRIBUTED + " is false"); + } else { + logJVMInfo(); + HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf); + HRegionServer.startRegionServer(hrs); + Thread rsThread = HRegionServer.startRegionServer(hrs); - // If 'local', don't start a region server here. Defer to - // LocalHBaseCluster. It manages 'local' clusters. - if (LocalHBaseCluster.isLocal(conf)) { - LOG.warn("Not starting a distinct region server because " - + HConstants.CLUSTER_DISTRIBUTED + " is false"); - } else { - logJVMInfo(); - HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf); - HRegionServer.startRegionServer(hrs); + rsThread.join(); + if (hrs.isAborted()) { + throw new RuntimeException("HRegionServer Aborted"); + } + } + } catch (Throwable t) { + LOG.error("Region server exiting", t); + return 1; } return 0; } @@ -67,7 +77,7 @@ public class HRegionServerCommandLine extends ServerCommandLine { public int run(String args[]) throws Exception { if (args.length != 1) { usage(null); - return -1; + return 1; } String cmd = args[0]; @@ -79,10 +89,10 @@ public class HRegionServerCommandLine extends ServerCommandLine { "To shutdown the regionserver run " + "bin/hbase-daemon.sh stop regionserver or send a kill signal to" + "the regionserver pid"); - return -1; + return 1; } else { usage("Unknown command: " + args[0]); - return -1; + return 1; } } }