findepi commented on code in PR #10691: URL: https://github.com/apache/iceberg/pull/10691#discussion_r1685431047
########## core/src/main/java/org/apache/iceberg/util/ParallelIterable.java: ########## @@ -192,4 +228,78 @@ public synchronized T next() { return queue.poll(); } } + + private static class Task<T> implements Supplier<Optional<Task<T>>>, Closeable { + private final Iterable<T> input; + private final ConcurrentLinkedQueue<T> queue; + private final AtomicBoolean closed; + private final int approximateMaxQueueSize; + + private Iterator<T> iterator = null; + + Task( + Iterable<T> input, + ConcurrentLinkedQueue<T> queue, + AtomicBoolean closed, + int approximateMaxQueueSize) { + this.input = Preconditions.checkNotNull(input, "input cannot be null"); + this.queue = Preconditions.checkNotNull(queue, "queue cannot be null"); + this.closed = Preconditions.checkNotNull(closed, "closed cannot be null"); + this.approximateMaxQueueSize = approximateMaxQueueSize; + } + + @Override + public Optional<Task<T>> get() { + try { + if (iterator == null) { Review Comment: Tasks are constructed lazily, when iterating `ParallelIterator#tasks`. Doing `tasks.hasNext()` likely will create a new Task (without returning it). If we init iterator in the Task constructor, we would have Tasks that need closing, but we wouldn't be closing them. See also https://github.com/apache/iceberg/pull/10691#discussion_r1677178824 -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org