timothyw553 commented on code in PR #18820:
URL: https://github.com/apache/iceberg/pull/18820#discussion_r4721971715


##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -230,6 +229,8 @@ List<ManifestFile> filterManifests(Schema tableSchema, 
List<ManifestFile> manife
               filtered[index] = manifest;
             });
 
+    deleteFiles.addAll(deletedFiles(filtered));

Review Comment:
   moving `deleteFiles.addAll(...)` after the worker loop means later duplicate 
entries in the same manifest no longer see earlier deletions. if the first 
entry has stats proving all rows match and the second has no stats, won't this 
throw `Cannot delete file where some, but not all, rows match filter` where it 
used to succeed? should we also check `deletedFiles.contains(file)` in 
`filterManifestWithDeletedFiles` and add a test?
   
   ```diff
                      isDanglingDV
                          || deletePaths.contains(file.location())
                          || deleteFiles.contains(file)
   +                      || deletedFiles.contains(file)
                          || dropPartitions.contains(file.specId(), 
file.partition())
   ```



##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +216,49 @@ public void deleteWithDuplicates() {
         .containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
   }
 
+  @TestTemplate
+  public void deleteDuplicateFilesWithConcurrentDeleteRetry() throws Exception 
{
+    String tableName = "retry-duplicate-delete";
+    File retryTableDir = temp.resolve(tableName).toFile();
+    AtomicBoolean failCommitAfterConcurrentDelete = new AtomicBoolean(false);
+    TestTables.TestTableOperations ops =
+        new TestTables.TestTableOperations(tableName, retryTableDir) {
+          @Override
+          public void commit(TableMetadata base, TableMetadata 
updatedMetadata) {
+            if (base != null && 
failCommitAfterConcurrentDelete.compareAndSet(true, false)) {
+              TestTables.load(retryTableDir, tableName)
+                  .newDelete()
+                  .deleteFromRowFilter(Expressions.alwaysTrue())
+                  .commit();
+              throw new CommitFailedException("Injected concurrent delete");
+            }
+
+            super.commit(base, updatedMetadata);
+          }
+        };
+    this.table =
+        TestTables.create(
+            retryTableDir, tableName, SCHEMA, SPEC, SortOrder.unsorted(), 
formatVersion, ops);
+    table.updateProperties().set("random-snapshot-ids", "true").commit();
+
+    DataFile file =
+        DataFiles.builder(SPEC)
+            .withPath("/path/to/concurrent-delete-duplicate.parquet")
+            .withFileSizeInBytes(10)
+            .withPartitionPath("data_bucket=0")
+            .withRecordCount(1)
+            .build();
+    ManifestFile manifest = 
writeManifestWithName("concurrent-delete-duplicate", file, file);
+    table.newFastAppend().appendManifest(manifest).commit();
+
+    failCommitAfterConcurrentDelete.set(true);
+    table.newDelete().deleteFromRowFilter(Expressions.alwaysTrue()).commit();
+
+    assertThat(table.currentSnapshot().summary())

Review Comment:
   this only checks that the duplicate count is absent after a concurrent 
delete. if we always reported `0` for `DELETED_DUPLICATE_FILES`, wouldn't all 
tests still pass? could we add a test that calls `apply()` then updates the row 
filter before `commit()` and asserts `DELETED_DUPLICATE_FILES` is `"1"`?



##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +216,49 @@ public void deleteWithDuplicates() {
         .containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
   }
 
+  @TestTemplate
+  public void deleteDuplicateFilesWithConcurrentDeleteRetry() throws Exception 
{
+    String tableName = "retry-duplicate-delete";
+    File retryTableDir = temp.resolve(tableName).toFile();
+    AtomicBoolean failCommitAfterConcurrentDelete = new AtomicBoolean(false);
+    TestTables.TestTableOperations ops =
+        new TestTables.TestTableOperations(tableName, retryTableDir) {
+          @Override
+          public void commit(TableMetadata base, TableMetadata 
updatedMetadata) {
+            if (base != null && 
failCommitAfterConcurrentDelete.compareAndSet(true, false)) {
+              TestTables.load(retryTableDir, tableName)
+                  .newDelete()
+                  .deleteFromRowFilter(Expressions.alwaysTrue())
+                  .commit();
+              throw new CommitFailedException("Injected concurrent delete");
+            }
+
+            super.commit(base, updatedMetadata);
+          }
+        };
+    this.table =
+        TestTables.create(
+            retryTableDir, tableName, SCHEMA, SPEC, SortOrder.unsorted(), 
formatVersion, ops);
+    table.updateProperties().set("random-snapshot-ids", "true").commit();
+
+    DataFile file =
+        DataFiles.builder(SPEC)
+            .withPath("/path/to/concurrent-delete-duplicate.parquet")
+            .withFileSizeInBytes(10)
+            .withPartitionPath("data_bucket=0")
+            .withRecordCount(1)
+            .build();
+    ManifestFile manifest = 
writeManifestWithName("concurrent-delete-duplicate", file, file);

Review Comment:
   since there is only one manifest here, multiple workers never update 
`deleteFiles` concurrently. restoring `deleteFiles.add(fileCopy)` inside the 
worker callback still passes all tests, right? could we add a multi-manifest 
test with parallel workers to actually cover the race fix?



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