Skip to content

Commit

Permalink
[SPARK-6087][CORE] Provide actionable exception if Kryo buffer is not…
Browse files Browse the repository at this point in the history
… large enough

A simple try-catch wrapping KryoException to be more informative.

Author: Lev Khomich <[email protected]>

Closes apache#4947 from levkhomich/master and squashes the following commits:

0f7a947 [Lev Khomich] [SPARK-6087][CORE] Provide actionable exception if Kryo buffer is not large enough
  • Loading branch information
levkhomich authored and srowen committed Mar 10, 2015
1 parent 9a0272f commit c4c4b07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ private[spark] class KryoSerializerInstance(ks: KryoSerializer) extends Serializ

override def serialize[T: ClassTag](t: T): ByteBuffer = {
output.clear()
kryo.writeClassAndObject(output, t)
try {
kryo.writeClassAndObject(output, t)
} catch {
case e: KryoException if e.getMessage.startsWith("Buffer overflow") =>
throw new SparkException(s"Kryo serialization failed: ${e.getMessage}. To avoid this, " +
"increase spark.kryoserializer.buffer.max.mb value.")
}
ByteBuffer.wrap(output.toBytes)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ class KryoSerializerSuite extends FunSuite with SharedSparkContext {
ser.serialize(HighlyCompressedMapStatus(BlockManagerId("exec-1", "host", 1234), blockSizes))
}
}

test("serialization buffer overflow reporting") {
import org.apache.spark.SparkException
val kryoBufferMaxProperty = "spark.kryoserializer.buffer.max.mb"

val largeObject = (1 to 1000000).toArray

val conf = new SparkConf(false)
conf.set(kryoBufferMaxProperty, "1")

val ser = new KryoSerializer(conf).newInstance()
val thrown = intercept[SparkException](ser.serialize(largeObject))
assert(thrown.getMessage.contains(kryoBufferMaxProperty))
}
}


Expand Down

0 comments on commit c4c4b07

Please sign in to comment.