hudi-agent commented on code in PR #19677:
URL: https://github.com/apache/hudi/pull/19677#discussion_r3834729602


##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/config/UnstructuredFileSourceConfig.java:
##########
@@ -122,6 +122,15 @@ public class UnstructuredFileSourceConfig extends 
HoodieConfig {
       .sinceVersion("1.2.0")
       .withDocumentation("Number of characters consecutive chunks overlap 
by.");
 
+  public static final ConfigProperty<Integer> MAX_FILES_PER_BATCH = 
ConfigProperty

Review Comment:
   🤖 Worth noting the two bounds aren't mutually exclusive — `selectNextBatch` 
still honors `sourceLimit` (bytes) at line 201 *and* `maxFilesPerBatch` at line 
198, whichever trips first. The reason a byte-only bound isn't sufficient: it 
never caps the *number* of files, and file count is what drives driver-side 
memory and task count. A folder of many tiny files stays well under any byte 
budget yet can still pull the whole corpus into one sync. So bytes protects 
against a few huge files, file count protects against many small ones — keeping 
both covers both failure modes.



##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/unstructured/UnstructuredFilePathSelector.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.hudi.utilities.sources.helpers.unstructured;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.table.checkpoint.Checkpoint;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.common.util.VisibleForTesting;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.hadoop.fs.HadoopFSUtils;
+import org.apache.hudi.utilities.config.DFSPathSelectorConfig;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.hudi.common.table.checkpoint.CheckpointUtils.createCheckpoint;
+import static org.apache.hudi.common.util.ConfigUtils.getIntWithAltKeys;
+import static org.apache.hudi.common.util.ConfigUtils.getStringWithAltKeys;
+import static 
org.apache.hudi.utilities.config.UnstructuredFileSourceConfig.MAX_FILES_PER_BATCH;
+
+/**
+ * Selects the next batch of files for {@code UnstructuredFileDFSSource}.
+ *
+ * <p>Differs from {@link 
org.apache.hudi.utilities.sources.helpers.DFSPathSelector} in three ways
+ * that matter at scale:
+ *
+ * <ul>
+ *   <li>The batch is bounded by file <em>count</em> as well as bytes. A byte 
budget alone never
+ *       bounds the number of files, and file count is what drives driver 
memory and task count.</li>
+ *   <li>The checkpoint carries {@code (modificationTime, lastPath)} rather 
than a bare timestamp,
+ *       so a group of files sharing one modification time can be split across 
syncs without the
+ *       unread remainder being stranded by a {@code mtime > checkpoint} 
filter. Files arriving in
+ *       one bulk upload routinely share a timestamp, and object stores report 
modification times
+ *       at second granularity.</li>
+ *   <li>Selected files are returned as a list of {@code (path, size, 
modificationTime)} rather
+ *       than one comma-joined string. Paths legitimately contain commas, and 
re-splitting on one
+ *       corrupts them.</li>
+ * </ul>
+ */
+public class UnstructuredFilePathSelector implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+  private static final ObjectMapper MAPPER = new ObjectMapper();
+  private static final List<String> IGNORE_FILE_PREFIXES = Arrays.asList(".", 
"_");
+
+  private final String rootPath;
+  private final int maxFilesPerBatch;
+  private final transient Configuration hadoopConf;
+
+  public UnstructuredFilePathSelector(TypedProperties props, Configuration 
hadoopConf) {
+    this.rootPath = getStringWithAltKeys(props, 
DFSPathSelectorConfig.ROOT_INPUT_PATH);
+    this.maxFilesPerBatch = getIntWithAltKeys(props, MAX_FILES_PER_BATCH);
+    // a non-positive cap would select nothing, leave the checkpoint 
untouched, and stall every
+    // subsequent sync without ever failing
+    ValidationUtils.checkArgument(maxFilesPerBatch > 0,
+        MAX_FILES_PER_BATCH.key() + " must be positive, got " + 
maxFilesPerBatch);
+    this.hadoopConf = hadoopConf;
+  }
+
+  /**
+   * One selected file, carrying what the driver already learned from listing 
so executors do not
+   * have to stat it a second time.
+   */
+  public static class FileEntry implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    public final String path;
+    public final long size;
+    public final long modificationTime;
+
+    public FileEntry(String path, long size, long modificationTime) {
+      this.path = path;
+      this.size = size;
+      this.modificationTime = modificationTime;
+    }
+  }
+
+  /**
+   * The files chosen for one sync and the checkpoint to record if it commits.
+   */
+  public static class Batch {
+    public final List<FileEntry> files;
+    public final Checkpoint checkpoint;
+
+    Batch(List<FileEntry> files, Checkpoint checkpoint) {
+      this.files = files;
+      this.checkpoint = checkpoint;
+    }
+  }
+
+  /**
+   * Position in the source folder: everything at an earlier modification 
time, plus everything at
+   * this modification time whose path sorts at or before {@code lastPath}, 
has been ingested.
+   */
+  @VisibleForTesting
+  static class Position {
+    final long modificationTime;
+    final String lastPath;
+
+    Position(long modificationTime, String lastPath) {
+      this.modificationTime = modificationTime;
+      this.lastPath = lastPath;
+    }
+
+    /** True when this file still needs ingesting. */
+    boolean isAfter(FileStatus file) {
+      if (file.getModificationTime() != modificationTime) {
+        return file.getModificationTime() > modificationTime;
+      }
+      // same timestamp: only the tail of the group beyond lastPath remains. A 
checkpoint written
+      // by the old timestamp-only format has no lastPath, and treating the 
whole group as done
+      // preserves the previous behaviour rather than re-ingesting it on 
upgrade.

Review Comment:
   🤖 nit: `from.isAfter(status)` reads as "the position is after the file," but 
the intent (per the Javadoc) is "this file still needs ingesting." Something 
like `from.isUnread(status)` or `from.needsIngestion(status)` would make the 
call site self-explanatory without requiring the reader to cross-reference the 
doc.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/unstructured/UnstructuredFilePathSelector.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.hudi.utilities.sources.helpers.unstructured;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.table.checkpoint.Checkpoint;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.common.util.VisibleForTesting;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.hadoop.fs.HadoopFSUtils;
+import org.apache.hudi.utilities.config.DFSPathSelectorConfig;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.hudi.common.table.checkpoint.CheckpointUtils.createCheckpoint;
+import static org.apache.hudi.common.util.ConfigUtils.getIntWithAltKeys;
+import static org.apache.hudi.common.util.ConfigUtils.getStringWithAltKeys;
+import static 
org.apache.hudi.utilities.config.UnstructuredFileSourceConfig.MAX_FILES_PER_BATCH;
+
+/**
+ * Selects the next batch of files for {@code UnstructuredFileDFSSource}.
+ *
+ * <p>Differs from {@link 
org.apache.hudi.utilities.sources.helpers.DFSPathSelector} in three ways
+ * that matter at scale:
+ *
+ * <ul>
+ *   <li>The batch is bounded by file <em>count</em> as well as bytes. A byte 
budget alone never
+ *       bounds the number of files, and file count is what drives driver 
memory and task count.</li>
+ *   <li>The checkpoint carries {@code (modificationTime, lastPath)} rather 
than a bare timestamp,
+ *       so a group of files sharing one modification time can be split across 
syncs without the
+ *       unread remainder being stranded by a {@code mtime > checkpoint} 
filter. Files arriving in
+ *       one bulk upload routinely share a timestamp, and object stores report 
modification times
+ *       at second granularity.</li>
+ *   <li>Selected files are returned as a list of {@code (path, size, 
modificationTime)} rather
+ *       than one comma-joined string. Paths legitimately contain commas, and 
re-splitting on one
+ *       corrupts them.</li>
+ * </ul>
+ */
+public class UnstructuredFilePathSelector implements Serializable {

Review Comment:
   🤖 Even setting the file-count feature aside, this class still earns its keep 
— the class javadoc (lines 54-68) lists two other fixes that are independent of 
file-count bounding: selected files are returned as a `List<FileEntry>` instead 
of a comma-joined string (so paths containing commas aren't torn apart), and 
the checkpoint carries `(modificationTime, lastPath)` instead of a bare 
timestamp (so a group of files sharing one mtime can be split across syncs 
without the remainder being stranded by the `mtime > checkpoint` filter). Both 
are real correctness bugs in DFSPathSelector for this source, so the selector 
remains useful regardless of whether the file-count cap stays.



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

Reply via email to