@@ -53,15 +53,17 @@ private[spark] class HashShuffleReader[K, C](
53
53
val recordIterator = wrappedStreams.flatMap { wrappedStream =>
54
54
val kvIter = serializerInstance.deserializeStream(wrappedStream).asKeyValueIterator
55
55
CompletionIterator [(Any , Any ), Iterator [(Any , Any )]](kvIter, {
56
- // Close the stream once all the records have been read from it
56
+ // Close the stream once all the records have been read from it to free underlying
57
+ // ManagedBuffer as soon as possible. Note that in case of task failure, the task's
58
+ // TaskCompletionListener will make sure this is released.
57
59
wrappedStream.close()
58
60
})
59
61
}
60
62
61
63
// Update read metrics for each record materialized
62
- val iter = new InterruptibleIterator [Any ](context, recordIterator) {
64
+ val iter = new InterruptibleIterator [( Any , Any ) ](context, recordIterator) {
63
65
val readMetrics = context.taskMetrics.createShuffleReadMetricsForDependency()
64
- override def next (): Any = {
66
+ override def next (): ( Any , Any ) = {
65
67
readMetrics.incRecordsRead(1 )
66
68
delegate.next()
67
69
}
@@ -70,14 +72,14 @@ private[spark] class HashShuffleReader[K, C](
70
72
val aggregatedIter : Iterator [Product2 [K , C ]] = if (dep.aggregator.isDefined) {
71
73
if (dep.mapSideCombine) {
72
74
// We are reading values that are already combined
73
- val combinedKeyValuesIterator = iter.asInstanceOf [Iterator [(K ,C )]]
75
+ val combinedKeyValuesIterator = iter.asInstanceOf [Iterator [(K , C )]]
74
76
new InterruptibleIterator (context,
75
77
dep.aggregator.get.combineCombinersByKey(combinedKeyValuesIterator, context))
76
78
} else {
77
79
// We don't know the value type, but also don't care -- the dependency *should*
78
80
// have made sure its compatible w/ this aggregator, which will convert the value
79
81
// type to the combined type C
80
- val keyValuesIterator = iter.asInstanceOf [Iterator [(K ,Nothing )]]
82
+ val keyValuesIterator = iter.asInstanceOf [Iterator [(K , Nothing )]]
81
83
new InterruptibleIterator (context,
82
84
dep.aggregator.get.combineValuesByKey(keyValuesIterator, context))
83
85
}
0 commit comments