amogh-jahagirdar commented on code in PR #19187:
URL: https://github.com/apache/iceberg/pull/19187#discussion_r4789615995


##########
core/src/main/java/org/apache/iceberg/ManifestCacheKey.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import java.util.Objects;
+
+/**
+ * Identifies a manifest in a cache by its location and the metadata it 
inherits from the manifest
+ * list it was read from.
+ *
+ * <p>A manifest written by a transaction that has not been committed keeps 
its location when the
+ * transaction retries, but inherits a new sequence number and first row ID, 
so a result that an
+ * earlier attempt cached for it is not valid anymore.
+ */
+final class ManifestCacheKey {

Review Comment:
   I feel like this is a good use case for a `record` type, a lot of the code 
is boilerplate stuff, and it's package private and can also be backported to 
older iceberg versions like 1.11+ that supported JDK16+ (which is what's 
relevant for this fix for row lineage)



##########
core/src/test/java/org/apache/iceberg/TestTransaction.java:
##########
@@ -47,6 +49,148 @@
 
 public class TestTransaction extends TestBase {
 
+  @Test

Review Comment:
   Existing tests already cover reusing cached results for committed manifests, 
and your tests cover not reusing them for uncommitted ones. I think what's not 
covered is the count on that reuse: since the count now resets on every 
attempt, a reused filtered or merged manifest has to be counted again, or 
manifests-replaced drops to 0 on every retried delete or merge. While not 
directly related to this bug, I think it'd be good to add these tests as part 
of this PR
   
   
   ```java
     @Test
     public void testRetryWithCommittedManifestRewrittenByFilter() {
       table.newFastAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
       Snapshot snapshotAB = table.currentSnapshot();
   
       Transaction txn = table.newTransaction();
       txn.newDelete().deleteFile(FILE_B).commit();
       List<ManifestFile> uncommitted = 
txn.table().currentSnapshot().allManifests(table.io());
       assertThat(uncommitted).hasSize(1);
       ManifestFile firstAttempt = uncommitted.get(0);
   
       // the manifest of FILE_A and FILE_B is committed, so the retry reuses 
its rewritten copy
       table.newFastAppend().appendFile(FILE_C).commit();
       txn.commitTransaction();
   
       List<ManifestFile> manifests = 
table.currentSnapshot().allManifests(table.io());
       assertThat(manifests).hasSize(2);
       ManifestFile rewritten = manifests.get(1);
       assertThat(rewritten.path()).isEqualTo(firstAttempt.path());
       
assertThat(rewritten.sequenceNumber()).isEqualTo(table.currentSnapshot().sequenceNumber());
       
assertThat(rewritten.minSequenceNumber()).isEqualTo(snapshotAB.sequenceNumber());
   
       List<ManifestEntry<DataFile>> entries = entries(rewritten);
       assertThat(entries)
           .extracting(entry -> entry.file().location(), ManifestEntry::status)
           .containsExactly(
               tuple(FILE_A.location(), Status.EXISTING), 
tuple(FILE_B.location(), Status.DELETED));
       ManifestEntry<DataFile> entryA = entries.get(0);
       
assertThat(entryA.dataSequenceNumber()).isEqualTo(snapshotAB.sequenceNumber());
       
assertThat(entryA.file().firstRowId()).isEqualTo(snapshotAB.firstRowId());
   
       assertThat(table.currentSnapshot().summary())
           .containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
     }
   
     @Test
     public void testRetryWithCommittedManifestsRewrittenByMerge() {
       table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT, 
"2").commit();
       table.newFastAppend().appendFile(FILE_A).commit();
       Snapshot snapshotA = table.currentSnapshot();
       table.newFastAppend().appendFile(FILE_B).commit();
       Snapshot snapshotB = table.currentSnapshot();
   
       // FILE_D is not in the table, so the delete only merges the committed 
manifests
       Transaction txn = table.newTransaction();
       txn.newDelete().deleteFile(FILE_D).commit();
       List<ManifestFile> uncommitted = 
txn.table().currentSnapshot().allManifests(table.io());
       assertThat(uncommitted).hasSize(1);
       ManifestFile firstAttempt = uncommitted.get(0);
   
       // a commit to another branch advances the sequence number without 
changing main's manifests,
       // so the retry merges the same bin and reuses the merged manifest
       table.manageSnapshots().createBranch("audit").commit();
       table.newFastAppend().appendFile(FILE_C).toBranch("audit").commit();
       txn.commitTransaction();
   
       Snapshot snapshot = table.currentSnapshot();
       List<ManifestFile> manifests = snapshot.allManifests(table.io());
       assertThat(manifests).hasSize(1);
       ManifestFile merged = manifests.get(0);
       assertThat(merged.path()).isEqualTo(firstAttempt.path());
       assertThat(merged.sequenceNumber()).isEqualTo(snapshot.sequenceNumber());
   
       assertThat(entries(merged))
           .extracting(
               entry -> entry.file().location(),
               ManifestEntry::status,
               ManifestEntry::dataSequenceNumber,
               entry -> entry.file().firstRowId())
           .containsExactlyInAnyOrder(
               tuple(
                   FILE_A.location(),
                   Status.EXISTING,
                   snapshotA.sequenceNumber(),
                   snapshotA.firstRowId()),
               tuple(
                   FILE_B.location(),
                   Status.EXISTING,
                   snapshotB.sequenceNumber(),
                   snapshotB.firstRowId()));
   
       
assertThat(snapshot.summary()).containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT,
 "2");
     }
   ```



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