szehon-ho commented on code in PR #6335:
URL: https://github.com/apache/iceberg/pull/6335#discussion_r1258991416


##########
core/src/main/java/org/apache/iceberg/FastAppend.java:
##########
@@ -178,8 +184,25 @@ public Object updateEvent() {
 
   @Override
   protected void cleanUncommitted(Set<ManifestFile> committed) {
-    if (newManifest != null && !committed.contains(newManifest)) {
-      deleteFile(newManifest.path());
+    if (newManifests != null) {
+      // Delete newManifests that have not been committed and clear them from 
the list.
+      // This is needed for manifests cleanup especially in transaction mode, 
for example:
+      //   Transaction txn = beginTransaction(...)
+      //   // Operation succeeds and calls cleanUncommitted'
+      //   txn.newFastAppend().appendFile(...).commit();
+      //   // Some other operations ...
+      //   // Commit fails and needs to clean up newManifests

Review Comment:
   Nit: should this comment be after next one?  (seems comments refer to the 
line above)



##########
core/src/main/java/org/apache/iceberg/FastAppend.java:
##########
@@ -49,8 +51,9 @@ class FastAppend extends SnapshotProducer<AppendFiles> 
implements AppendFiles {
   private final List<DataFile> newFiles = Lists.newArrayList();
   private final List<ManifestFile> appendManifests = Lists.newArrayList();
   private final List<ManifestFile> rewrittenAppendManifests = 
Lists.newArrayList();
-  private ManifestFile newManifest = null;
+  private List<ManifestFile> newManifests = null;
   private boolean hasNewFiles = false;
+  private final long targetSizeBytes;

Review Comment:
   Nit: put the final with the other final vars?



##########
core/src/main/java/org/apache/iceberg/RollingManifestWriter.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+
+/** As opposed to {@link ManifestWriter}, a rolling writer could produce 
multiple manifest file. */

Review Comment:
   Nit file => files



##########
core/src/main/java/org/apache/iceberg/RollingManifestWriter.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.List;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+
+/** As opposed to {@link ManifestWriter}, a rolling writer could produce 
multiple manifest file. */
+abstract class RollingManifestWriter<T extends ContentFile<T>> implements 
FileAppender<T> {

Review Comment:
   Thanks, this definitely looks cleaner. 
   
   Im just not sure what to do with existing hierarchy (ManifestWriter), as 
there are many duplications.  
   
   Did we think about modifying ManifestWriter, to take extra variable 
'targetFileSizeBytes', then trigger tryRollover only in this case.
   
   The problem may be the method manifestFile() in writer?  It should have been 
manifestFiles().  Maybe we can deprecate existing method?
   
   CC @aokolnychyi .



##########
core/src/main/java/org/apache/iceberg/ManifestFiles.java:
##########
@@ -167,6 +167,30 @@ public static ManifestWriter<DataFile> write(
         "Cannot write manifest for table version: " + formatVersion);
   }
 
+  /**
+   * Create a new {@link RollingManifestWriter} for the given format version.
+   *
+   * @param formatVersion a target format version
+   * @param snapshotId a snapshot ID for the manifest entries, or null for an 
inherited ID
+   * @param spec a {@link PartitionSpec}
+   * @param io a {@link FileIO}
+   * @param outputFileFactory a {@link ManifestOutputFileFactory} to generate 
the manifest output
+   *     file
+   * @param targetFileSizeInBytes the target file size for manifest file, and 
will create a new one

Review Comment:
   Nit: i would say, 'the target file size for manifest files' is good enough, 
it's a bit complicated to explain more.
   
   Or if we need, at least fix the file => files.  
   `the target size for manifest files.  This writer will create a new manifest 
file when the current one has reached this size'



##########
core/src/main/java/org/apache/iceberg/FastAppend.java:
##########
@@ -178,8 +184,25 @@ public Object updateEvent() {
 
   @Override
   protected void cleanUncommitted(Set<ManifestFile> committed) {
-    if (newManifest != null && !committed.contains(newManifest)) {
-      deleteFile(newManifest.path());
+    if (newManifests != null) {
+      // Delete newManifests that have not been committed and clear them from 
the list.
+      // This is needed for manifests cleanup especially in transaction mode, 
for example:
+      //   Transaction txn = beginTransaction(...)
+      //   // Operation succeeds and calls cleanUncommitted'

Review Comment:
   Nit: typo (trailing ')?



##########
core/src/main/java/org/apache/iceberg/ManifestFiles.java:
##########
@@ -167,6 +167,30 @@ public static ManifestWriter<DataFile> write(
         "Cannot write manifest for table version: " + formatVersion);
   }
 
+  /**
+   * Create a new {@link RollingManifestWriter} for the given format version.
+   *
+   * @param formatVersion a target format version
+   * @param snapshotId a snapshot ID for the manifest entries, or null for an 
inherited ID
+   * @param spec a {@link PartitionSpec}
+   * @param io a {@link FileIO}
+   * @param outputFileFactory a {@link ManifestOutputFileFactory} to generate 
the manifest output
+   *     file
+   * @param targetFileSizeInBytes the target file size for manifest file, and 
will create a new one
+   *     when reached
+   * @return a rolling manifest writer which could generate multiple manifest 
file

Review Comment:
   Nit: files



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