All posts

Inside Apache XTable: from source metadata to target commits

How the controller picks a full or incremental pass for each target, the four different rules a source uses to decide it is safe to resume, and what the code does when a target fails.

9 min read Lakehouse

TL;DR

A sync is a loop over targets. For each one, the controller decides between a snapshot pass and an incremental pass, reads the source through a ConversionSource, and TableFormatSync applies the result in a fixed order.

  • Every source answers the same question differently: is it safe to resume from this instant? Hudi checks the cleaner, Iceberg walks the snapshot parents, Delta looks for an active commit, and Paimon checks that snapshots still reach back that far.
  • The mode is decided per target from the target’s own XTABLE_METADATA. The most out-of-sync target sets how far back the source is read, and each target skips what it already has.
  • An incremental pass replays each source commit as a target commit. A snapshot pass writes the current file set in one.
  • The internal model has 19 data types, six partition transforms and a file with partition values and column statistics. Anything outside that is dropped by design.
  • Failures are contained per target. Nothing in the sync retries them, and a repeat run resumes from what each target recorded.

The architecture post described the pieces. This one follows the data through them, in the order the code runs it. Every claim was read from the 0.5.0-incubating source, and the classes are named so you can open them.

1. How each source finds the logical table

A directory of Parquet files is not a table. Each source has to work out which files belong to the table now, which is why none of them lists the folder.

Source Where the logic lives What it reads
Hudi HudiConversionSource, HudiDataFileExtractor, HudiTableExtractor The timeline and file slices through Hudi’s own metadata classes
Iceberg IcebergConversionSource, IcebergDataFileExtractor The current snapshot and its manifests
Delta DeltaConversionSource, DeltaDataFileExtractor The Delta log’s current snapshot of add and remove actions
Paimon PaimonConversionSource, PaimonDataFileExtractor Snapshots and manifests of the LSM tree’s top level
Parquet ParquetConversionSource, ParquetDataManager The files under the base path, with footer metadata

The Parquet row is the odd one: with no table metadata it has to list files and read footers, which is why it is configured separately. It treats each file’s modification time as its commit time, so incremental sync works from file modification times, and its isIncrementalSyncSafeFrom is true when the earliest file is not newer than the instant. All targets must be at the same instant, or it fails with Parquet incremental sync does not support target formats synced to different instants. This was read from the code and not run. For the others, a storage listing is never the source of truth. A folder can hold replaced, cleaned or uncommitted files that the table’s own metadata excludes.

2. The internal model

Each source fills the same structures in xtable-api.

Schema. An InternalSchema is a tree of fields. Each node has an InternalType, and the full set is RECORD, ENUM, LIST, MAP, UNION, UUID, FIXED, STRING, BYTES, INT, LONG, FLOAT, DOUBLE, BOOLEAN, NULL, DATE, DECIMAL, TIMESTAMP and TIMESTAMP_NTZ. Every format’s schema is mapped into that list by its own extractor (HudiSchemaExtractor, IcebergSchemaExtractor, DeltaSchemaExtractor, PaimonSchemaExtractor, ParquetSchemaExtractor) and back out again by the target. A type that is not in the list has no path through the model.

Partitions. A partition field has a source field and one of YEAR, MONTH, DAY, HOUR, VALUE or BUCKET. The table also carries a layout strategy, one of HIVE_STYLE_PARTITION, DIR_HIERARCHY_PARTITION_VALUES or FLAT, which says how partition values appear in file paths. Hudi sources read the partition spec from configuration, which is the partitionSpec field you set, through ConfigurationBasedPartitionSpecExtractor, or from the path.

Files. An InternalDataFile has a path, a size, a record count, a format, partition values, column statistics and a last-modified time. Statistics come from the source’s own metadata where it has them: Iceberg manifests carry them, and Delta keeps them in the log. Hudi reads them from its metadata table and, where a file has none that are usable, from the Parquet footer.

Changes. For an incremental pass the source builds a TableChange per commit, holding an InternalFilesDiff (files added and removed) and the table as of that commit.

3. Choosing the mode

The decision for one target: does the target say incremental is safe, does it have a sync record, is the source safe from the earliest pending instant; any no leads to a snapshot sync

RunSync builds its ConversionConfig with SyncMode.INCREMENTAL every time. There is no flag for a full sync. ConversionController.getFormatsToSyncIncrementally then walks the targets, and a target stays incremental only if it passes three checks:

  1. The target says so. isIncrementalSyncSafe() on the target defaults to true, and in 0.5.0 only the Hudi target overrides it. It returns false for an existing Hudi target that has a timeline but no column-stats index, which is what a table synced by 0.4.0 looks like. The next sync then takes a snapshot pass so every file is registered again with its statistics.
  2. The target has a sync record. The last synced instant and any pending instants come from its XTABLE_METADATA. With neither, the controller logs No previous InternalTable sync for target. Falling back to snapshot sync.
  3. The source can resume from there. The earliest of the last synced instant and the pending instants goes to isIncrementalSyncSafeFrom. If that returns false, the controller logs Incremental sync is not safe from instant ... Falling back to snapshot sync.

