mirror of
https://github.com/apache/sqoop.git
synced 2025-05-04 05:20:22 +08:00
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
This commit is contained in:
parent
fd3634dc3c
commit
d6eec1f2d5
@ -27,11 +27,13 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.conf.Configuration;
|
||||||
import org.apache.hadoop.mapreduce.RecordWriter;
|
import org.apache.hadoop.mapreduce.RecordWriter;
|
||||||
import org.apache.hadoop.mapreduce.TaskAttemptContext;
|
import org.apache.hadoop.mapreduce.TaskAttemptContext;
|
||||||
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
||||||
|
import com.cloudera.sqoop.util.LoggingUtils;
|
||||||
import com.cloudera.sqoop.lib.SqoopRecord;
|
import com.cloudera.sqoop.lib.SqoopRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,6 +49,8 @@
|
|||||||
public abstract class AsyncSqlRecordWriter<K extends SqoopRecord, V>
|
public abstract class AsyncSqlRecordWriter<K extends SqoopRecord, V>
|
||||||
extends RecordWriter<K, V> {
|
extends RecordWriter<K, V> {
|
||||||
|
|
||||||
|
private static final Log LOG = LogFactory.getLog(AsyncSqlRecordWriter.class);
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
private Configuration conf;
|
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.
|
// Check for any previous SQLException. If one happened, rethrow it here.
|
||||||
SQLException lastException = execThread.getLastError();
|
SQLException lastException = execThread.getLastError();
|
||||||
if (null != lastException) {
|
if (null != lastException) {
|
||||||
|
LoggingUtils.logAll(LOG, lastException);
|
||||||
throw lastException;
|
throw lastException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
import org.apache.hadoop.util.ReflectionUtils;
|
import org.apache.hadoop.util.ReflectionUtils;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
|
||||||
|
import com.cloudera.sqoop.util.LoggingUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A RecordReader that reads records from a SQL table.
|
* A RecordReader that reads records from a SQL table.
|
||||||
* Emits LongWritables containing the record number as
|
* Emits LongWritables containing the record number as
|
||||||
@ -245,6 +247,7 @@ public boolean nextKeyValue() throws IOException {
|
|||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
LoggingUtils.logAll(LOG, e);
|
||||||
throw new IOException("SQLException in nextKeyValue", e);
|
throw new IOException("SQLException in nextKeyValue", e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
53
src/java/com/cloudera/sqoop/util/LoggingUtils.java
Normal file
53
src/java/com/cloudera/sqoop/util/LoggingUtils.java
Normal file
@ -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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user