iceberg: Failed to assign splits due to the serialized split size

Apache Iceberg version

1.4.2 (latest release)

Query engine

Flink

Please describe the bug ๐Ÿž

Hi there, I am trying to consume records from an Iceberg table in my Flink application and I am running into the following issue;

Caused by: org.apache.flink.util.FlinkRuntimeException: Failed to serialize splits.
	at org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext.lambda$assignSplits$4(SourceCoordinatorContext.java:223)
	at java.base/java.util.HashMap.forEach(HashMap.java:1337)
	at org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext.lambda$assignSplits$5(SourceCoordinatorContext.java:213)
	at org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext.callInCoordinatorThread(SourceCoordinatorContext.java:428)
	... 14 more
Caused by: java.io.UTFDataFormatException: Encoded string is too long: 123214
	at org.apache.flink.core.memory.DataOutputSerializer.writeUTF(DataOutputSerializer.java:257)
	at org.apache.iceberg.flink.source.split.IcebergSourceSplit.serializeV2(IcebergSourceSplit.java:150)
	at org.apache.iceberg.flink.source.split.IcebergSourceSplitSerializer.serialize(IcebergSourceSplitSerializer.java:42)
	at org.apache.iceberg.flink.source.split.IcebergSourceSplitSerializer.serialize(IcebergSourceSplitSerializer.java:25)
	at org.apache.flink.runtime.source.event.AddSplitEvent.<init>(AddSplitEvent.java:44)
	at org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext.lambda$assignSplits$4(SourceCoordinatorContext.java:220)
	... 17 more

Not really sure why it gets too big but when I looked at the source code here, it might be because there is too many file scan task in one split and that is why this is happening.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (29 by maintainers)

Commits related to this issue

Most upvoted comments

But I still have too many equality deletes which is still causing the limit excess. Did I use the wrong spark procedure?

I think RewriteDataFilesAction could help you there. If I remember correctly it will apply all the delete files on reading, so in theory, after a compaction, you should not need the delete files anymore. That said, I havenโ€™t tried it myself, so this should be checked.

I couldnโ€™t do this @pvary , the split is far ahead and some time is needed to get there in the application. My local environment is not able to run the app on real data and hit this problematic split on debug mode. It crashes because debug mode is quite a resource consuming mode. Still looking for a way to reproduce it and debu it but Just wanted to let you know the status. (Side note, I ended up re-creating my entire source data, that way it did not have this problem. But I want to find the reason why it exceeds that limit regardless.)

@stevenzwu: After a quick check, I have found this: https://github.com/apache/flink/blob/c6997c97c575d334679915c328792b8a3067cfb5/flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java#L256-L260

        if (utflen > 65535) {
            throw new UTFDataFormatException("Encoded string is too long: " + utflen);
        } else if (this.position > this.buffer.length - utflen - 2) {
            resize(utflen + 2);
        }

This means that anything which is above 64k could not be serialized by DataOutputSerializer.writeUTF, which seems a bit arbitrary limit for me.

We could use DataOutputSerializer.writeChars which uses DataOutputSerializer.writeChar. The downside is that it is less effective if we use simple chars (between 0x0001 and 0x007F): See: https://github.com/apache/flink/blob/c6997c97c575d334679915c328792b8a3067cfb5/flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java#L245C1-L254C10

        for (int i = 0; i < strlen; i++) {
            c = str.charAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                utflen++;
            } else if (c > 0x07FF) {
                utflen += 3;
            } else {
                utflen += 2;
            }
        }

The upside that it should work regardless of the size of the string.