Targets that fail go to a snapshot pass and the rest go incremental, in the same invocation.

What “safe” means, per source

Source isIncrementalSyncSafeFrom(instant) is true when
Hudi A commit exists as of the instant, and the last completed clean has not removed it: the clean’s earliest commit to retain must not be after the instant
Iceberg Walking back from the current snapshot through parent snapshots reaches a snapshot at or before the instant. A missing or expired parent returns false
Delta The log has an active commit at or before the instant
Paimon Snapshots exist, the instant is not in the future, and the earliest snapshot is not newer than the instant, so expiry has not removed it

The Hudi row is why the cleaner matters. A clean that retained fewer commits than your sync lag makes the next run a snapshot pass, as the Hudi source post shows with a failing read.

The rule each source uses to decide it is safe to resume from an instant: Hudi checks cleans, Iceberg walks parent snapshots, Delta looks for an active commit, Paimon checks the earliest snapshot, Parquet checks file times

4. The incremental pass

syncIncrementalChanges collects the sync records of the incremental targets and calls getMostOutOfSyncCommitAndPendingCommits. That picks the oldest last-synced instant among them, and the union of their pending instants. The source reads changes from that point once, and TableFormatSync.syncChanges applies them to each target. A change applies to a target only if its commit time is after that target’s last synced instant or is in its pending list, so a target that already has it skips it.

Two targets at different commits: the oldest last-synced instant sets the start, the source is read once, and each target applies only the commits it lacks

Each source commit becomes one commit in the target. A target that was three commits behind ends the run with three new target commits, which is why a long gap is slower than a short one even before any fallback.

The pending instants exist for commits that were still in flight at the last sync, such as a Hudi instant that had not completed. They are stored in XTABLE_METADATA next to the last synced instant so a later run picks them up.

5. The snapshot pass

When any target needs a snapshot, the source reads its current state once with getCurrentSnapshot(), which returns an InternalSnapshot: the table, the files grouped by partition, the pending commits and a source identifier. Every snapshot target applies it with syncFilesForSnapshot. The cost grows with the number of files and commits the source has to read, not with the number of rows.

6. What happens when something fails

Each target runs in its own try block in TableFormatSync. An exception becomes an error result for that format, with an ErrorDetails object that includes a canRetryOnFailure flag, and the loop moves on. The controller then logs Sync is successful for the following formats ... for the successes and Sync failed for the following formats ... for the failures.

Three targets in one run: Iceberg and Hudi succeed and Delta fails with an error result, without stopping the others

Three things follow from that code:

  • A partial result is normal. One format can succeed while another fails, so check for the failure line, not only the success line.
  • Nothing retries. The flag tells a caller whether a retry makes sense. No code in the sync acts on it.
  • A failed target stops for the run. If a target fails on one commit, syncChanges skips it for the remaining commits in that run, while the other targets continue.
  • A repeat run resumes. The state written first in each target’s sync (syncMetadata, before schema and files) is what the next run reads. A target that failed before completing keeps its previous record, and the run after takes the mode from that.

7. Where to read the code

To understand Open
The decision and the loop ConversionController.syncTableFormats, getFormatsToSyncIncrementally, isIncrementalSyncSufficient
Call order and error handling TableFormatSync.syncSnapshot, syncChanges, getSyncResult
The stored state TableSyncMetadata and the XTABLE_METADATA constant
One source’s safety check isIncrementalSyncSafeFrom in each *ConversionSource
Type mapping InternalType and the *SchemaExtractor classes
One target’s writer each *ConversionTarget, and ConversionTargetFactory

Checked against the source

Every statement above comes from the 0.5.0-incubating tag. The four isIncrementalSyncSafeFrom rules and the controller’s three checks are quoted from the code, and the log messages are the strings in ConversionController. The two logs shown for a first run and an incremental run are from the first sync lab. Parquet’s behaviour was read from its package listing and was not traced in depth.

Key takeaways

The sync is decided one target at a time from a record each target keeps, and the source’s own definition of “safe to resume” is the only place a table’s history matters. That is why retention on the source side, not anything in XTable’s configuration, decides whether your runs stay incremental. The model is small on purpose, and it is also why some things never cross.

References

Trademarks

Apache XTable (incubating), Apache Hudi, Apache Iceberg, Apache Paimon, Apache Parquet and Apache are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries. Delta Lake is a trademark of the Linux Foundation. All other marks are the property of their respective owners.

Found this useful?

These posts and tools are free. If one saved you an afternoon, you can buy me a coffee.

Buy me a coffee

Comments

Questions, corrections and reviews are welcome. Sign in with GitHub to post; comments are stored in this site's public GitHub Discussions.