Skip to content

Commit 49d2ec6

Browse files
mccheahpwendell
authored andcommitted
[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. Author: mcheah <[email protected]> Closes apache#5218 from mccheah/feature/limit-kryo-buffer and squashes the following commits: 1d6d1be [mcheah] Fixing numeric typo e2e30ce [mcheah] Removing explicit int and double type to match style 09fd80b [mcheah] Should be >= not >. Slightly more consistent error message. 60634f9 [mcheah] [SPARK-6405] Limiting the maximum Kryo buffer size to be 2GB.
1 parent 39fb579 commit 49d2ec6

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 = 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 mb, got: + $bufferSizeMb mb.")
56+
}
57+
private val bufferSize = (bufferSizeMb * 1024 * 1024).toInt
58+
59+
val maxBufferSizeMb = 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 mb, 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)