Skip to content

fix(spec): validate the metadata log in build() with the entry for the previous file - #3695

Merged
laskoviymishka merged 2 commits into
apache:mainfrom
c-thiel:ct/fix-validate-metadata-log-with-entry-for-previous-file
Nov 16, 2026
Merged

laskoviymishka merged 2 commits into
apache:mainfrom
c-thiel:ct/fix-validate-metadata-log-with-entry-for-previous-file

Conversation

@c-thiel

@c-thiel c-thiel commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

A writer whose clock runs ahead can make TableMetadataBuilder produce table metadata that neither this crate nor Iceberg Java can load again.

What changes are included in this PR?

TableMetadataBuilder::build() validated the new metadata before it added the metadata-log entry for the previous metadata file. A build whose last-updated-ms was more than one minute before that entry passed. The written file then failed to load with "Invalid update timestamp …: before last metadata log entry".

One way to get there: a writer whose clock is ahead adds a snapshot on a branch, so last-updated-ms becomes that snapshot's time. The next change to the table that adds no snapshot takes the current time, which is before the previous file's entry.

build() now adds the entry and expires the metadata log before it validates, so such a build fails instead of producing metadata that no reader can load. Iceberg Java (TableMetadata.Builder.build(), then the TableMetadata constructor) and iceberg-go (MetadataBuilder.Build) check in this order.

Are these changes tested?

Yes. test_metadata_change_after_a_fast_branch_snapshot_is_refused_in_build in spec::table_metadata_builder adds a branch snapshot dated two hours ahead, then sets a property, and checks that the build fails with the metadata-log error. It fails without the fix.

AI Disclosure

Supported by Claude Code. Reviewed and checked by me.

@laskoviymishka laskoviymishka left a comment

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.

Thanks @c-thiel for the repro test. As I read it, running try_normalize() after the push only changes the outcome of validate_chronological_metadata_logs, and the builds that now fail are the ones the deserializer already rejects on load. Java and iceberg-go also append the previous-file entry before the same one-minute check.

}

#[test]
fn test_metadata_change_after_a_fast_branch_snapshot_is_refused_in_build() {

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.

Could we add a companion case where the skew stays inside the one-minute tolerance (say 30s) and the second build() still succeeds? This test is the only one that reaches the metadata-log check with a previous-file entry, so nothing would catch the check being tightened past the tolerance.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added test_metadata_change_after_a_slightly_fast_branch_snapshot_builds in fa4c201: the same setup with 30 s of skew, where the second build() succeeds and the entry for the previous file is the last metadata-log entry. Both tests now share a small helper. With the tolerance cut to 10 s, the new test fails.

@laskoviymishka
laskoviymishka added this pull request to the merge queue Nov 16, 2026
Merged via the queue into apache:main with commit d15dca0 Nov 16, 2026
24 checks passed
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.

2 participants