Skip to content

Commit 60634f9

Browse files
committed
[SPARK-6405] Limiting the maximum Kryo buffer size to be 2GB.
Kryo buffers are backed by byte arrays, but primitive arrays can only be up to 2GB in size. It is misleading to allow users to set buffers past this size.
1 parent 784fcd5 commit 60634f9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/src/main/scala/org/apache/spark/serializer/KryoSerializer.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,20 @@ class KryoSerializer(conf: SparkConf)
4949
with Logging
5050
with Serializable {
5151

52-
private val bufferSize =
53-
(conf.getDouble("spark.kryoserializer.buffer.mb", 0.064) * 1024 * 1024).toInt
52+
private val bufferSizeMb: Double = conf.getDouble("spark.kryoserializer.buffer.mb", 0.064)
53+
if (bufferSizeMb > 2048) {
54+
throw new IllegalArgumentException("spark.kryoserializer.buffer.mb must be less than " +
55+
s"2048 megabytes, got: + $bufferSizeMb mb.")
56+
}
57+
private val bufferSize = (bufferSizeMb * 1024 * 1024).toInt
58+
59+
val maxBufferSizeMb: Int = conf.getInt("spark.kryoserializer.buffer.max.mb", 64)
60+
if (maxBufferSizeMb > 2048) {
61+
throw new IllegalArgumentException("spark.kryoserializer.buffer.max.mb must be less than " +
62+
s"2048 megabytes, got: + $maxBufferSizeMb mb.")
63+
}
64+
private val maxBufferSize = maxBufferSizeMb * 1024 * 1024
5465

55-
private val maxBufferSize = conf.getInt("spark.kryoserializer.buffer.max.mb", 64) * 1024 * 1024
5666
private val referenceTracking = conf.getBoolean("spark.kryo.referenceTracking", true)
5767
private val registrationRequired = conf.getBoolean("spark.kryo.registrationRequired", false)
5868
private val userRegistrator = conf.getOption("spark.kryo.registrator")

0 commit comments

Comments
 (0)