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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to