Repository navigation
Core: unlink table metadata's last-updated timestamp from snapshot timestamp - #14504
Conversation
… snapshot timestamp
|
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. |
| } | ||
|
|
||
| snapshotLog.add(new SnapshotLogEntry(lastUpdatedMillis, ref.snapshotId())); | ||
| snapshotLog.add(new SnapshotLogEntry(snapshot.timestampMillis(), snapshot.snapshotId())); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
iceberg/api/src/main/java/org/apache/iceberg/HistoryEntry.java
Lines 30 to 31 in c07f2aa
| metadataLog = metadataLogs.get(2); | ||
| assertThat(metadataLog.getField("timestamp")) | ||
| .isEqualTo(Instant.ofEpochMilli(currentSnapshot.timestampMillis())); | ||
| .isEqualTo(Instant.ofEpochMilli(tableMetadata.lastUpdatedMillis())); |
There was a problem hiding this comment.
If we make no guarantees, should we just assert that the table metadata snapshot is newer than the current snapshot?
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
Not sure this matters because it's a test on a single node, but I think we let this drift into the future
Rollback snapshot will use current timestamp in snapshot log
|
@rdblue can you take another look at this? Appreciated! |
|
@rdblue updated per your suggestion, appreciated if you can take another look at this change :) |
|
@rdblue Last call, any comments left on this? I'll merge tomorrow if there is no additional feedback |
|
Merged, Thanks @dramaticlly for the PR! Thanks @nastra, @stevenzwu and @rdblue for reviewing |
|
@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 |
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]>
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.
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-msrepresentThe 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:
iceberg/core/src/main/java/org/apache/iceberg/TableMetadata.java
Line 1258 in f65558e
and set(snapshot)Ref:
iceberg/core/src/main/java/org/apache/iceberg/TableMetadata.java
Line 1317 in f65558e
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
metadata.json