Skip to content

Core: unlink table metadata's last-updated timestamp from snapshot timestamp - #14504

Merged
RussellSpitzer merged 4 commits into
apache:mainfrom
dramaticlly:timesdtampFollowsSnapshot
Jan 8, 2026
Merged

RussellSpitzer merged 4 commits into
apache:mainfrom
dramaticlly:timesdtampFollowsSnapshot

Conversation

@dramaticlly

@dramaticlly dramaticlly commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

This pull introduce a change to unlink the table metadata's last updated timestamp from snapshot creation timestamp when snapshot was added or set as main branch reference.

Background

From iceberg spec per https://iceberg.apache.org/spec/#table-metadata-fields, the last-updated-ms represent

Timestamp in milliseconds from the unix epoch when the table was last updated. Each table metadata file should update this field just before writing.

The existing implementation have implicit behavior when snapshot is added or set as the reference in main branch, the last updated timestamp follows the snapshot creation timestamp in addSnapshot:

this.lastUpdatedMillis = snapshot.timestampMillis();

and set(snapshot)Ref:
this.lastUpdatedMillis = snapshot.timestampMillis();

There's also requirements to be validated when building TableMetadata

  • Chronological Ordering of Metadata Log Entries
    All metadata and data changes that affect the Iceberg state and result in a metadata.json file are recorded in MetadataLogEntry, which stores both the json file name and timestamp. These entries are required to be sorted chronologically by their lastUpdatedMillis, with a one-minute clock skew tolerance.

  • Chronological Ordering of Snapshot History Log
    Only data or manifest changes will generate a new snapshot. The Snapshot history log maintains both snapshot-id and timestamp, requiring chronological sorting by lastUpdatedMillis, with a one-minute clock skew tolerance.

Problem

This models works well when a single table is true authority of the truth, however when table replication come into play, or when iceberg metadata is generated/translated from other data source/format, it's difficult to achieve the consistent time travel behavior. Given the iceberg time travel can be configured with both snapshot-id and timestamp, for consistent time travel experience, sometimes it's desired to have backdated snapshot where commit a slightly older snapshot at current time, or diverge on table metadata timestamp and snapshot timestamp.

Generally it's easy to ensure the chronological ordering of snapshot, but other concurrent change to the table like properties update will unnecessarily fail the commit due to violation of chronological ordering on metadata log entries.

How it helps

@dramaticlly

dramaticlly commented Nov 5, 2025 •

Copy link
Copy Markdown
Contributor Author

Discussed on Nov 5th 2025 community sync https://docs.google.com/document/d/1YuGhUdukLP5gGiqCbk0A5_Wifqe2CZWgOd3TbhY3UQg/edit?tab=t.0, existing behavior helps with debug information to have table metadata lastUpdatedAt time follows snapshot creation timestamp, but this is for informational only and no assumption build on top of this. @rdblue have minor preference for follow but no voiced objection.

@dramaticlly dramaticlly changed the title Core: control whether table metadata's last-updated timestamp follows snapshot timestamp Core: unlink table metadata's last-updated timestamp from snapshot timestamp Nov 6, 2025
}

snapshotLog.add(new SnapshotLogEntry(lastUpdatedMillis, ref.snapshotId()));
snapshotLog.add(new SnapshotLogEntry(snapshot.timestampMillis(), snapshot.snapshotId()));

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 don't think that this is correct. Whether to use the snapshot's timestamp in the log entry should still depend on whether the operation is a rollback or an added snapshot, so this needs to continue to check isAddedSnapshot.

I don't think that this PR should change any logic other than the snapshot used for table metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks ryan for catching this, rollback to an existing snapshot will not reuse its creation timestamp in snapshot log entry totally make senses, as the timestamp in HistoryEntry reflects the time of the change

/** Returns the timestamp in milliseconds of the change. */
long timestampMillis();

metadataLog = metadataLogs.get(2);
assertThat(metadataLog.getField("timestamp"))
.isEqualTo(Instant.ofEpochMilli(currentSnapshot.timestampMillis()));
.isEqualTo(Instant.ofEpochMilli(tableMetadata.lastUpdatedMillis()));

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.

If we make no guarantees, should we just assert that the table metadata snapshot is newer than the current snapshot?

@dramaticlly dramaticlly Nov 8, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks ryan! I think it's reasonable to assume this will be newer than (or equal on same millisecond) the snapshot timestamp.

