Skip to content

KryoException when writing Iceberg tables in Spark  #446

Closed

Description

@shardulm94

Say we have a table test (col1: string).

case class Input(col1: String)
val df = spark.createDataFrame(List(Input("data1"), Input("data2")))
df.write.format("iceberg").mode("overwrite").option("write-format", "parquet").save("default.test")
2019-09-04 05:35:13 ERROR TaskResultGetter:91 - Exception while getting task result
com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException
Serialization trace:
splitOffsets (org.apache.iceberg.GenericDataFile)
files (org.apache.iceberg.spark.source.Writer$TaskCommit)
	at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:391)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:302)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
	at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543)
	at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813)
	at org.apache.spark.serializer.KryoSerializerInstance.deserialize(KryoSerializer.scala:362)
	at org.apache.spark.scheduler.DirectTaskResult.value(TaskResult.scala:88)
	at org.apache.spark.scheduler.TaskResultGetter$$anon$3$$anonfun$run$1.apply$mcV$sp(TaskResultGetter.scala:72)
	at org.apache.spark.scheduler.TaskResultGetter$$anon$3$$anonfun$run$1.apply(TaskResultGetter.scala:63)
	at org.apache.spark.scheduler.TaskResultGetter$$anon$3$$anonfun$run$1.apply(TaskResultGetter.scala:63)
	at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1945)
	at org.apache.spark.scheduler.TaskResultGetter$$anon$3.run(TaskResultGetter.scala:62)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.UnsupportedOperationException
	at org.apache.iceberg.shaded.com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:244)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:134)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:40)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:731)
	at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
	... 18 more
2019-09-04 05:35:13 ERROR WriteToDataSourceV2Exec:70 - Data source writer IcebergWrite(table=default.test, format=PARQUET) is aborting.
2019-09-04 05:35:13 ERROR WriteToDataSourceV2Exec:70 - Data source writer IcebergWrite(table=default.test, format=PARQUET) aborted.

Hitting this when writing Parquet data in Spark 2.4 using the latest master. I believe this is because in 549da80 an immutable copy of the split offsets are stored in GenericDataFile. The serialization is successful, but when deserializing, Kryo will try to instantiate an ImmutableList first and then add elements to it.
I think this can be fixed in two ways:

  1. Don't use immutable copies of the split offsets list. I am not sure what was the intention of making them immutable in the first place. Other metadata like metrics are still being provided in mutable collections.
  2. Include custom Kryo serdes which support guava immutable collections. e.g. https://github.com/magro/kryo-serializers/

Option 2 seems a little overkill IMO for this specific case given that immutable collections don't seem to be necessary here, but would like to hear what others think.

Activity

  1. rdblue commented on Sep 5, 2019

    @rdblue
    Contributor

    I would rather add the Kryo serializers for immutable collections. I think it makes sense for Iceberg to use ImmutableList because the data returned should not be mutable and that minimizes the cost of later copies.

  2. aokolnychyi commented on Sep 6, 2019

    @aokolnychyi
    Contributor

    We ended up with kryo.register(Class.forName("org.apache.iceberg.GenericDataFile"), new JavaSerializer()); to make Kryo work with Iceberg. GenericDataFile has custom serialization logic.

  3. rdsr commented on Sep 17, 2019

    @rdsr
    Contributor

    @shardulm94 do u plan to submit a PR for this?

  4. shardulm94 commented on Sep 17, 2019

    @shardulm94
    ContributorAuthor

    @rdsr I plan to, although I am not fully sure how to register the custom serializers in Spark.

    @aokolnychyi Did you have to modify Spark to add that line (here) or is there a way to get the Kryo instance used so that we can register the class from inside Iceberg?

  5. aokolnychyi commented on Sep 17, 2019

    @aokolnychyi
    Contributor

    @shardulm94 @rdsr it is possible to set this via the public API:

    sparkConf.set("spark.kryo.registrator", "full-class-name-of-custom-registrator")
    
  6. aokolnychyi commented on Sep 17, 2019

    @aokolnychyi
    Contributor

    If the above logic works for you, it would be great to add this to our docs.

  7. aokolnychyi commented on Sep 26, 2019

    @aokolnychyi
    Contributor

    @shardulm94 did the suggested approach work for you?

  8. jzhuge commented on Oct 17, 2019

    @jzhuge
    Member

    @aokolnychyi @shardulm94 @rdsr please take a look at a custom Spark Kryo registrator for Iceberg in #549.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions