You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "stevenzwu (via GitHub)" <gi...@apache.org> on 2026/05/12 00:09:41 UTC

[PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

stevenzwu opened a new pull request, #16293:
URL: https://github.com/apache/iceberg/pull/16293

   ## Summary
   
   For format version 4 and above, this change makes `SnapshotProducer` produce snapshot timestamps that are strictly greater than the parent snapshot's `timestamp-ms`, using a Lamport-clock style fast-forward when the wall clock has drifted backward.
   
   - Adds `TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS = 4`.
   - In `SnapshotProducer.commit()`, replaces `System.currentTimeMillis()` with `snapshotTimestampMillis(parentSnapshot)`. The new helper returns `clock.millis()` for V1\u2013V3 (and for V4 root snapshots with no parent), and `max(clock.millis(), parentSnapshot.timestampMillis() + 1)` for V4+ with a parent on the target branch. This preserves wall-clock timestamps in the steady state and only fast-forwards by the minimum amount needed when the clock has drifted backward.
   - Adds an `@VisibleForTesting` `setClock(Clock)` hook so the Lamport behavior can be exercised deterministically.
   
   This is a behavior change for V4 only. V1\u2013V3 commits continue to use the wall clock unchanged.
   
   ## Why
   
   The format-v4 row-timestamp feature exposes each manifest entry's `commit_timestamp_ms` as the `_last_updated_timestamp_ms` metadata column. Time-travel and \"latest update\" queries on that column become incoherent if a backward jump in the writer's wall clock produces snapshots whose `timestamp-ms` does not strictly increase with sequence number. Enforcing monotonicity at write time keeps the per-row \"last updated\" timestamp consistent with snapshot order.
   
   The change is also defensive against clock skew between writers in distributed environments: a stale clock that briefly reports a past time no longer rewrites history.
   
   ## Test plan
   
   - [x] `./gradlew :iceberg-core:test --tests org.apache.iceberg.TestSnapshotProducer` (29 tests, 6 skipped for pre-V4 by `assumeThat`, 0 failures)
   - [x] `./gradlew :iceberg-core:spotlessCheck`
   - [ ] CI
   
   New tests in `TestSnapshotProducer`:
   - `testSnapshotTimestampsAreMonotonicallyIncreasing` \u2014 three consecutive V4 appends produce strictly increasing `timestamp-ms`.
   - `testV4LamportClockFastForwardsDriftedClock` \u2014 with the producer's `Clock` pinned 10s in the past, the second V4 snapshot's `timestamp-ms` equals `firstTs + 1`, confirming the fast-forward branch is exercised.
   
   ## Related
   
   A separate PR will propose the corresponding [table spec](../tree/main/format/spec.md) change documenting the monotonic-`timestamp-ms` requirement for V4.
   
   Made with [Cursor](https://cursor.com)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3606408468


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {

Review Comment:
   Specifically this 
   
   ```java
   if (last != null) {
     Preconditions.checkArgument(
         // commits can happen concurrently from different machines.
         // A tolerance helps us avoid failure for small clock skew
         lastUpdatedMillis - last.timestampMillis() >= -ONE_MINUTE,
         "Invalid update timestamp %s: before last snapshot log entry at %s",
         lastUpdatedMillis,
         last.timestampMillis());
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778200655


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {
+    long now = clock.millis();
+    if (base.formatVersion() >= TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS
+        && parentSnapshot != null) {
+      return Math.max(now, parentSnapshot.timestampMillis() + 1);

Review Comment:
   Any reason we can't just produce the monotonic timestamp for older format versions as well? Sure, it's not a spec level guarantee for those and we shouldn't validate on read that it's monotonic for older format versions, but from an implementation perspective I think we can just do it going forward? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778463355


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {
+    long now = clock.millis();
+    if (base.formatVersion() >= TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS
+        && parentSnapshot != null) {
+      return Math.max(now, parentSnapshot.timestampMillis() + 1);

Review Comment:
   I think it's both. I'm less opinionated on the monotinc production for older formats, it just seems to eliminate the portion of the if condition and is still spec compliant, and produces more "expected" timestamps etc. I think validaiton needs to be updated to make sure that any v4 snapshots are monotonic. So both I think, one makes sure that we produce reaosnable values in the Java implementation, and the other is a read-side validation (though since the comparison is done relative to the new v4 snapshot which we guarnateed that its monotonic, maybe it doesn't matter here either).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4210506771


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA, PartitionSpec.unpartitioned(), "location", ImmutableMap.of());

Review Comment:
   Probably need to explicitly pass through version here 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#issuecomment-4747343009

   This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#issuecomment-4686366951

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778469328


##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -276,4 +279,89 @@ public void testWriteManifestsWithInvalidParallelismThrows() {
       executor.shutdownNow();
     }
   }
+

Review Comment:
   Maybe some transaction tests which produce multipel snapshots? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#issuecomment-6046969320

   Merged. Thanks @stevenzwu for the pr and @huaxingao + @danielcweeks for reviewing.
   
   Since this is a good idea and isn't actually tied to the spec change I think it's fine to merge now before the vote is finished although that looks like it's going through easily as well :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778351578


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {

Review Comment:
   I think I somewhat agreee with this. I think the enforcement validation should change but I think we should make sure that comparison is done with lastUpdatedMillis reflecting the actually assigned snapshotTimestampMillis. In essence if parent snapshot was committed with 12:00:00.000, and the current clock is running slow and is at 11:59:57 , and the new snapshot is set to 12:00:01 based on the current logic, we should make sure this comparison is actually done against 12:00:01



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4211266693


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA, PartitionSpec.unpartitioned(), "location", ImmutableMap.of());

Review Comment:
   `format-version` is now passed in the properties map for each version in `V3_AND_BELOW`.



##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {

Review Comment:
   Parameterized on `TestHelpers.V3_AND_BELOW`. 
   
   v1 still uses sequence number 0, and v3 sets row-lineage fields, since those versions do not share one snapshot shape.



##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {

Review Comment:
   Used `TestHelpers.V4_AND_ABOVE` instead of `assumeThat`. 



##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA, PartitionSpec.unpartitioned(), "location", ImmutableMap.of());
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", null, null, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 999L, null, null, null, "file:/s2.avro", null, null, null);
+
+    TableMetadata withChild = TableMetadata.buildFrom(withParent).addSnapshot(child).build();
+    assertThat(withChild.snapshot(2L).timestampMillis()).isEqualTo(999L);
+  }
+
+  @Test
+  public void snapshotTimestampMayBeAheadOfLastUpdatedMillis() {

Review Comment:
   This behavior is not limited to versions below 4, so the test runs on `ALL_VERSIONS`. It is renamed to `snapshotTimestampMayBeAheadOfTableMetadataLastUpdatedMillis` to be more clear on the scenario



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4127795555


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {

Review Comment:
   @RussellSpitzer  The quoted snippet compares `TableMetadata.lastUpdatedMillis` (wall clock) to the snapshot log, not parent→child snapshot `timestamp-ms`. v4 now validates parent→child in `addSnapshot`. I dropped the check you quoted rather than tightening it: snapshot-log entries for new snapshots carry Lamport `timestamp-ms` and are no longer comparable to `last-updated-ms`. 



##########
core/src/main/java/org/apache/iceberg/TableMetadata.java:
##########
@@ -378,15 +379,6 @@ public String toString() {
       }
       last = logEntry;
     }

Review Comment:
   Dropped the `lastUpdatedMillis` vs last snapshot-log `ONE_MINUTE` check that used to sit here.
   
   These are different clocks: `TableMetadata.lastUpdatedMillis` is physical wall clock, while snapshot `timestamp-ms` is a monotonic Lamport clock (`max(now, parent+1)`) copied into the snapshot log for new snapshots. A Lamport fast-forward can put the snapshot log arbitrarily ahead of wall clock, so comparing them would reject a valid commit.
   
   The metadata-log checks remain unchanged; both sides are wall-clock `lastUpdatedMillis` ([L383-L402](https://github.com/apache/iceberg/blob/cead2eaf69932b67402794ac9cb9a1a1c9773035/core/src/main/java/org/apache/iceberg/TableMetadata.java#L383-L402)).



##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {
+    long now = clock.millis();
+    if (base.formatVersion() >= TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS
+        && parentSnapshot != null) {
+      return Math.max(now, parentSnapshot.timestampMillis() + 1);

Review Comment:
   Done in the latest commit: Java always stamps `max(now, parent+1)`. Spec validation remains v4-only in `addSnapshot`.



##########
core/src/test/java/org/apache/iceberg/TestSnapshotProducer.java:
##########
@@ -276,4 +279,89 @@ public void testWriteManifestsWithInvalidParallelismThrows() {
       executor.shutdownNow();
     }
   }
+

Review Comment:
   Added `transactionCommitsProduceMonotonicTimestamps` and `transactionRetryFastForwardsTimestampsPastConflictingSnapshot` (retry after a conflicting snapshot whose timestamp is ahead of the txn's stale clock).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4210495702


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {

Review Comment:
   I would use the "ALL_VERSIONS" test helper with "Assume Version > 4" rather than hardcoding the 4 in here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#issuecomment-6047515725

   thanks @RussellSpitzer @amogh-jahagirdar @huaxingao for the review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778366527


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {
+    long now = clock.millis();
+    if (base.formatVersion() >= TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS
+        && parentSnapshot != null) {
+      return Math.max(now, parentSnapshot.timestampMillis() + 1);

Review Comment:
   Hmm do you think we should do this monotonic production for older formats? or just change the validation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4210498192


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA, PartitionSpec.unpartitioned(), "location", ImmutableMap.of());
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", null, null, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 999L, null, null, null, "file:/s2.avro", null, null, null);
+
+    TableMetadata withChild = TableMetadata.buildFrom(withParent).addSnapshot(child).build();
+    assertThat(withChild.snapshot(2L).timestampMillis()).isEqualTo(999L);
+  }
+
+  @Test
+  public void snapshotTimestampMayBeAheadOfLastUpdatedMillis() {

Review Comment:
   All versions with Version < 4



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4210503094


##########
core/src/test/java/org/apache/iceberg/TestTableMetadata.java:
##########
@@ -2186,4 +2187,60 @@ public void testSetRefRejectsTagForMainBranch() {
             .build();
     assertThat(withTag.ref("tag1").isTag()).isTrue();
   }
+
+  @Test
+  public void addSnapshotRejectsNonMonotonicTimestampForV4() {
+    TableMetadata base =
+        TableMetadata.newTableMetadata(
+            TEST_SCHEMA,
+            PartitionSpec.unpartitioned(),
+            TEST_LOCATION,
+            ImmutableMap.of(TableProperties.FORMAT_VERSION, "4"));
+
+    Snapshot parent =
+        new BaseSnapshot(1, 1L, null, 1_000L, null, null, null, "file:/s1.avro", 0L, 0L, null);
+    TableMetadata withParent = TableMetadata.buildFrom(base).addSnapshot(parent).build();
+
+    Snapshot child =
+        new BaseSnapshot(2, 2L, 1L, 1_000L, null, null, null, "file:/s2.avro", 0L, 0L, null);
+
+    assertThatThrownBy(() -> TableMetadata.buildFrom(withParent).addSnapshot(child))
+        .isInstanceOf(ValidationException.class)
+        .hasMessage("Invalid snapshot timestamp 1000: not after parent snapshot 1 at 1000");
+  }
+
+  @Test
+  public void addSnapshotAllowsNonMonotonicTimestampBeforeV4() {

Review Comment:
   All versions with Versions <4



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4219990753


##########
core/src/main/java/org/apache/iceberg/TableMetadata.java:
##########
@@ -1270,6 +1262,18 @@ public Builder addSnapshot(Snapshot snapshot) {
           snapshot.sequenceNumber(),
           lastSequenceNumber);
 
+      if (formatVersion >= MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS && snapshot.parentId() != null) {
+        Snapshot parent = snapshotsById.get(snapshot.parentId());
+        if (parent != null) {
+          ValidationException.check(
+              snapshot.timestampMillis() > parent.timestampMillis(),
+              "Invalid snapshot timestamp %s: not after parent snapshot %s at %s",

Review Comment:
   Sorry for the delayed review, maybe in a follow on we can include the snapshot ID in the error message, maybe something like 
   
   ```
   "Snapshot %s must have a later timestamp than parent snapshot %s: %s <= %s"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4220986951


##########
core/src/main/java/org/apache/iceberg/TableMetadata.java:
##########
@@ -1270,6 +1262,18 @@ public Builder addSnapshot(Snapshot snapshot) {
           snapshot.sequenceNumber(),
           lastSequenceNumber);
 
+      if (formatVersion >= MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS && snapshot.parentId() != null) {
+        Snapshot parent = snapshotsById.get(snapshot.parentId());
+        if (parent != null) {
+          ValidationException.check(
+              snapshot.timestampMillis() > parent.timestampMillis(),
+              "Invalid snapshot timestamp %s: not after parent snapshot %s at %s",

Review Comment:
   parent snapshot id was already logged. the conflicting committing/child snapshot id wasn't really useful, as it wasn't committed. we can't inspect it from table history.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #16293: Core: ensure snapshot timestamp is monotonically increasing for V4 tables
URL: https://github.com/apache/iceberg/pull/16293


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#issuecomment-5007188159

   LGTM. Please land this together with / after the spec PR [#16294](https://github.com/apache/iceberg/pull/16294/) so v4 enforcement doesn't ship ahead of the ratified spec text.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3606400846


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {

Review Comment:
   I feel a little weird that we have the algorithm here, but the validation in the commit still allows for backwards drift. I would feel a little bit better if we changed the enforcement validation there as well if the format version > 4. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r3778677600


##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -683,6 +685,31 @@ protected ManifestReader<DeleteFile> newDeleteManifestReader(ManifestFile manife
     return ManifestFiles.readDeleteManifest(manifest, ops.io(), ops.current().specsById());
   }
 
+  @VisibleForTesting
+  void setClock(Clock newClock) {
+    this.clock = newClock;
+  }
+
+  /**
+   * Generates the snapshot timestamp in milliseconds.
+   *
+   * <p>For format version 4 and above, this implements the Lamport clock algorithm to guarantee
+   * monotonically increasing snapshot timestamps. For older format versions, this returns the
+   * current wall clock time.
+   *
+   * @param parentSnapshot the parent snapshot on the target branch, or null if there is no parent
+   * @return the snapshot timestamp in milliseconds
+   */
+  private long snapshotTimestampMillis(Snapshot parentSnapshot) {
+    long now = clock.millis();
+    if (base.formatVersion() >= TableMetadata.MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS
+        && parentSnapshot != null) {
+      return Math.max(now, parentSnapshot.timestampMillis() + 1);

Review Comment:
   > it's not a spec level guarantee for those and we shouldn't validate on read that it's monotonic for older format versions, but from an implementation perspective I think we can just do it going forward?
   
   I am good with this. The reference implementation can change to monotonic timestamp for older format versions. we just don't validate it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer merged PR #16293:
URL: https://github.com/apache/iceberg/pull/16293


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: ensure snapshot timestamp is monotonically increasing for V4 tables [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #16293:
URL: https://github.com/apache/iceberg/pull/16293#discussion_r4220986951


##########
core/src/main/java/org/apache/iceberg/TableMetadata.java:
##########
@@ -1270,6 +1262,18 @@ public Builder addSnapshot(Snapshot snapshot) {
           snapshot.sequenceNumber(),
           lastSequenceNumber);
 
+      if (formatVersion >= MIN_FORMAT_VERSION_MONOTONIC_TIMESTAMPS && snapshot.parentId() != null) {
+        Snapshot parent = snapshotsById.get(snapshot.parentId());
+        if (parent != null) {
+          ValidationException.check(
+              snapshot.timestampMillis() > parent.timestampMillis(),
+              "Invalid snapshot timestamp %s: not after parent snapshot %s at %s",

Review Comment:
   parent snapshot id was already included in the error msg. the conflicting committing/child snapshot id wasn't really useful, as it wasn't committed. we can't inspect it from table history.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org