Skip to content

Commit

Permalink
Add fix for SPARK-7766.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed May 20, 2015
1 parent 71845e3 commit e19726d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private[spark] class KryoSerializerInstance(ks: KryoSerializer) extends Serializ

override def serialize[T: ClassTag](t: T): ByteBuffer = {
output.clear()
kryo.reset() // We must reset in case this serializer instance was reused (see SPARK-7766)
try {
kryo.writeClassAndObject(output, t)
} catch {
Expand All @@ -202,6 +203,7 @@ private[spark] class KryoSerializerInstance(ks: KryoSerializer) extends Serializ
}

override def serializeStream(s: OutputStream): SerializationStream = {
kryo.reset() // We must reset in case this serializer instance was reused (see SPARK-7766)
new KryoSerializationStream(kryo, s)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ class KryoSerializerSuite extends FunSuite with SharedSparkContext {
assert (output1 === output2)
}

// Regression test for SPARK-7766, an issue where disabling auto-reset and enabling
// reference-tracking would lead to corrupted output when serializer instances are re-used
for (referenceTracking <- Set(true, false); autoReset <- Set(true, false)) {
test(s"instance reuse with autoReset = $autoReset, referenceTracking = $referenceTracking") {
testSerializerInstanceReuse(autoReset = autoReset, referenceTracking = referenceTracking)
Expand Down

0 comments on commit e19726d

Please sign in to comment.