From c24bc4a949a0635b127f211d552e843b8840f120 Mon Sep 17 00:00:00 2001 From: Elliott Neil Clark Date: Sun, 27 Oct 2013 13:23:51 -0700 Subject: [PATCH] HBASE-9848 Make regionserver Canary exit with different exit codes --- .../java/org/apache/hadoop/hbase/tool/Canary.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java index ed98a75..d1fbd75 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/Canary.java @@ -109,6 +109,9 @@ public final class Canary implements Tool { } } + private static final int USAGE_EXIT_CODE = 1; + private static final int INIT_ERROR_EXIT_CODE = 2; + private static final int ERROR_EXIT_CODE = 3; private static final long DEFAULT_INTERVAL = 6000; @@ -230,6 +233,9 @@ public final class Canary implements Tool { monitor = this.newMonitor(index, args); monitorThread = new Thread(monitor); startTime = System.currentTimeMillis(); + if (this.failOnError && monitor.hasError()) { + System.exit(INIT_ERROR_EXIT_CODE); + } monitorThread.start(); while (!monitor.isDone()) { // wait for 1 sec @@ -237,7 +243,7 @@ public final class Canary implements Tool { // exit if any error occurs if (this.failOnError && monitor.hasError()) { monitorThread.interrupt(); - System.exit(1); + System.exit(ERROR_EXIT_CODE); } currentTimeLength = System.currentTimeMillis() - startTime; if (currentTimeLength > this.timeout) { @@ -252,13 +258,13 @@ public final class Canary implements Tool { if (this.failOnError && monitor.hasError()) { monitorThread.interrupt(); - System.exit(1); + System.exit(ERROR_EXIT_CODE); } Thread.sleep(interval); } while (interval > 0); - return(monitor.hasError()? 1: 0); + return(monitor.hasError()? ERROR_EXIT_CODE: 0); } private void printUsageAndExit() { @@ -276,7 +282,7 @@ public final class Canary implements Tool { System.err.println(" -f stop whole program if first error occurs," + " default is true"); System.err.println(" -t timeout for a check, default is 600000 (milisecs)"); - System.exit(1); + System.exit(USAGE_EXIT_CODE); } /** @@ -350,8 +356,7 @@ public final class Canary implements Tool { LOG.error("Initial HBaseAdmin failed...", e); this.error = true; } - } - if (admin.isAborted()) { + } else if (admin.isAborted()) { LOG.error("HBaseAdmin aborted"); this.error = true; } @@ -395,11 +400,11 @@ public final class Canary implements Tool { HTableDescriptor[] tds = null; Set tmpTables = new TreeSet(); try { - for(int a = 0; a < monitorTargets.length; a++) { - pattern = Pattern.compile(monitorTargets[a]); + for (String monitorTarget : monitorTargets) { + pattern = Pattern.compile(monitorTarget); tds = this.admin.listTables(pattern); - if(tds != null) { - for(HTableDescriptor td : tds) { + if (tds != null) { + for (HTableDescriptor td : tds) { tmpTables.add(td.getNameAsString()); } } @@ -410,13 +415,13 @@ public final class Canary implements Tool { } if(tmpTables.size() > 0) { - returnTables = tmpTables.toArray(new String[]{}); + returnTables = tmpTables.toArray(new String[tmpTables.size()]); } else { String msg = "No any HTable found, tablePattern:" + Arrays.toString(monitorTargets); LOG.error(msg); this.error = true; - new TableNotFoundException(msg); + throw new TableNotFoundException(msg); } } else { returnTables = monitorTargets; @@ -438,8 +443,6 @@ public final class Canary implements Tool { /** * Canary entry point for specified table. - * @param admin - * @param tableName * @throws Exception */ public static void sniff(final HBaseAdmin admin, TableName tableName) throws Exception { @@ -448,9 +451,6 @@ public final class Canary implements Tool { /** * Canary entry point for specified table. - * @param admin - * @param sink - * @param tableName * @throws Exception */ private static void sniff(final HBaseAdmin admin, final Sink sink, String tableName) -- 1.8.3.4 (Apple Git-47)