Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/2416#discussion_r17923361
--- Diff:
core/src/main/scala/org/apache/spark/util/collection/ExternalSorter.scala ---
@@ -271,19 +246,17 @@ private[spark] class ExternalSorter[K, V, C](
spillToMergeableFile(collection)
}
- if (usingMap) {
- map = new SizeTrackingAppendOnlyMap[(Int, K), C]
- } else {
- buffer = new SizeTrackingPairBuffer[(Int, K), C]
- }
-
- // Release our memory back to the shuffle pool so that other threads
can grab it
- shuffleMemoryManager.release(myMemoryThreshold)
- myMemoryThreshold = 0
-
- _memoryBytesSpilled += memorySize
+ newCollection[A](collection)
}
+ private def newCollection[A](t: A): A =
+ t match {
+ case _: AppendOnlyMap[_, _] =>
+ new SizeTrackingAppendOnlyMap[(Int, K), C].asInstanceOf[A]
+ case _ =>
+ new SizeTrackingPairBuffer[(Int, K), C].asInstanceOf[A]
+ }
+
--- End diff --
We don't need to match here to find out what type to return. We already
know this through `usingMap`. Also, if you follow my suggestions elsewhere then
we can just the `map` and `buffer` variables directly instead of returning it
and trying to cast it back to some type `A`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]