Skip to content

Add Spark custom Kryo registrator - #549

Closed
jzhuge wants to merge 1 commit into
apache:masterfrom
jzhuge:spark-custom-kryo-registrator
Closed

jzhuge wants to merge 1 commit into
apache:masterfrom
jzhuge:spark-custom-kryo-registrator

Conversation

@jzhuge

@jzhuge jzhuge commented Oct 15, 2019 •

Copy link
Copy Markdown
Member

Kryo can't handle guava ImmutableList and ImmutableMap. This commit add a Spark custom Kryo registrator for these classes used by GenericDataFile.

Unit test TestKryoSerialization adapted from the one in #546.

A downstream project works fine after adding this Spark conf:

spark.kryo.registrator                org.apache.iceberg.spark.SparkKryoRegistrator

Fixes #446.

This PR replaces #546 that may be merged first before the release.

Comment thread build.gradle Outdated
compile project(':iceberg-parquet')
compile project(':iceberg-hive')

compile 'de.javakaffee:kryo-serializers'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be included in iceberg-spark-runtime, which means that we will need to make sure we add it to the shaded LICENSE and NOTICE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added additional LICENSE and NOTICE.

.build();

private SparkConf conf = new SparkConf()
.set("spark.kryo.registrator", SparkKryoRegistrator.class.getCanonicalName());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the registration to Spark's KryoSerializer from IcebergSource? It would be nice if users didn't have to add config properties.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the idea. Let me explore. Might have to instantiate the global SparkEnv.

Comment thread versions.lock Outdated
asm:asm:3.1 (2 constraints: 4f19c3c6)
com.carrotsearch:hppc:0.7.2 (1 constraints: f70cda14)
com.clearspring.analytics:stream:2.7.0 (1 constraints: 1a0dd136)
com.esotericsoftware:kryo:4.0.2 (1 constraints: 720da324)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to substitute kryo with kryo-shaded?
I took a quick stab at gradle dependency substitution but couldn't get it going because --write-locks still output kryo, not kryo-shaded.

@jzhuge
jzhuge force-pushed the spark-custom-kryo-registrator branch from 9b0b7ff to 4928991 Compare October 15, 2019 19:43
@jzhuge

jzhuge commented Oct 15, 2019 •

Copy link
Copy Markdown
Member Author

Rebase after merging #546.

TODO:

  • Substitute dependency kryo with kryo-shaded
  • Explore registering Kryo serializers in IcebergSource thus no need to add Spark conf spark.kryo.registrator.

@aokolnychyi

Copy link
Copy Markdown
Contributor

This PR will also unblock #553 as we need to handle SerializableConfiguration in a special way when broadcasting.

@jzhuge
jzhuge force-pushed the spark-custom-kryo-registrator branch from 869ea31 to 93eafaa Compare October 20, 2019 02:14
@jzhuge

jzhuge commented Oct 20, 2019

Copy link
Copy Markdown
Member Author

Spark KryoSerializer calls Twitter's com.twitter.chill.AllScalaRegistrar that includes serializers for many Java unmodifiable collections.

@rdblue

rdblue commented Dec 18, 2019

Copy link
Copy Markdown
Contributor

I think we want to avoid requiring a custom registrator for Spark to work with Kryo. Instead, we will need to use non-guava collections in places that may be serialized with Kryo.

@jzhuge, @aokolnychyi, should we close this or is there still value in having a custom registrator even if we try to avoid needing it?

@jzhuge

jzhuge commented Dec 18, 2019

Copy link
Copy Markdown
Member Author

Ok to close.

@rdblue rdblue closed this Dec 18, 2019
@flyrain

flyrain commented Jul 28, 2021 •

Copy link
Copy Markdown
Contributor

Are we going to replace guava maps with non-guava ones? There are bunches of place using guava's Immutable Map. For example, here are 4 guava maps in class TableMetadata. We hit this issue when we were trying to broadcast one of them.

    this.snapshotsById = indexAndValidateSnapshots(snapshots, lastSequenceNumber);
    this.schemasById = indexSchemas();
    this.specsById = indexSpecs(specs);
    this.sortOrdersById = indexSortOrders(sortOrders);

@jzhuge

jzhuge commented Jul 29, 2021

Copy link
Copy Markdown
Member Author

What version of kyro do you use? Newer versions support ImmutableMap.

@flyrain

flyrain commented Jul 29, 2021 •

Copy link
Copy Markdown
Contributor

@jzhuge

jzhuge commented Jul 29, 2021

Copy link
Copy Markdown
Member Author

Oops, I referenced the wrong repo.

If possible, you can add the following code to KryoSerializer.newKryo():

    ImmutableListSerializer.registerSerializers(kryo);
    ImmutableMapSerializer.registerSerializers(kryo);

Be sure to add dependency on de.javakaffee:kryo-serializers.

@flyrain

flyrain commented Jul 30, 2021

Copy link
Copy Markdown
Contributor

Hi @jzhuge, not sure I understand. Do I add these lines to my Spark application or Spark itself?

    ImmutableListSerializer.registerSerializers(kryo);
    ImmutableMapSerializer.registerSerializers(kryo);

@jzhuge

jzhuge commented Jul 30, 2021

Copy link
Copy Markdown
Member Author

Spark itself if you can

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KryoException when writing Iceberg tables in Spark

4 participants