Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions core/src/main/scala/org/apache/spark/rdd/HadoopRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,21 @@ class HadoopRDD[K, V](
}

override def close() {
try {
reader.close()
if (reader != null) {
// Close the reader and release it. Note: it's very important that we don't close the
// reader more than once, since that exposes us to MAPREDUCE-5918 when running against
// Hadoop 1.x and older Hadoop 2.x releases. That bug can lead to non-deterministic
// corruption issues when reading compressed input.
try {
reader.close()
} catch {
case e: Exception =>
if (!Utils.inShutdown()) {
logWarning("Exception in RecordReader.close()", e)
}
} finally {
reader = null
}
if (bytesReadCallback.isDefined) {
inputMetrics.updateBytesRead()
} else if (split.inputSplit.value.isInstanceOf[FileSplit] ||
Expand All @@ -269,12 +282,6 @@ class HadoopRDD[K, V](
logWarning("Unable to get input size to set InputMetrics for task", e)
}
}
} catch {
case e: Exception => {
if (!Utils.inShutdown()) {
logWarning("Exception in RecordReader.close()", e)
}
}
}
}
}
Expand Down
25 changes: 16 additions & 9 deletions core/src/main/scala/org/apache/spark/rdd/NewHadoopRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class NewHadoopRDD[K, V](
configurable.setConf(conf)
case _ =>
}
val reader = format.createRecordReader(
var reader = format.createRecordReader(
split.serializableHadoopSplit.value, hadoopAttemptContext)
reader.initialize(split.serializableHadoopSplit.value, hadoopAttemptContext)

Expand Down Expand Up @@ -158,8 +158,21 @@ class NewHadoopRDD[K, V](
}

private def close() {
try {
reader.close()
if (reader != null) {
// Close the reader and release it. Note: it's very important that we don't close the
// reader more than once, since that exposes us to MAPREDUCE-5918 when running against
// Hadoop 1.x and older Hadoop 2.x releases. That bug can lead to non-deterministic
// corruption issues when reading compressed input.
try {
reader.close()
} catch {
case e: Exception =>
if (!Utils.inShutdown()) {
logWarning("Exception in RecordReader.close()", e)
}
} finally {
reader = null
}
if (bytesReadCallback.isDefined) {
inputMetrics.updateBytesRead()
} else if (split.serializableHadoopSplit.value.isInstanceOf[FileSplit] ||
Expand All @@ -173,12 +186,6 @@ class NewHadoopRDD[K, V](
logWarning("Unable to get input size to set InputMetrics for task", e)
}
}
} catch {
case e: Exception => {
if (!Utils.inShutdown()) {
logWarning("Exception in RecordReader.close()", e)
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/org/apache/spark/util/NextIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ private[spark] abstract class NextIterator[U] extends Iterator[U] {
*/
def closeIfNeeded() {
if (!closed) {
close()
// Note: it's important that we set closed = true before calling close(), since setting it
// afterwards would permit us to call close() multiple times if close() threw an exception.
closed = true
close()
}
}

Expand Down