Github user JerryLead commented on the pull request:
https://github.com/apache/spark/pull/3545#issuecomment-65356196
I write a simple example as follows to show how the abnormal `$outer` is
generated. I think the reason is that zipPartitions() in foo() uses the
VertexRDD.bar(). As a result, VertexRDD becomes the `$outer` and its member
variable `PartitionsRDD` will be serialized. @rxin @tdas @ankurdave @jason-dai
The `f=>$outer=>VertexRDD=>PartitionsRDD=>v` will be serialized while the
task is being serialized (shown in the following figures). P.S., Does cleanF in
compute() have problems when this RDD is recomputed?
import org.apache.spark.SparkContext
import org.apache.spark.rdd._
class PartitionsRDD extends Serializable {
val v = "partitionsRDD"
}
class VertexRDD extends Serializable {
val partitionsRDD = new PartitionsRDD
def foo(pairs1: RDD[(Int, Char)], pairs2: RDD[(Int, Char)]) = {
val zipRDD = pairs1.zipPartitions(pairs2) {
(thisIter, otherIter) =>
val p1 = thisIter.next()
val p2 = otherIter.next()
Iterator((p1._1 + p2._1 + bar(), p1._2 + ":" + p2._2))
}
zipRDD
}
def bar() = 5
}
object AbnormalFClosure {
def main(args: Array[String]) {
val sc = new SparkContext("local", "ZippedPartition Test")
val data1 = Array[(Int, Char)]((1, 'a'), (2, 'b'),
(3, 'c'), (4, 'd'),
(5, 'e'), (3, 'f'),
(2, 'g'), (1, 'h'))
val pairs1 = sc.parallelize(data1, 2)
val data2 = Array[(Int, Char)]((1, 'A'), (2, 'B'),
(3, 'C'), (4, 'D'))
val pairs2 = sc.parallelize(data2, 2)
val zipRDD = new VertexRDD().foo(pairs1, pairs2)
zipRDD.count()
}
}
The serialization chain of `f=>$outer(i.e., VertexRDD)=>PartitionsRDD=>v`:

PartitionsRDD is being serialized:

---
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]