huaxingao commented on code in PR #17754:
URL: https://github.com/apache/iceberg/pull/17754#discussion_r4732622100


##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -977,15 +987,58 @@ protected void validateAddedDVs(
             filterManifestsByPartition(base, conflictDetectionFilter, 
newDeleteManifests),
             ManifestFile::hasAddedFiles);
 
+    List<DeleteFile> concurrentDVs = 
Collections.synchronizedList(Lists.newArrayList());
+
+    // only DVs added by delete operations can be merged
+    Set<Long> mergeableSnapshotIds;
+    if (canMergeConcurrentDVs) {
+      mergeableSnapshotIds =
+          newSnapshotIds.stream()
+              .filter(id -> 
DataOperations.DELETE.equals(base.snapshot(id).operation()))
+              .collect(Collectors.toSet());
+    } else {
+      mergeableSnapshotIds = ImmutableSet.of();
+    }
+
     Tasks.foreach(matchingManifests)
         .stopOnFailure()
         .throwFailureWhenFinished()
         .executeWith(workerPool())
-        .run(manifest -> validateAddedDVs(manifest, conflictDetectionFilter, 
newSnapshotIds));
+        .run(
+            manifest ->
+                validateAddedDVs(
+                    manifest,
+                    conflictDetectionFilter,
+                    newSnapshotIds,
+                    mergeableSnapshotIds,
+                    concurrentDVs));
+
+    if (!concurrentDVs.isEmpty()) {
+      // rows deleted by a merged DV may have been copied into concurrently 
added data files
+      try (CloseableIterator<ManifestEntry<DataFile>> addedDataFiles =
+          addedDataFiles(base, startingSnapshotId, conflictDetectionFilter, 
null, parent)
+              .iterator()) {
+        DeleteFile concurrentDV = concurrentDVs.get(0);
+        ValidationException.check(
+            !addedDataFiles.hasNext(),

Review Comment:
   If any new data file matches the filter, the merge is skipped and the commit 
fails like before. That's safe. Could we add a test where the new data file is 
outside the filter, so the merge still happens? Also, the error message is the 
same "Found concurrently added DV" as before. Could it say the merge was 
skipped because new data files were added?



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