|
23 | 23 | import org.apache.hadoop.mapreduce.JobStatus; |
24 | 24 | import org.apache.hadoop.mapreduce.OutputCommitter; |
25 | 25 | import org.apache.hadoop.mapreduce.TaskAttemptContext; |
| 26 | +import org.slf4j.Logger; |
| 27 | +import org.slf4j.LoggerFactory; |
26 | 28 |
|
27 | 29 | import java.io.IOException; |
28 | 30 | import java.util.HashMap; |
|
35 | 37 | * Delegated instances are supplied along with a schema, which is used to configure the commit operation. |
36 | 38 | */ |
37 | 39 | public class DelegatingMultiSinkOutputCommitter extends OutputCommitter { |
| 40 | + private static final Logger LOG = LoggerFactory.getLogger(DelegatingMultiSinkOutputCommitter.class); |
38 | 41 | private final Map<String, OutputCommitter> committerMap; |
39 | 42 | private final Map<String, Schema> schemaMap; |
40 | 43 | private final String projectName; |
@@ -99,18 +102,28 @@ public boolean needsTaskCommit(TaskAttemptContext taskAttemptContext) throws IOE |
99 | 102 | @Override |
100 | 103 | public void commitTask(TaskAttemptContext taskAttemptContext) throws IOException { |
101 | 104 | for (String tableName : committerMap.keySet()) { |
102 | | - configureContext(taskAttemptContext, tableName); |
103 | | - |
104 | | - committerMap.get(tableName).commitTask(taskAttemptContext); |
| 105 | + try { |
| 106 | + configureContext(taskAttemptContext, tableName); |
| 107 | + committerMap.get(tableName).commitTask(taskAttemptContext); |
| 108 | + } catch (IOException e) { |
| 109 | + LOG.warn("BigQuery multi-sink table '{}' failed during task commit. Reason: {}", |
| 110 | + tableName, getFailureReason(e), e); |
| 111 | + throw e; |
| 112 | + } |
105 | 113 | } |
106 | 114 | } |
107 | 115 |
|
108 | 116 | @Override |
109 | 117 | public void commitJob(JobContext jobContext) throws IOException { |
110 | 118 | for (String tableName : committerMap.keySet()) { |
111 | | - configureContext(jobContext, tableName); |
112 | | - |
113 | | - committerMap.get(tableName).commitJob(jobContext); |
| 119 | + try { |
| 120 | + configureContext(jobContext, tableName); |
| 121 | + committerMap.get(tableName).commitJob(jobContext); |
| 122 | + } catch (IOException e) { |
| 123 | + LOG.warn("BigQuery multi-sink table '{}' failed during job commit. Reason: {}", |
| 124 | + tableName, getFailureReason(e), e); |
| 125 | + throw e; |
| 126 | + } |
114 | 127 | } |
115 | 128 | } |
116 | 129 |
|
@@ -168,4 +181,12 @@ public void configureContext(JobContext context, String tableName) throws IOExce |
168 | 181 | gcsPath, |
169 | 182 | fields); |
170 | 183 | } |
| 184 | + |
| 185 | + private String getFailureReason(IOException exception) { |
| 186 | + Throwable rootCause = exception; |
| 187 | + while (rootCause.getCause() != null) { |
| 188 | + rootCause = rootCause.getCause(); |
| 189 | + } |
| 190 | + return rootCause.getMessage() == null ? exception.getMessage() : rootCause.getMessage(); |
| 191 | + } |
171 | 192 | } |
0 commit comments