rdblue commented on code in PR #19129:
URL: https://github.com/apache/iceberg/pull/19129#discussion_r4807505407


##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -86,55 +73,67 @@ abstract class MergingSnapshotProducer<ThisT> extends 
SnapshotProducer<ThisT> {
 
   private final String tableName;
   private final SnapshotSummary.Builder summaryBuilder = 
SnapshotSummary.builder();
-  private final ManifestMergeManager<DataFile> mergeManager;
-  private final ManifestFilterManager<DataFile> filterManager;
-  private final ManifestMergeManager<DeleteFile> deleteMergeManager;
-  private final ManifestFilterManager<DeleteFile> deleteFilterManager;
-  private final AtomicInteger dvMergeAttempt = new AtomicInteger(0);
+  private final ProducerActions producer;
+  private final RootManifestProducer rootManifestProducer;
+  private final ManifestListProducer manifestListProducer;
+  private boolean failAnyDelete = false;
+  private boolean failMissingDeletePaths = false;
 
   // update data
-  private final Map<Integer, DataFileSet> newDataFilesBySpec = 
Maps.newHashMap();
-  private Long newDataFilesDataSequenceNumber;
-  private final List<DeleteFile> v2Deletes = Lists.newArrayList();
-  private final Map<String, List<DeleteFile>> dvsByReferencedFile = 
Maps.newLinkedHashMap();
-  private final List<ManifestFile> appendManifests = Lists.newArrayList();
-  private final List<ManifestFile> rewrittenAppendManifests = 
Lists.newArrayList();
-  private final SnapshotSummary.Builder addedDataFilesSummary = 
SnapshotSummary.builder();
-  private final SnapshotSummary.Builder addedDeleteFilesSummary = 
SnapshotSummary.builder();
-  private final SnapshotSummary.Builder appendedManifestsSummary = 
SnapshotSummary.builder();
+  private final List<DataFile> appendedDataFiles = Lists.newArrayList();
   private Expression deleteExpression = Expressions.alwaysFalse();
+  private final List<DeleteFile> addedDeleteFiles = Lists.newArrayList();
+  private boolean deletesDataFiles = false;
+  private boolean deletesDeleteFiles = false;
 
-  // reused v4 producer
-  private RootManifestProducer rootManifestProducer;
-
-  // cache new data manifests after writing
-  private final List<ManifestFile> cachedNewDataManifests = 
Lists.newLinkedList();
-  private boolean hasNewDataFiles = false;
-
-  // cache new manifests for delete files
-  private final List<ManifestFile> cachedNewDeleteManifests = 
Lists.newLinkedList();
-  private boolean hasNewDeleteFiles = false;
+  private final SnapshotSummary.Builder addedDataFilesSummary = 
SnapshotSummary.builder();
+  private final SnapshotSummary.Builder appendedManifestsSummary = 
SnapshotSummary.builder();
 
   private boolean caseSensitive = true;
 
   MergingSnapshotProducer(String tableName, TableOperations ops) {
     super(ops);
     this.tableName = tableName;
-    long targetSizeBytes =
-        ops.current()
-            .propertyAsLong(MANIFEST_TARGET_SIZE_BYTES, 
MANIFEST_TARGET_SIZE_BYTES_DEFAULT);
-    int minCountToMerge =
-        ops.current().propertyAsInt(MANIFEST_MIN_MERGE_COUNT, 
MANIFEST_MIN_MERGE_COUNT_DEFAULT);
-    boolean mergeEnabled =
-        ops.current()
-            .propertyAsBoolean(
-                TableProperties.MANIFEST_MERGE_ENABLED,
-                TableProperties.MANIFEST_MERGE_ENABLED_DEFAULT);
-    this.mergeManager = new DataFileMergeManager(targetSizeBytes, 
minCountToMerge, mergeEnabled);
-    this.filterManager = new DataFileFilterManager();
-    this.deleteMergeManager =
-        new DeleteFileMergeManager(targetSizeBytes, minCountToMerge, 
mergeEnabled);
-    this.deleteFilterManager = new DeleteFileFilterManager();
+    if (ops.current().formatVersion() < 4) {
+      this.manifestListProducer =
+          new ManifestListProducer(tableName, ops, snapshotId(), 
formatVersion());
+      this.rootManifestProducer = null;
+      this.producer = manifestListProducer;
+    } else {
+      this.manifestListProducer = null;
+      this.rootManifestProducer = new RootManifestProducer(ops, snapshotId());
+      this.producer = rootManifestProducer;
+    }
+  }
+
+  @Override
+  public ThisT scanManifestsWith(ExecutorService pool) {
+    Preconditions.checkArgument(pool != null, "Executor service cannot be 
null");
+    if (manifestListProducer != null) {
+      manifestListProducer.scanWith(pool);
+    }
+
+    super.scanManifestsWith(pool);
+    return self();
+  }
+
+  @Override
+  public ThisT writeManifestsWith(ExecutorService pool, int parallelism) {
+    if (manifestListProducer != null) {
+      manifestListProducer.writeWith(pool, parallelism);
+    }
+
+    return self();
+  }
+
+  @Override
+  public ThisT deleteWith(Consumer<String> deleteCallback) {
+    if (manifestListProducer != null) {

Review Comment:
   Good catch. I'll take the suggestion.
   
   The purpose of the failure when setting the delete function twice is 
actually to ensure that user-registered delete functions are not allowed in 
transactions (because the transaction registers its own). In order for this 
issue to cause an actual problem, the caller would have to catch the error 
thrown in `super.deleteWith` and then use the operation anyway, which I think 
is pretty unlikely but the fix is straightforward so it makes sense to just do 
it and not worry.



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