raunaqmorarka commented on code in PR #18540:
URL: https://github.com/apache/iceberg/pull/18540#discussion_r4405685593
##########
core/src/main/java/org/apache/iceberg/util/Tasks.java:
##########
@@ -500,65 +500,62 @@ private static boolean causedByInterruption(Throwable
throwable) {
@SuppressWarnings("checkstyle:CyclomaticComplexity")
private static Collection<Throwable> waitFor(Collection<Future<?>> futures) {
- while (true) {
- int numFinished = 0;
+ try {
+ // block on each unfinished future in turn until all are done
for (Future<?> future : futures) {
- if (future.isDone()) {
- numFinished += 1;
- }
- }
-
- if (numFinished == futures.size()) {
- List<Throwable> uncaught = Lists.newArrayList();
- // all of the futures are done, get any uncaught exceptions
- for (Future<?> future : futures) {
+ if (!future.isDone()) {
try {
future.get();
+ } catch (ExecutionException | CancellationException ignored) {
+ // collected once all futures are done
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for tasks to finish", e);
- } catch (InterruptedException e) {
- LOG.warn("Interrupted while getting future results", e);
- for (Throwable t : uncaught) {
- e.addSuppressed(t);
- }
- Thread.currentThread().interrupt();
- throw new RuntimeException(e);
+ for (Future<?> future : futures) {
+ future.cancel(true);
+ }
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
- } catch (CancellationException e) {
- // ignore cancellations
+ List<Throwable> uncaught = Lists.newArrayList();
+ // all of the futures are done, get any uncaught exceptions
+ for (Future<?> future : futures) {
+ try {
+ future.get();
- } catch (ExecutionException e) {
- Throwable cause = e.getCause();
- if (cause instanceof Error) {
- for (Throwable t : uncaught) {
- cause.addSuppressed(t);
- }
- throw (Error) cause;
- }
+ } catch (InterruptedException e) {
Review Comment:
> Is this reachable now?
Not with Iceberg's own pools. ThreadPools returns JDK FutureTask, whose
get() on a done future never checks for interrupts. But the executor often
belongs to the caller. Tasks.executeWith is public, and scanManifestsWith,
planWith and executeDeleteWith pass a caller's ExecutorService through to it.
Guava's futures, for example from MoreExecutors.listeningDecorator, throw
InterruptedException from get() on a pending interrupt even when done. They
also clear the interrupt status first, and this catch sets it again. An
IllegalStateException would lose that, so I kept the handling and added a
comment saying when it fires.
##########
core/src/main/java/org/apache/iceberg/util/Tasks.java:
##########
@@ -500,65 +500,62 @@ private static boolean causedByInterruption(Throwable
throwable) {
@SuppressWarnings("checkstyle:CyclomaticComplexity")
private static Collection<Throwable> waitFor(Collection<Future<?>> futures) {
- while (true) {
- int numFinished = 0;
+ try {
+ // block on each unfinished future in turn until all are done
for (Future<?> future : futures) {
- if (future.isDone()) {
- numFinished += 1;
- }
- }
-
- if (numFinished == futures.size()) {
- List<Throwable> uncaught = Lists.newArrayList();
- // all of the futures are done, get any uncaught exceptions
- for (Future<?> future : futures) {
+ if (!future.isDone()) {
try {
future.get();
+ } catch (ExecutionException | CancellationException ignored) {
+ // collected once all futures are done
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for tasks to finish", e);
- } catch (InterruptedException e) {
- LOG.warn("Interrupted while getting future results", e);
- for (Throwable t : uncaught) {
- e.addSuppressed(t);
- }
- Thread.currentThread().interrupt();
- throw new RuntimeException(e);
+ for (Future<?> future : futures) {
+ future.cancel(true);
+ }
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
- } catch (CancellationException e) {
- // ignore cancellations
+ List<Throwable> uncaught = Lists.newArrayList();
+ // all of the futures are done, get any uncaught exceptions
+ for (Future<?> future : futures) {
+ try {
+ future.get();
- } catch (ExecutionException e) {
- Throwable cause = e.getCause();
- if (cause instanceof Error) {
- for (Throwable t : uncaught) {
- cause.addSuppressed(t);
- }
- throw (Error) cause;
- }
+ } catch (InterruptedException e) {
Review Comment:
This catch is gone now that waitFor is a single pass. Every interrupt goes
through one handler.
--
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]