stevenzwu commented on code in PR #19266:
URL: https://github.com/apache/iceberg/pull/19266#discussion_r4765661076


##########
core/src/test/java/org/apache/iceberg/TestTrackedFileAdapters.java:
##########
@@ -799,14 +799,6 @@ void dataTrackedFileAdapterKeepsPartitionTuple() {
         .isEqualTo(PARTITION);
   }
 
-  @Test
-  void manifestTrackedFileAdapterUnwrapsToOriginalTrackedFile() {

Review Comment:
   Removed with the unwrap check in `wrap()`, since it only covered that path.



##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -77,24 +77,15 @@ static ManifestFile asManifestFile(TrackedFile file) {
     return new TrackedManifestFile(file);
   }
 
-  static TrackedFile asTrackedFile(ManifestFile file) {
-    if (file instanceof TrackedManifestFile wrapper) {
-      return wrapper.file();
-    }
-
-    return forManifestFile().wrap(file);
+  static TrackedFile asTrackedFile(ManifestFile file, long 
parentSnapshotTimestampMicros) {

Review Comment:
   I removed the one-argument version because 
`RootManifestProducer.fromSnapshot` was its only caller. I also dropped the 
`instanceof TrackedManifestFile` unwrap here: that caller only passes plain 
manifests from a pre-v4 manifest list, never a `TrackedManifestFile`. A future 
v4 `appendManifest` wouldn't use it either: the manifest would be rewritten as 
a v4 leaf and appended to the root as a new ADDED entry.



##########
core/src/main/java/org/apache/iceberg/RootManifestProducer.java:
##########
@@ -175,10 +184,15 @@ private static RootMetadata fromSnapshot(TableMetadata 
meta, Snapshot snapshot,
       if (snapshot == null) {
         return null;
       } else if (snapshot.manifestListLocation() != null) {
+        long snapshotTimestampMicros = 
TimeUnit.MILLISECONDS.toMicros(snapshot.timestampMillis());

Review Comment:
   This branch runs when the parent snapshot still has a manifest list, which 
happens in the first commit on a table or branch after a v1-v3 table is 
upgraded to v4. Those manifests have no snapshot timestamp of their own, so 
they're carried into the root with the parent snapshot's timestamp.



##########
core/src/main/java/org/apache/iceberg/TrackingStruct.java:
##########
@@ -52,6 +52,7 @@ class TrackingStruct extends SupportsIndexProjection 
implements Tracking, Serial
           Tracking.SEQUENCE_NUMBER,
           Tracking.FILE_SEQUENCE_NUMBER,
           Tracking.FIRST_ROW_ID,
+          Tracking.SNAPSHOT_TIMESTAMP,

Review Comment:
   The scan-planning projection now includes `snapshot_timestamp` because only 
ADDED and MODIFIED entries inherit a timestamp on read. Without it, an EXISTING 
root entry reads back with a null timestamp: an EXISTING data file would report 
no last-updated timestamp, and an EXISTING leaf manifest fails planning with 
"Invalid snapshot timestamp for committed manifest". 
`TestFilePlanner.rootWithExistingLeafManifest` covers the leaf-manifest case.



##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -77,24 +77,15 @@ static ManifestFile asManifestFile(TrackedFile file) {
     return new TrackedManifestFile(file);
   }
 
-  static TrackedFile asTrackedFile(ManifestFile file) {
-    if (file instanceof TrackedManifestFile wrapper) {
-      return wrapper.file();
-    }
-
-    return forManifestFile().wrap(file);
+  static TrackedFile asTrackedFile(ManifestFile file, long 
parentSnapshotTimestampMicros) {
+    return new ManifestTrackedFile(parentSnapshotTimestampMicros).wrap(file);
   }
 
   /** Returns a reusable adapter from {@link DataFile} to {@link TrackedFile}. 
*/
   static DataTrackedFile forDataFile(Schema tableSchema) {
     return new DataTrackedFile(tableSchema);
   }
 
-  /** Returns a reusable adapter from {@link ManifestFile} to {@link 
TrackedFile}. */
-  static ManifestTrackedFile forManifestFile() {

Review Comment:
   Removed `forManifestFile()` and the no-arg `ManifestTrackedFile` 
constructor. `asTrackedFile(manifest, ts)` was their only production user, so 
the remaining tests call it directly. The constructor now takes a primitive 
`long` since every caller has a real timestamp.



##########
core/src/main/java/org/apache/iceberg/SnapshotProducer.java:
##########
@@ -371,11 +372,13 @@ public Snapshot apply() {
 
     runValidations(parentSnapshot);
 
+    long timestampMillis = snapshotTimestampMillis(parentSnapshot);

Review Comment:
   The commit timestamp is now picked before the manifests are written so the 
root manifest writer can stamp it on entries. For v1-v3 tables nothing else 
changes: `writeManifestList` doesn't take the timestamp, and the snapshot gets 
the same value as before, just picked slightly earlier (before the manifest 
list is written rather than after). It's still strictly later than the parent's 
and still re-picked on every retry, since `apply()` runs per attempt.



##########
core/src/test/java/org/apache/iceberg/TestFilePlanner.java:
##########
@@ -164,6 +165,34 @@ void rootWithMixedDataAndLeafManifests(FileFormat format) 
throws IOException {
         .containsExactlyInAnyOrder(FILE_A, FILE_C, FILE_D);
   }
 
+  @ParameterizedTest
+  @FieldSource("MANIFEST_FORMATS")
+  void rootWithExistingLeafManifest(FileFormat format) throws IOException {

Review Comment:
   This covers the `TrackingStruct.SCAN_TYPE` change. Planning reads the root 
through the scan projection, and an EXISTING entry doesn't inherit a timestamp, 
so its stored one must be projected. Without `Tracking.SNAPSHOT_TIMESTAMP` in 
`SCAN_TYPE`, this test fails with "Invalid snapshot timestamp for committed 
manifest" when the leaf is opened. The other planner tests only write ADDED 
entries, which inherit the root's timestamp, so none of them caught it.



##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -711,26 +698,21 @@ public TrackedFile copyWithStats(Set<Integer> 
requestedColumnIds) {
   /** Adapts a {@link ManifestFile} to {@link TrackedFile}. */
   static class ManifestTrackedFile implements TrackedFile {
     private final WrappedManifestInfo manifestInfo = new WrappedManifestInfo();
-    private final WrappedManifestTracking trackingWrapper = new 
WrappedManifestTracking();
+    private final WrappedManifestTracking trackingWrapper;
     private Tracking tracking;
     private ManifestFile manifest;
     private long recordCount;
     private FileContent contentType;
 
-    ManifestTrackedFile() {}
+    ManifestTrackedFile(long parentSnapshotTimestampMicros) {
+      this.trackingWrapper = new 
WrappedManifestTracking(parentSnapshotTimestampMicros);
+    }
 
     /**
      * Re-points this adapter at {@code newManifest}. Converts the manifest's 
own fields only;
      * write-time tracking updates are applied by the versioned writer.
-     *
-     * <p>Returns the inner {@link TrackedFile} when {@code newManifest} is a 
{@link
-     * TrackedManifestFile}.
      */
     public TrackedFile wrap(ManifestFile newManifest) {
-      if (newManifest instanceof TrackedManifestFile tracked) {

Review Comment:
   Removed this check along with `TrackedManifestFile.file()`, its only caller. 
Nothing reaches `wrap()` with a `TrackedManifestFile`: the first v4 commit 
passes plain manifests from a pre-v4 manifest list, a v4 parent keeps its 
entries as `TrackedFile` from the root, and the only producer of 
`TrackedManifestFile` is `asManifestFile`, which is used for scan planning.



-- 
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