You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dramaticlly (via GitHub)" <gi...@apache.org> on 2026/02/24 01:21:24 UTC

[PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

dramaticlly opened a new pull request, #15426:
URL: https://github.com/apache/iceberg/pull/15426

   Currently, executorService is only used in `ManifestGroup::plan`
   https://github.com/apache/iceberg/blob/a97b4ecc4db52ee2b0ddcecd34219275df002876/core/src/main/java/org/apache/iceberg/ManifestGroup.java#L215-L219 But it can also benefit when scanning entries in multiple manifests. 
   
   Also apply defensive copy on entries as ManifestReader reuseContainers across iteration
   
   @stevenzwu @RussellSpitzer 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849176301


##########
core/src/main/java/org/apache/iceberg/ManifestGroup.java:
##########
@@ -222,13 +222,23 @@ public <T extends ScanTask> CloseableIterable<T> plan(CreateTasksFunction<T> cre
   /**
    * Returns an iterable for manifest entries in the set of manifests.
    *
-   * <p>Entries are not copied and it is the caller's responsibility to make defensive copies if
-   * adding these entries to a collection.
+   * <p>When parallel execution is enabled via {@link #planWith(ExecutorService)}, entries are
+   * defensively copied since the underlying {@link ManifestReader} reuses entry objects during
+   * iteration. Otherwise, entries are not copied and it is the caller's responsibility to make
+   * defensive copies if adding these entries to a collection.
    *
    * @return a CloseableIterable of manifest entries.
    */
   public CloseableIterable<ManifestEntry<DataFile>> entries() {
-    return CloseableIterable.concat(entries((manifest, entries) -> entries));
+    if (executorService != null) {
+      // copy entries to avoid object reuse issues when scanning manifests in parallel,
+      // as ManifestReader reuses entry objects during iteration
+      Iterable<CloseableIterable<ManifestEntry<DataFile>>> entryIterables =
+          entries((manifest, entries) -> CloseableIterable.transform(entries, ManifestEntry::copy));

Review Comment:
   why do we need to copy it?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2848051519


##########
core/src/main/java/org/apache/iceberg/ManifestGroup.java:
##########
@@ -222,13 +222,23 @@ public <T extends ScanTask> CloseableIterable<T> plan(CreateTasksFunction<T> cre
   /**
    * Returns an iterable for manifest entries in the set of manifests.
    *
-   * <p>Entries are not copied and it is the caller's responsibility to make defensive copies if
-   * adding these entries to a collection.
+   * <p>When parallel execution is enabled via {@link #planWith(ExecutorService)}, entries are
+   * defensively copied since the underlying {@link ManifestReader} reuses entry objects during
+   * iteration. Otherwise, entries are not copied and it is the caller's responsibility to make
+   * defensive copies if adding these entries to a collection.
    *
    * @return a CloseableIterable of manifest entries.
    */
   public CloseableIterable<ManifestEntry<DataFile>> entries() {
-    return CloseableIterable.concat(entries((manifest, entries) -> entries));
+    if (executorService != null) {
+      // copy entries to avoid object reuse issues when scanning manifests in parallel,
+      // as ManifestReader reuses entry objects during iteration
+      Iterable<CloseableIterable<ManifestEntry<DataFile>>> entryIterables =
+          entries((manifest, entries) -> CloseableIterable.transform(entries, ManifestEntry::copy));

Review Comment:
   I'm a little worried about introducing a sort of hidden "materialize everything" setting. 
   
   We have one internal use where this could come up and we are effectively double copying with this change
   
   ## FindFiles
   
   https://github.com/apache/iceberg/blob/84172252a1f2537549e52b174299cbf715138760/core/src/main/java/org/apache/iceberg/FindFiles.java#L201-L223
   
   So not even counting external users of this library we are already introducing a regression. I'm not saying we shouldn't do this but we should be very careful here to avoid accidentally doubling memory consumption (or greatly increasing consumption) of a downstream consumer.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849250788


##########
core/src/main/java/org/apache/iceberg/ManifestGroup.java:
##########
@@ -222,13 +222,23 @@ public <T extends ScanTask> CloseableIterable<T> plan(CreateTasksFunction<T> cre
   /**
    * Returns an iterable for manifest entries in the set of manifests.
    *
-   * <p>Entries are not copied and it is the caller's responsibility to make defensive copies if
-   * adding these entries to a collection.
+   * <p>When parallel execution is enabled via {@link #planWith(ExecutorService)}, entries are
+   * defensively copied since the underlying {@link ManifestReader} reuses entry objects during
+   * iteration. Otherwise, entries are not copied and it is the caller's responsibility to make
+   * defensive copies if adding these entries to a collection.
    *
    * @return a CloseableIterable of manifest entries.
    */
   public CloseableIterable<ManifestEntry<DataFile>> entries() {
-    return CloseableIterable.concat(entries((manifest, entries) -> entries));
+    if (executorService != null) {
+      // copy entries to avoid object reuse issues when scanning manifests in parallel,
+      // as ManifestReader reuses entry objects during iteration
+      Iterable<CloseableIterable<ManifestEntry<DataFile>>> entryIterables =
+          entries((manifest, entries) -> CloseableIterable.transform(entries, ManifestEntry::copy));

Review Comment:
   Hey Steven, I think this is due to we reuse containers to read manifest entry using ManifestReader, mentioned in comment above as well https://github.com/apache/iceberg/pull/15426#issuecomment-3948664727.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849605821


##########
core/src/main/java/org/apache/iceberg/FindFiles.java:
##########
@@ -208,18 +208,18 @@ public CloseableIterable<DataFile> collect() {
       }
 
       // when snapshot is not null
-      CloseableIterable<ManifestEntry<DataFile>> entries =
-          new ManifestGroup(ops.io(), snapshot.dataManifests(ops.io()))
-              .specsById(ops.current().specsById())
-              .filterData(rowFilter)
-              .filterFiles(fileFilter)
-              .filterPartitions(partitionFilter)
-              .ignoreDeleted()
-              .caseSensitive(caseSensitive)
-              .planWith(executorService)
-              .entries();
-
-      return CloseableIterable.transform(entries, entry -> entry.file().copy(includeColumnStats));
+      return new ManifestGroup(ops.io(), snapshot.dataManifests(ops.io()))

Review Comment:
   I assume this change is required after we fixed the thread pool usage. the transform need to be happened inside the `entries` execution.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2846010033


##########
core/src/test/java/org/apache/iceberg/TestFindFiles.java:
##########
@@ -209,15 +210,20 @@ public void testNoSnapshot() {
 
   @TestTemplate
   public void testPlanWith() {
-    table
-        .newAppend()
-        .appendFile(FILE_A)
-        .appendFile(FILE_B)
-        .appendFile(FILE_C)
-        .appendFile(FILE_D)
-        .commit();
-
-    ExecutorService executorService = Executors.newFixedThreadPool(2);
+    table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+    table.newAppend().appendFile(FILE_C).appendFile(FILE_D).commit();
+    assertThat(table.currentSnapshot().dataManifests(table.io())).hasSize(2);
+
+    AtomicInteger planThreadsIndex = new AtomicInteger(0);
+    ExecutorService executorService =
+        Executors.newFixedThreadPool(

Review Comment:
   Should we consider migrating to `Executors.newVirtualThreadPerTaskExecutor()`?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "stevenzwu (via GitHub)" <gi...@apache.org>.
stevenzwu commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849660175


##########
core/src/main/java/org/apache/iceberg/FindFiles.java:
##########
@@ -208,18 +208,18 @@ public CloseableIterable<DataFile> collect() {
       }
 
       // when snapshot is not null
-      CloseableIterable<ManifestEntry<DataFile>> entries =
-          new ManifestGroup(ops.io(), snapshot.dataManifests(ops.io()))
-              .specsById(ops.current().specsById())
-              .filterData(rowFilter)
-              .filterFiles(fileFilter)
-              .filterPartitions(partitionFilter)
-              .ignoreDeleted()
-              .caseSensitive(caseSensitive)
-              .planWith(executorService)
-              .entries();
-
-      return CloseableIterable.transform(entries, entry -> entry.file().copy(includeColumnStats));
+      return new ManifestGroup(ops.io(), snapshot.dataManifests(ops.io()))

Review Comment:
   nm. this is using the new API.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "RussellSpitzer (via GitHub)" <gi...@apache.org>.
RussellSpitzer commented on PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#issuecomment-3948496906

   Could you elaborate more on the previous behavior, and how you are changing that in this PR? 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#issuecomment-3948664727

   > Could you elaborate more on the previous behavior, and how you are changing that in this PR?
   
   Happy to! Before this change when we scan the manifest entries using ManifestGroup, we will scan manifest sequentially using `CloseableIterable.concat` even when executorService is provided. 
   
   After this change, we now can benefit from using threadpool to scan the manifests if ManifestGroup is created with executorService provided in planWith(). One caveat is that we also need to make defensive copy of entries in parallel scanning as entries are reused across all iterations within a manifest given the reuseContainers in  ManifestReader.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849240473


##########
core/src/main/java/org/apache/iceberg/ManifestGroup.java:
##########
@@ -222,13 +222,23 @@ public <T extends ScanTask> CloseableIterable<T> plan(CreateTasksFunction<T> cre
   /**
    * Returns an iterable for manifest entries in the set of manifests.
    *
-   * <p>Entries are not copied and it is the caller's responsibility to make defensive copies if
-   * adding these entries to a collection.
+   * <p>When parallel execution is enabled via {@link #planWith(ExecutorService)}, entries are
+   * defensively copied since the underlying {@link ManifestReader} reuses entry objects during
+   * iteration. Otherwise, entries are not copied and it is the caller's responsibility to make
+   * defensive copies if adding these entries to a collection.
    *
    * @return a CloseableIterable of manifest entries.
    */
   public CloseableIterable<ManifestEntry<DataFile>> entries() {
-    return CloseableIterable.concat(entries((manifest, entries) -> entries));
+    if (executorService != null) {
+      // copy entries to avoid object reuse issues when scanning manifests in parallel,
+      // as ManifestReader reuses entry objects during iteration
+      Iterable<CloseableIterable<ManifestEntry<DataFile>>> entryIterables =
+          entries((manifest, entries) -> CloseableIterable.transform(entries, ManifestEntry::copy));

Review Comment:
   Thanks Russell, I think you raised a good point as existing consumer of this API might already apply the defensive copy so we dont want to double the memory. I took the stab to follow what's existing https://github.com/apache/iceberg/blob/9534c9b3adc29d127ecc541ce131f49fd72f1980/core/src/main/java/org/apache/iceberg/ManifestGroup.java#L180 is doing and add a new method which takes a function for transform. 
   
   So testManifestGroupEntriesWithParallelExecution() kind of illustrate that if we only need filePath, we can skip defensive copy like how we collect DataFiles in FindFiles::collect



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "dramaticlly (via GitHub)" <gi...@apache.org>.
dramaticlly commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2849204623


##########
core/src/test/java/org/apache/iceberg/TestFindFiles.java:
##########
@@ -209,15 +210,20 @@ public void testNoSnapshot() {
 
   @TestTemplate
   public void testPlanWith() {
-    table
-        .newAppend()
-        .appendFile(FILE_A)
-        .appendFile(FILE_B)
-        .appendFile(FILE_C)
-        .appendFile(FILE_D)
-        .commit();
-
-    ExecutorService executorService = Executors.newFixedThreadPool(2);
+    table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+    table.newAppend().appendFile(FILE_C).appendFile(FILE_D).commit();
+    assertThat(table.currentSnapshot().dataManifests(table.io())).hasSize(2);
+
+    AtomicInteger planThreadsIndex = new AtomicInteger(0);
+    ExecutorService executorService =
+        Executors.newFixedThreadPool(

Review Comment:
   I think we still build against java17, so we can migrate this later once we move to jdk21 as minimal support.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Core: Support parallel execution when scanning entries in ManifestGroup [iceberg]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #15426:
URL: https://github.com/apache/iceberg/pull/15426#discussion_r2846010033


##########
core/src/test/java/org/apache/iceberg/TestFindFiles.java:
##########
@@ -209,15 +210,20 @@ public void testNoSnapshot() {
 
   @TestTemplate
   public void testPlanWith() {
-    table
-        .newAppend()
-        .appendFile(FILE_A)
-        .appendFile(FILE_B)
-        .appendFile(FILE_C)
-        .appendFile(FILE_D)
-        .commit();
-
-    ExecutorService executorService = Executors.newFixedThreadPool(2);
+    table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+    table.newAppend().appendFile(FILE_C).appendFile(FILE_D).commit();
+    assertThat(table.currentSnapshot().dataManifests(table.io())).hasSize(2);
+
+    AtomicInteger planThreadsIndex = new AtomicInteger(0);
+    ExecutorService executorService =
+        Executors.newFixedThreadPool(

Review Comment:
   Should we consider migrating to `Executors.newVirtualThreadPerTaskExecutor()` (jdk21)?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org