Skip to content

Commit f28399e

Browse files
nongliyhuai
authored andcommitted
[SPARK-11328][SQL] Improve error message when hitting this issue
The issue is that the output commiter is not idempotent and retry attempts will fail because the output file already exists. It is not safe to clean up the file as this output committer is by design not retryable. Currently, the job fails with a confusing file exists error. This patch is a stop gap to tell the user to look at the top of the error log for the proper message. This is difficult to test locally as Spark is hardcoded not to retry. Manually verified by upping the retry attempts. Author: Nong Li <[email protected]> Author: Nong Li <[email protected]> Closes #10080 from nongli/spark-11328. (cherry picked from commit 47a0abc) Signed-off-by: Yin Huai <[email protected]>
1 parent 80dac0b commit f28399e

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/WriterContainer.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ private[sql] abstract class BaseWriterContainer(
122122
}
123123
}
124124

125+
protected def newOutputWriter(path: String): OutputWriter = {
126+
try {
127+
outputWriterFactory.newInstance(path, dataSchema, taskAttemptContext)
128+
} catch {
129+
case e: org.apache.hadoop.fs.FileAlreadyExistsException =>
130+
if (outputCommitter.isInstanceOf[parquet.DirectParquetOutputCommitter]) {
131+
// Spark-11382: DirectParquetOutputCommitter is not idempotent, meaning on retry
132+
// attempts, the task will fail because the output file is created from a prior attempt.
133+
// This often means the most visible error to the user is misleading. Augment the error
134+
// to tell the user to look for the actual error.
135+
throw new SparkException("The output file already exists but this could be due to a " +
136+
"failure from an earlier attempt. Look through the earlier logs or stage page for " +
137+
"the first error.\n File exists error: " + e)
138+
}
139+
throw e
140+
}
141+
}
142+
125143
private def newOutputCommitter(context: TaskAttemptContext): OutputCommitter = {
126144
val defaultOutputCommitter = outputFormatClass.newInstance().getOutputCommitter(context)
127145

@@ -230,7 +248,7 @@ private[sql] class DefaultWriterContainer(
230248
executorSideSetup(taskContext)
231249
val configuration = SparkHadoopUtil.get.getConfigurationFromJobContext(taskAttemptContext)
232250
configuration.set("spark.sql.sources.output.path", outputPath)
233-
val writer = outputWriterFactory.newInstance(getWorkPath, dataSchema, taskAttemptContext)
251+
val writer = newOutputWriter(getWorkPath)
234252
writer.initConverter(dataSchema)
235253

236254
var writerClosed = false
@@ -400,7 +418,7 @@ private[sql] class DynamicPartitionWriterContainer(
400418
val configuration = SparkHadoopUtil.get.getConfigurationFromJobContext(taskAttemptContext)
401419
configuration.set(
402420
"spark.sql.sources.output.path", new Path(outputPath, partitionPath).toString)
403-
val newWriter = outputWriterFactory.newInstance(path.toString, dataSchema, taskAttemptContext)
421+
val newWriter = super.newOutputWriter(path.toString)
404422
newWriter.initConverter(dataSchema)
405423
newWriter
406424
}

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/DirectParquetOutputCommitter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import org.apache.parquet.hadoop.{ParquetFileReader, ParquetFileWriter, ParquetO
4141
* no safe way undo a failed appending job (that's why both `abortTask()` and `abortJob()` are
4242
* left * empty).
4343
*/
44-
private[parquet] class DirectParquetOutputCommitter(outputPath: Path, context: TaskAttemptContext)
44+
private[datasources] class DirectParquetOutputCommitter(
45+
outputPath: Path, context: TaskAttemptContext)
4546
extends ParquetOutputCommitter(outputPath, context) {
4647
val LOG = Log.getLog(classOf[ParquetOutputCommitter])
4748

0 commit comments

Comments
 (0)