diff --git beeline/src/java/org/apache/hive/beeline/BeeLine.java beeline/src/java/org/apache/hive/beeline/BeeLine.java index 0ee1e4f..a657c54 100644 --- beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -623,8 +623,9 @@ public int begin(String[] args, InputStream inputStream) throws IOException { try { // load the options first, so we can override on the command line getOpts().load(); - } catch (Exception e) { - // nothing + } catch (IOException e) { + // Cannot load opts.. + handleException(e); } if (!(initArgs(args))) { @@ -1468,7 +1469,12 @@ private Driver findRegisteredDriver(String url) { // now instantiate and initialize it driverClasses.add(c.newInstance()); + } catch (ClassNotFoundException ignore) { + // if no such class it is OK } catch (Throwable t) { + // other exceptions, such as InvocationTargetException, are + // unexpected and should be logged. + error(t); } } info("scan complete in " @@ -1530,12 +1536,20 @@ private Driver findRegisteredDriver(String url) { try { // load and initialize Class.forName(name); + } catch (ClassNotFoundException ignore) { + // if no such class it is OK } catch (Exception e) { + // unexpected + error(e); } driverClasses.add(c.newInstance()); } } + } catch (ClassNotFoundException ignore) { + // if no such class it is OK } catch (Throwable t) { + // unexpected + error(t); } } } @@ -1608,7 +1622,8 @@ void runBatch(List statements) { } finally { try { stmnt.close(); - } catch (Exception e) { + } catch (SQLException e) { + info("Unexpected exception during stmnt.close(): " + e); } } } catch (Exception e) { diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index 8694864..389a767 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -238,7 +238,9 @@ public boolean dropall(String line) { } finally { try { rs.close(); - } catch (Exception e) { + } catch (SQLException e) { + // exception when closing the ResultSet + beeLine.error(e); } } // run as a batch @@ -355,7 +357,8 @@ public boolean set(String line) { if (success && beeLine.getOpts().getAutosave()) { try { beeLine.getOpts().save(); - } catch (Exception saveException) { + } catch (IOException saveException) { + beeLine.error(saveException); } } return success; diff --git beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java index 00b49af..a8b16d6 100644 --- beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java +++ beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java @@ -123,7 +123,8 @@ boolean connect() throws SQLException { boolean foundDriver = false; try { foundDriver = DriverManager.getDriver(getUrl()) != null; - } catch (Exception e) { + } catch (SQLException e) { + beeLine.error(e); } try { diff --git hcatalog/core/src/main/java/org/apache/hcatalog/cli/HCatCli.java hcatalog/core/src/main/java/org/apache/hcatalog/cli/HCatCli.java index 14bf1c4..74e6a5a 100644 --- hcatalog/core/src/main/java/org/apache/hcatalog/cli/HCatCli.java +++ hcatalog/core/src/main/java/org/apache/hcatalog/cli/HCatCli.java @@ -60,12 +60,6 @@ @SuppressWarnings("static-access") public static void main(String[] args) { - try { - LogUtils.initHiveLog4j(); - } catch (LogInitializationException e) { - - } - CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class)); ss.in = System.in; try { @@ -75,6 +69,12 @@ public static void main(String[] args) { System.exit(1); } + try { + LogUtils.initHiveLog4j(); + } catch (LogInitializationException e) { + ss.err.println("Failed to initialize Log4j, exception: " + e); + } + HiveConf conf = ss.getConf(); HiveConf.setVar(conf, ConfVars.SEMANTIC_ANALYZER_HOOK, HCatSemanticAnalyzer.class.getName()); diff --git hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/HCatCli.java hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/HCatCli.java index ba08545..32210af 100644 --- hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/HCatCli.java +++ hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/HCatCli.java @@ -57,12 +57,6 @@ @SuppressWarnings("static-access") public static void main(String[] args) { - try { - LogUtils.initHiveLog4j(); - } catch (LogInitializationException e) { - - } - CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class)); ss.in = System.in; try { @@ -72,6 +66,12 @@ public static void main(String[] args) { System.exit(1); } + try { + LogUtils.initHiveLog4j(); + } catch (LogInitializationException e) { + ss.err.println("Failed to initialize Log4j, exception: " + e); + } + HiveConf conf = ss.getConf(); HiveConf.setVar(conf, ConfVars.SEMANTIC_ANALYZER_HOOK, HCatSemanticAnalyzer.class.getName()); diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/JobState.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/JobState.java index afca4ac..fa38d93 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/JobState.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/JobState.java @@ -115,8 +115,7 @@ public String getId() { /** * The percent complete of a job */ - public String getPercentComplete() - throws IOException { + public String getPercentComplete() { return getField("percentComplete"); } @@ -133,11 +132,8 @@ public void setPercentComplete(String percent) */ public void addChild(String jobid) throws IOException { String jobids = ""; - try { - jobids = getField("children"); - } catch (Exception e) { - // There are none or they're not readable. - } + jobids = getField("children"); + if (jobids==null) { jobids = ""; } @@ -201,8 +197,7 @@ public void setCreated(long created) /** * The user who started this job. */ - public String getUser() - throws IOException { + public String getUser() { return getField("user"); } @@ -228,8 +223,7 @@ public void setUserArgs(Map userArgs) /** * The url callback */ - public String getCallback() - throws IOException { + public String getCallback() { return getField("callback"); } @@ -241,8 +235,7 @@ public void setCallback(String callback) /** * The status of a job once it is completed. */ - public String getCompleteStatus() - throws IOException { + public String getCompleteStatus() { return getField("completed"); } @@ -298,8 +291,7 @@ public void setField(String name, String val) } } - public String getField(String name) - throws IOException { + public String getField(String name) { return storage.getField(type, id, name); } diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperCleanup.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperCleanup.java index 4f5e2d9..9c5a630 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperCleanup.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperCleanup.java @@ -116,7 +116,7 @@ public void run() { try { zk.close(); } catch (InterruptedException e) { - // We're trying to exit anyway, just ignore. + LOG.warn("Interrupted when closing down, ", e); } } } diff --git hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperStorage.java hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperStorage.java index ecde598..ca6c6d3 100644 --- hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperStorage.java +++ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperStorage.java @@ -127,6 +127,7 @@ public void create(Type type, String id) Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); wasCreated = true; } catch (KeeperException.NodeExistsException e) { + LOG.warn("Zookeeper node already exists: " + id); } } if (wasCreated) { diff --git hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java index 0ad8f89..ca01295 100644 --- hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java +++ hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java @@ -122,7 +122,8 @@ public HWISessionItem(HWIAuth auth, String sessionName) { if (status != WebSessionItemStatus.READY) { try { runnable.wait(); - } catch (Exception ex) { + } catch (InterruptedException ex) { + l4j.warn("Interrupted: ", ex); } } } diff --git jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java index 59ce692..973e47e 100644 --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hive.jdbc; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.service.HiveClient; @@ -54,6 +56,8 @@ * */ public class HiveConnection implements java.sql.Connection { + public static final Log LOG = LogFactory.getLog(HiveConnection.class); + private TTransport transport; private HiveInterface client; private boolean isClosed = true; @@ -106,7 +110,8 @@ public HiveConnection(String uri, Properties info) throws SQLException { String host = hostport[0]; try { port = Integer.parseInt(hostport[1]); - } catch (Exception e) { + } catch (NumberFormatException e) { + LOG.warn("Illegal format of hostport: " + hostport[1]); } transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 9b160e3..14da963 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -389,6 +389,7 @@ public static void setWorkflowAdjacencies(Configuration conf, QueryPlan plan) { children.toArray(new String[children.size()])); } } catch (IOException e) { + LOG.warn("Caught exception: ", e); } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java index 179ad29..5be18ad 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/mr/ExecDriver.java @@ -455,6 +455,8 @@ public int execute(DriverContext driverContext) { jobID = rj.getID().toString(); } } catch (Exception e) { + String mesg = "Caught exception during clean-up after job submission"; + console.printError(mesg, "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e)); } } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java index 92ab0cc..bba259b 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java @@ -497,6 +497,7 @@ public int progressLocal(Process runningJob, String taskId) { try { exitVal = runningJob.waitFor(); //TODO: poll periodically } catch (InterruptedException e) { + console.printInfo("Interrupted when waiting for runningJob." + e); } if (exitVal != 0) { diff --git ql/src/java/org/apache/hadoop/hive/ql/history/HiveHistoryUtil.java ql/src/java/org/apache/hadoop/hive/ql/history/HiveHistoryUtil.java index c7cf2a3..cf169eb 100644 --- ql/src/java/org/apache/hadoop/hive/ql/history/HiveHistoryUtil.java +++ ql/src/java/org/apache/hadoop/hive/ql/history/HiveHistoryUtil.java @@ -60,6 +60,8 @@ public static void parseHiveHistory(String path, Listener l) throws IOException try { reader.close(); } catch (IOException ex) { + // Exception during close... Something wrong.. + throw ex; } } } diff --git ql/src/java/org/apache/hadoop/hive/ql/processors/CompileProcessor.java ql/src/java/org/apache/hadoop/hive/ql/processors/CompileProcessor.java index 8b8475b..07f88d6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/processors/CompileProcessor.java +++ ql/src/java/org/apache/hadoop/hive/ql/processors/CompileProcessor.java @@ -246,6 +246,7 @@ CommandProcessorResponse compile(SessionState ss) throws CompileProcessorExcepti try { out.close(); } catch (IOException WhatCanYouDo) { + LOG.warn("Caught exception when closing outputstream", WhatCanYouDo); } } }