From d6eec1f2d59bdda06a51b50ed39f1af81a92c4c7 Mon Sep 17 00:00:00 2001 From: Arvind Prabhakar Date: Fri, 7 Oct 2011 19:12:01 +0000 Subject: [PATCH] SQOOP-357. Debug logs should include chained exception trace. (Bilung Lee via Arvind Prabhakar) git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1180162 13f79535-47bb-0310-9956-ffa450edef68 --- .../sqoop/mapreduce/AsyncSqlRecordWriter.java | 7 ++- .../sqoop/mapreduce/db/DBRecordReader.java | 3 ++ .../com/cloudera/sqoop/util/LoggingUtils.java | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/java/com/cloudera/sqoop/util/LoggingUtils.java diff --git a/src/java/com/cloudera/sqoop/mapreduce/AsyncSqlRecordWriter.java b/src/java/com/cloudera/sqoop/mapreduce/AsyncSqlRecordWriter.java index 279a0d31..d757e464 100755 --- a/src/java/com/cloudera/sqoop/mapreduce/AsyncSqlRecordWriter.java +++ b/src/java/com/cloudera/sqoop/mapreduce/AsyncSqlRecordWriter.java @@ -27,11 +27,13 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapreduce.RecordWriter; import org.apache.hadoop.mapreduce.TaskAttemptContext; import com.cloudera.sqoop.mapreduce.db.DBConfiguration; - +import com.cloudera.sqoop.util.LoggingUtils; import com.cloudera.sqoop.lib.SqoopRecord; /** @@ -47,6 +49,8 @@ public abstract class AsyncSqlRecordWriter extends RecordWriter { + private static final Log LOG = LogFactory.getLog(AsyncSqlRecordWriter.class); + private Connection connection; private Configuration conf; @@ -166,6 +170,7 @@ private void execUpdate(boolean commit, boolean stopThread) // Check for any previous SQLException. If one happened, rethrow it here. SQLException lastException = execThread.getLastError(); if (null != lastException) { + LoggingUtils.logAll(LOG, lastException); throw lastException; } } diff --git a/src/java/com/cloudera/sqoop/mapreduce/db/DBRecordReader.java b/src/java/com/cloudera/sqoop/mapreduce/db/DBRecordReader.java index bef41487..b572341a 100644 --- a/src/java/com/cloudera/sqoop/mapreduce/db/DBRecordReader.java +++ b/src/java/com/cloudera/sqoop/mapreduce/db/DBRecordReader.java @@ -37,6 +37,8 @@ import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.conf.Configuration; +import com.cloudera.sqoop.util.LoggingUtils; + /** * A RecordReader that reads records from a SQL table. * Emits LongWritables containing the record number as @@ -245,6 +247,7 @@ public boolean nextKeyValue() throws IOException { pos++; } catch (SQLException e) { + LoggingUtils.logAll(LOG, e); throw new IOException("SQLException in nextKeyValue", e); } return true; diff --git a/src/java/com/cloudera/sqoop/util/LoggingUtils.java b/src/java/com/cloudera/sqoop/util/LoggingUtils.java new file mode 100644 index 00000000..1ea17f52 --- /dev/null +++ b/src/java/com/cloudera/sqoop/util/LoggingUtils.java @@ -0,0 +1,53 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cloudera.sqoop.util; + +import java.sql.SQLException; + +import org.apache.commons.logging.Log; + +/** + * A helper class for logging. + */ +public final class LoggingUtils { + + /** + * Private constructor to prevent instantiation. + */ + private LoggingUtils() { + } + + /** + * Log every exception in the chain if + * the exception is a chain of exceptions. + */ + public static void logAll(Log log, SQLException e) { + log.error("Top level exception: ", e); + e = e.getNextException(); + int indx = 1; + while (e != null) { + log.error("Chained exception " + indx + ": ", e); + e = e.getNextException(); + indx++; + } + } +} +