kumarpritam863 opened a new pull request, #19136:
URL: https://github.com/apache/iceberg/pull/19136
## Summary
Fix `RewriteDataFiles` never rewriting on S3: the planned groups fail to
serialize (the table of a planned group travels as Java-serialized bytes).
## Problem
`RewriteDataFiles` (Flink table maintenance compaction) never rewrites
anything on a table whose FileIO is `S3FileIO`. The planner finds the files to
rewrite, then fails when it sends the groups to the rewrite tasks. The failure
is caught and logged as a WARN, the task counts an error and the job keeps
running, so compaction just looks idle.
```
WARN DataFileRewritePlanner - [For table iceberg.<db>.<table> with
RewriteDataFiles [1][1] at 1795234338726]: Failed to plan data file rewrite
groups
com.esotericsoftware.kryo.KryoException:
java.lang.UnsupportedOperationException: can't get field offset on a hidden
class:
private final org.apache.iceberg.aws.AwsClientFactory
org.apache.iceberg.aws.s3.S3FileIO$$Lambda$3143/0x00007f1f830bb618.arg$1
Serialization trace:
s3 (org.apache.iceberg.aws.s3.S3FileIO)
io (org.apache.iceberg.SerializableTable)
table
(org.apache.iceberg.flink.maintenance.operator.DataFileRewritePlanner$PlannedGroup)
at
com.esotericsoftware.kryo.serializers.ReflectField.write(ReflectField.java:102)
...
at
org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.serialize(KryoSerializer.java:346)
at
org.apache.flink.streaming.runtime.streamrecord.StreamElementSerializer.serialize(StreamElementSerializer.java:173)
at
org.apache.flink.runtime.io.network.api.writer.RecordWriter.emit(RecordWriter.java:108)
...
at
org.apache.flink.streaming.api.operators.TimestampedCollector.collect(TimestampedCollector.java:53)
at
org.apache.iceberg.flink.maintenance.operator.DataFileRewritePlanner.processElement(DataFileRewritePlanner.java:172)
...
Caused by: java.lang.UnsupportedOperationException: can't get field offset
on a hidden class: ... S3FileIO$$Lambda$3143/0x00007f1f830bb618.arg$1
at
[email protected]/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:645)
at
com.esotericsoftware.kryo.serializers.UnsafeField.<init>(UnsafeField.java:38)
```
## Why it happens
1. `DataFileRewritePlanner` emits `PlannedGroup` objects to the
`DataFileRewriteRunner` (a `rebalance()` edge, so over the network). A
`PlannedGroup` holds a `SerializableTable`.
2. `PlannedGroup` is not a POJO (private final fields, no setters), so Flink
types it as a generic type and serializes it with **Kryo**, field by field.
3. The table's `io` is an `S3FileIO`. Its `s3` field is a
`SerializableSupplier<S3Client>` created from `AwsClientFactory::s3`, i.e. a
**lambda**. On Java 17 a lambda is a *hidden class*, and Kryo's `UnsafeField`
cannot take the offset of its captured field (`arg$1`). Java serialization
handles such lambdas (`SerializedLambda`), Kryo does not.
4. It only fails when the plan has at least one group, and only with a
FileIO that holds a lambda. The unit tests use `HadoopFileIO`, so they never
see it, and a table with nothing to rewrite never reaches the serializer.
5. The planner catches the exception (`LOG.warn(... "Failed to plan data
file rewrite groups")`, error counter, `TaskResultAggregator.ERROR_STREAM`), so
the job stays RUNNING and nothing else fails. The only signs are that WARN, the
error counter, and `Rewrite commit` never receiving a record.
## Reproducing it
`TestRewriteDataFilesWithLambdaFileIO` (new) runs the real
`RewriteDataFiles` pipeline on a mini cluster against a table whose FileIO
holds a lambda, like `S3FileIO` does. On the unfixed branch it fails with the
same error as above:
```
WARN DataFileRewritePlanner - [For table dummyTable with dummyTask[0] ...]:
Failed to plan data file rewrite groups
com.esotericsoftware.kryo.KryoException:
java.lang.UnsupportedOperationException: can't get field offset on a hidden
class: private final java.lang.String
...LambdaHoldingFileIO$$Lambda$1300/0x000000060179bd98.arg$1
TaskResult{... success=false,
exceptions=[com.esotericsoftware.kryo.KryoException: ...
```
## Change (the table travels as bytes)
`PlannedGroup` keeps the table as Java-serialized bytes
(`InstantiationUtil.serializeObject`) and deserializes it lazily in `table()`,
so Kryo only sees a `byte[]` and never reaches the FileIO. This is the
simplification suggested in review, in place of a custom `TypeInformation`,
`TypeSerializer` and factory (about 285 lines, now removed).
- The planner serializes the table **once per plan** and the groups of the
plan share the bytes (the previous revision of this PR serialized it once per
record).
- `table()` deserializes on first use with the context class loader (the
user-code class loader in a task) and caches the result. The cache is
`transient`: Kryo skips it, and a copy Flink makes for chained operators
rebuilds it lazily.
- No change to the operators or to the wiring. The table still travels with
every group, as it did before the bug.
## Tests
- `TestRewriteDataFilesWithLambdaFileIO` (new): the end-to-end pipeline
above. Fails on the base branch, passes with this change.
- `TestPlannedGroupSerialization` (new, 5 tests): round trip through Flink's
own serializer for a plain table and for a FileIO that holds a lambda (it fails
on the base code with the Kryo error of the S3 job), the copy Flink makes for
chained operators, the table being deserialized once, and `PlannedGroup`
staying a generic type (the table is bytes, so the generic serializer is
enough).
- `TestDataFileRewriteRunner#testError` now breaks the rewrite by deleting
the data files. It used to drop the table, but the data files of that test
table are outside the table location and survive the drop, so the old failure
came from the group's table, not from reading the files; with the table
serialized through Java serialization the rewrite succeeds after the drop, so
the test no longer tested an error.
- `org.apache.iceberg.flink.maintenance.*`: 385 tests, 0 failures, rerun on
this revision. `spotlessCheck` is clean. I could not run `checkstyleMain/Test`:
its dependencies are not in the offline cache.
## Workaround without this change
Make Flink serialize `SerializableTable` with Java serialization, in the
Flink configuration:
```
pipeline.serialization-config: "[{org.apache.iceberg.SerializableTable:
{type: kryo, kryo-type: default, class:
com.esotericsoftware.kryo.serializers.JavaSerializer}}]"
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]