Skip to content

fix(update): keep snapshot timestamps strictly increasing - #1152

Merged
zhjwpku merged 1 commit into
apache:mainfrom
xndai:xndai/iceberg-cpp/W8
Nov 21, 2026
Merged

zhjwpku merged 1 commit into
apache:mainfrom
xndai:xndai/iceberg-cpp/W8

Conversation

@xndai

@xndai xndai commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

The v4 spec requires a snapshot's timestamp-ms to be strictly greater than its parent's. SnapshotUpdate stamped new snapshots with the current time, so two commits in the same millisecond, or a commit on top of a parent written by a clock running ahead, broke that rule. Those commits would fail once v4 writes and the matching validation (#1070) land.

New snapshots now get max(now, parent.timestamp_ms + 1), where the parent is the head of the target branch. This matches Java's SnapshotProducer.snapshotTimestampMillis from apache/iceberg#16293 (apache/iceberg#16293) and, like Java, applies to every format version. Every snapshot producer, including a non-fast-forward cherry-pick, goes through SnapshotUpdate::Apply, so this is the only place that needs the change.

New SnapshotTimestampTest cases:

  • FirstSnapshotUsesCurrentTime: with no parent, the snapshot gets the current time.
  • SuccessiveCommitsStrictlyIncrease: back-to-back commits on one branch get strictly increasing timestamps.
  • FutureParentGetsParentPlusOne: with main's head one hour in the future, two commits get parent+1, then parent+2.
  • UsesParentOnTargetBranch: a branch whose parent is in the past gets the current time, while main, whose head is in the future, gets parent+1.

A parent in the future acts as a clock that hasn't caught up, so no clock injection point is needed.

Part of #1107.

The v4 spec requires a snapshot's timestamp-ms to be strictly greater
than its parent's. SnapshotUpdate stamped new snapshots with the
current time, so two commits in the same millisecond, or a commit on
top of a parent from a clock running ahead, broke that rule.

New snapshots now get max(now, parent.timestamp_ms + 1), where the
parent is the head of the target branch. This matches Java's
SnapshotProducer.snapshotTimestampMillis (apache/iceberg#16293) and,
like Java, applies to every format version.

Tests cover a first snapshot, back-to-back commits, a parent in the
future, and a branch whose parent differs from main's head.

@zhjwpku zhjwpku left a comment

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.

Works for me. I guess this restriction won't cause any regressions in pre-v4.

@zhjwpku
zhjwpku merged commit e93b327 into apache:main Nov 21, 2026
15 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