Skip to content

Commit 6b8de0e

Browse files
GrahamDennisrxin
authored andcommitted
SPARK-2893: Do not swallow Exceptions when running a custom kryo registrator
The previous behaviour of swallowing ClassNotFound exceptions when running a custom Kryo registrator could lead to difficult to debug problems later on at serialisation / deserialisation time, see SPARK-2878. Instead it is better to fail fast. Added test case. Author: Graham Dennis <[email protected]> Closes #1827 from GrahamDennis/feature/spark-2893 and squashes the following commits: fbe4cb6 [Graham Dennis] [SPARK-2878]: Update the test case to match the updated exception message 65e53c5 [Graham Dennis] [SPARK-2893]: Improve message when a spark.kryo.registrator fails. f480d85 [Graham Dennis] [SPARK-2893] Fix typo. b59d2c2 [Graham Dennis] SPARK-2893: Do not swallow Exceptions when running a custom spark.kryo.registrator
1 parent d069c5d commit 6b8de0e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ class KryoSerializer(conf: SparkConf)
7979
kryo.register(classOf[HttpBroadcast[_]], new KryoJavaSerializer())
8080

8181
// Allow the user to register their own classes by setting spark.kryo.registrator
82-
try {
83-
for (regCls <- registrator) {
84-
logDebug("Running user registrator: " + regCls)
82+
for (regCls <- registrator) {
83+
logDebug("Running user registrator: " + regCls)
84+
try {
8585
val reg = Class.forName(regCls, true, classLoader).newInstance()
8686
.asInstanceOf[KryoRegistrator]
8787
reg.registerClasses(kryo)
88+
} catch {
89+
case e: Exception =>
90+
throw new SparkException(s"Failed to invoke $regCls", e)
8891
}
89-
} catch {
90-
case e: Exception => logError("Failed to run spark.kryo.registrator", e)
9192
}
9293

9394
// Register Chill's classes; we do this after our ranges and the user's own classes to let

core/src/test/scala/org/apache/spark/serializer/KryoSerializerSuite.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ class KryoSerializerSuite extends FunSuite with SharedSparkContext {
207207
.fold(new ClassWithoutNoArgConstructor(10))((t1, t2) => new ClassWithoutNoArgConstructor(t1.x + t2.x)).x
208208
assert(10 + control.sum === result)
209209
}
210+
211+
test("kryo with nonexistent custom registrator should fail") {
212+
import org.apache.spark.{SparkConf, SparkException}
213+
214+
val conf = new SparkConf(false)
215+
conf.set("spark.kryo.registrator", "this.class.does.not.exist")
216+
217+
val thrown = intercept[SparkException](new KryoSerializer(conf).newInstance())
218+
assert(thrown.getMessage.contains("Failed to invoke this.class.does.not.exist"))
219+
}
210220
}
211221

212222
class KryoSerializerResizableOutputSuite extends FunSuite {

0 commit comments

Comments
 (0)