On top of that, I think is still valuable to assert the timestamp of metadata log against the tableMetadata lastUpdated milliseconds as this was part of implementation in

current.lastUpdatedMillis(), current.metadataFileLocation()));
.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rollback snapshot will use current timestamp in snapshot log
@dramaticlly

Copy link
Copy Markdown
Contributor Author

@rdblue can you take another look at this? Appreciated!

@dramaticlly

Copy link
Copy Markdown
Contributor Author

@rdblue updated per your suggestion, appreciated if you can take another look at this change :)

@RussellSpitzer

Copy link
Copy Markdown
Member

@rdblue Last call, any comments left on this? I'll merge tomorrow if there is no additional feedback

@RussellSpitzer
RussellSpitzer merged commit 615b5a0 into apache:main Jan 8, 2026
@dramaticlly
dramaticlly deleted the timesdtampFollowsSnapshot branch January 8, 2026 17:45
@RussellSpitzer

Copy link
Copy Markdown
Member

Merged, Thanks @dramaticlly for the PR! Thanks @nastra, @stevenzwu and @rdblue for reviewing

@agnes-xinyi-lu

Copy link
Copy Markdown
Contributor

@dramaticlly @RussellSpitzer This change seems to be missing update for spark 4.1 and new commits based on latest master could fail https://github.com/agnes-xinyi-lu/iceberg/actions/runs/20830453226/job/59842992804#step:7:34260

@dramaticlly

Copy link
Copy Markdown
Contributor Author

@dramaticlly @RussellSpitzer This change seems to be missing update for spark 4.1 and new commits based on latest master could fail https://github.com/agnes-xinyi-lu/iceberg/actions/runs/20830453226/job/59842992804#step:7:34260

Thanks @agnes-xinyi-lu for the catch, I just realized this as well. Here's the fix in #15004

talatuyarer pushed a commit to talatuyarer/iceberg that referenced this pull request Apr 1, 2026
cdouglas added a commit to cdouglas/catalog that referenced this pull request Oct 18, 2026
Iceberg 1.12.0 (apache/iceberg#14504) no longer takes a table's
last-updated-ms from a snapshot it adds, and logs main's move to a
snapshot at the snapshot's own time if the same builder added it, else
at last-updated-ms. Replay of an inline delta added each snapshot in a
builder of its own, without the writer's last-updated-ms:

- A commit that only added a snapshot (a staged append) replayed at the
  reader's clock. The next delta stores its snapshots' times relative
  to that, so they drifted too.
- computeDelta expected main's new log entry at the commit's
  last-updated-ms, so on 1.12.0 nearly every append went in full.

Replay now applies the run of table-metadata updates up to a delta's
first manifest update to one builder, pinned to the writer's
last-updated-ms: its new snapshots, numbered after the base's last
sequence number as before, with the refs and the rest. computeDelta
expects main's entry at the time Iceberg logs it: the snapshot's if the
commit added it, else last-updated-ms. design.md (I4, I7) and SPEC_TM.md
describe the rule.

Found by TestInlineDeltaProperties, TestInlineDifferentialProperties
(metadata_log_entries read differently) and TestCatalogFaultProperties
(a staged snapshot's time changed) on the rebase onto 1.12.0.
Regression tests: TestCatalogRegressions.TimesOfAddedSnapshots.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
c-thiel added a commit to lakekeeper/lakekeeper that referenced this pull request Nov 3, 2026
Every commit now stores Lakekeeper's clock, read once per commit attempt, as the table's last-updated-ms, as Iceberg Java does since 1.11 (apache/iceberg#14504). Before, the table took the time of the last snapshot the client added. A client whose clock ran ahead could make the table unwritable for other clients, and a snapshot from such a client on a branch or a staged (WAP) snapshot, followed by any metadata-only commit, stored metadata that no client could load. Snapshot times and the snapshot-log entries of added snapshots keep the client's time; a main rollback or publish is logged at the server clock, as in Java. With the iceberg-rust fork's Java-order validation, a writer whose clock is behind Lakekeeper's commits on any branch and as the only writer on main, as with Java's REST catalog.

A build that fails because of the times answers 400, as Java's reference server does: TimestampAheadOfServerClock when the stored last-updated-ms, the last snapshot-log entry or a new main snapshot-log entry is more than one minute after the server clock, and TimestampBeforeTableHistory when a new main snapshot-log entry is more than one minute before an earlier one. Every other build error keeps 409.

The production checklist asks to keep the clocks of Lakekeeper and its clients synchronized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants