Uh oh!
There was an error while loading. Please reload this page.
[SPARK-30772][ML][SQL] avoid tuple assignment because it will circumvent the transient tag - #27523
[SPARK-30772][ML][SQL] avoid tuple assignment because it will circumvent the transient tag#27523zhengruifeng wants to merge 2 commits into
Conversation
zhengruifeng
commented
Feb 10, 2020
I use following code to check this issue: importjava.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}
defserialise(value: Any):Array[Byte] = {
valstream:ByteArrayOutputStream=newByteArrayOutputStream()
valoos=newObjectOutputStream(stream)
oos.writeObject(value)
oos.close()
stream.toByteArray
}
defdeserialise(bytes: Array[Byte]):Any= {
valois=newObjectInputStream(newByteArrayInputStream(bytes))
valvalue= ois.readObject
ois.close()
value
}
classAextendsSerializable { @transient lazyvala= {println("get a"); System.currentTimeMillis} }
vala=newA
a.a
vala2= deserialise(serialise(a)).asInstanceOf[A]
a2.a
a.a == a2.a
classBextendsSerializable { @transient lazyval (a,b) = {println("get a & b"); valt=System.currentTimeMillis; (t, -t)} }
valb=newB
b.a
valb2= deserialise(serialise(b)).asInstanceOf[B]
b2.a
b.a == b2.a
b.b == b2.b
classCextendsSerializable { @transient lazyvalt= {println("get a & b"); valt=System.currentTimeMillis; (t, -t)}; @transient lazyvala= t._1; @transient lazyvalb= t._2 }
valc=newC
c.a
valc2= deserialise(serialise(c)).asInstanceOf[C]
c2.a
c.a == c2.a
c.b == c2.bResult: scala>classAextendsSerializable { @transient lazyvala= {println("get a"); System.currentTimeMillis} }
defined classA
scala>vala=newA
a:A=A@68ef01a5
scala> a.a
get a
res0:Long=1581333143300
scala>vala2= deserialise(serialise(a)).asInstanceOf[A]
a2:A=A@f017dd0
scala> a2.a
get a
res1:Long=1581333143523
scala> a.a == a2.a
res2:Boolean=false
scala> scala>classBextendsSerializable { @transient lazyval (a,b) = {println("get a & b"); valt=System.currentTimeMillis; (t, -t)} }
defined classB
scala>valb=newB
b:B=B@1d008e61
scala> b.a
get a & b
res3:Long=1581333144022
scala>valb2= deserialise(serialise(b)).asInstanceOf[B]
b2:B=B@6ab826bb
scala> b2.a
res4:Long=1581333144022
scala> b.a == b2.a
res5:Boolean=true
scala> b.b == b2.b
res6:Boolean=true
scala> scala>classCextendsSerializable { @transient lazyvalt= {println("get a & b"); valt=System.currentTimeMillis; (t, -t)}; @transient lazyvala= t._1; @transient lazyvalb= t._2 }
defined classC
scala>valc=newC
c:C=C@7ec01440
scala> c.a
get a & b
res7:Long=1581333144575
scala>valc2= deserialise(serialise(c)).asInstanceOf[C]
c2:C=C@42a698bd
scala> c2.a
get a & b
res8:Long=1581333144713
scala> c.a == c2.a
res9:Boolean=false
scala> c.b == c2.b
res10:Boolean=falseWe can see that |
zhengruifeng
commented
Feb 10, 2020
friendly ping @srowen , I can not find in the scala community any description or disscussin on this issue. |
SparkQA
commented
Feb 10, 2020
Test build #118156 has finished for PR 27523 at commit
|
srowen
left a comment
There was a problem hiding this comment.
Weird. @sethah do you recall this? you added the comment in 1db1c65#diff-668c79317c51f40df870d3404d8a731fR921 several years ago.
So, if this isn't actually avoiding serialization, but still works, another option is to decide that's fine and just let them serialize. I don't know which of them are actually really big, but, that would keep existing behavior right?
There was a problem hiding this comment.
Hm, this pattern is a little ugly / adds extra overhead, but might be necessary vs just referencing "elementIndexVar._1" later in the code or something similar.
sethah
commented
Feb 11, 2020
What's the question 😛 ? See my comments here: #14109 Also the databricks style guide mentions it: https://github.com/databricks/scala-style-guide#destructuring-binds |
srowen
commented
Feb 11, 2020
Oh ha thanks @sethah ! never seen that. Yeah I was just asking if you knew anything more about why or what is happening here. That's pretty good. |
sethah
commented
Feb 11, 2020
Heh np, I remember it being really subtle! But that's about all I can give you. |
zhengruifeng
commented
Feb 11, 2020
acturally, I do know how big those variables in SQL are. If they are supposed to be transient, I guess that should keep existing behavior. |
zhengruifeng
commented
Feb 11, 2020
retest this please |
SparkQA
commented
Feb 11, 2020
Test build #118202 has finished for PR 27523 at commit
|
srowen
commented
Feb 13, 2020
I'm OK with it, I guess I was just saying that the current behavior is not as intended, but still 'works' it seems. Maybe in some cases they aren't that big. But if you're pretty confident they are then this is a 'win'. |
srowen
commented
Feb 13, 2020
Jenkins retest this please |
SparkQA
commented
Feb 13, 2020
Test build #118371 has finished for PR 27523 at commit
|
zhengruifeng
commented
Feb 14, 2020
@srowen acturally, I do not know how big the objects in SQL are. So I agree to let them alone, and only change the ML side. |
477f99e to
968ffb3CompareSparkQA
commented
Feb 14, 2020
Test build #118407 has finished for PR 27523 at commit
|
srowen
commented
Feb 14, 2020
Oh, I don't think it's 'wrong' to fix. Or if we know the intended behavior isn't working, just undo the intention (i.e. remove transient lazy). Well, either way. |
srowen
commented
Feb 16, 2020
Merged to master |
…ent the transient tag ### What changes were proposed in this pull request? it is said in [LeastSquaresAggregator](https://github.com/apache/spark/blob/12e1bbaddbb2ef304b5880a62df6683fcc94ea54/mllib/src/main/scala/org/apache/spark/ml/optim/aggregator/LeastSquaresAggregator.scala#L188) that : > // do not use tuple assignment above because it will circumvent the transient tag I then check this issue with Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_241) ### Why are the changes needed? avoid tuple assignment because it will circumvent the transient tag ### Does this PR introduce any user-facing change? No ### How was this patch tested? existing testsuites Closesapache#27523 from zhengruifeng/avoid_tuple_assign_to_transient. Authored-by: zhengruifeng <ruifengz@foxmail.com> Signed-off-by: Sean Owen <srowen@gmail.com>
…ent the transient tag ### What changes were proposed in this pull request? it is said in [LeastSquaresAggregator](https://github.com/apache/spark/blob/12e1bbaddbb2ef304b5880a62df6683fcc94ea54/mllib/src/main/scala/org/apache/spark/ml/optim/aggregator/LeastSquaresAggregator.scala#L188) that : > // do not use tuple assignment above because it will circumvent the transient tag I then check this issue with Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_241) ### Why are the changes needed? avoid tuple assignment because it will circumvent the transient tag ### Does this PR introduce any user-facing change? No ### How was this patch tested? existing testsuites Closesapache#27523 from zhengruifeng/avoid_tuple_assign_to_transient. Authored-by: zhengruifeng <ruifengz@foxmail.com> Signed-off-by: Sean Owen <srowen@gmail.com>
…ent the transient tag ### What changes were proposed in this pull request? it is said in [LeastSquaresAggregator](https://github.com/apache/spark/blob/12e1bbaddbb2ef304b5880a62df6683fcc94ea54/mllib/src/main/scala/org/apache/spark/ml/optim/aggregator/LeastSquaresAggregator.scala#L188) that : > // do not use tuple assignment above because it will circumvent the transient tag I then check this issue with Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_241) ### Why are the changes needed? avoid tuple assignment because it will circumvent the transient tag ### Does this PR introduce any user-facing change? No ### How was this patch tested? existing testsuites Closesapache#27523 from zhengruifeng/avoid_tuple_assign_to_transient. Authored-by: zhengruifeng <ruifengz@foxmail.com> Signed-off-by: Sean Owen <srowen@gmail.com>
What changes were proposed in this pull request?
it is said in LeastSquaresAggregator that :
I then check this issue with Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_241)
Why are the changes needed?
avoid tuple assignment because it will circumvent the transient tag
Does this PR introduce any user-facing change?
No
How was this patch tested?
existing testsuites