Skip to content
Snippets Groups Projects
Commit c4c4b07b authored by Lev Khomich's avatar Lev Khomich Committed by Sean Owen
Browse files

[SPARK-6087][CORE] Provide actionable exception if Kryo buffer is not large enough

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

Author: Lev Khomich <levkhomich@gmail.com>

Closes #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
parent 9a0272fb
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
......@@ -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))
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment