amogh-jahagirdar commented on code in PR #14824:
URL: https://github.com/apache/iceberg/pull/14824#discussion_r2616493379
##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -201,21 +224,36 @@ public boolean hasNext() {
return true;
}
- while (true) {
- if (isDone()) {
- return false;
+ while (!shutdown.get()) {
+ // Check for worker failure
Review Comment:
Minor: Unnecessary comment
##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -137,16 +131,50 @@ public void run() {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
+ failure.compareAndSet(null, new RuntimeException("PlanWorker was
interrupted", e));
Review Comment:
@singhpk234 Are we sure setting the failure is the right thing to do in case
of interruption? The loop condition should already handle the case of exiting
when the thread is interrupted. If we set the failure on interruption, a
consumer thread is going to blow up. I'd think the right thing to do is just
gracefully terminate.
##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -137,16 +131,55 @@ public void run() {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
+ failure.compareAndSet(null, new RuntimeException("PlanWorker was
interrupted", e));
+ shutdown.set(true);
} catch (Exception e) {
- throw new RuntimeException("Worker failed processing planTask", e);
+ failure.compareAndSet(null, new RuntimeException("Worker failed
processing planTask", e));
+ shutdown.set(true);
} finally {
- int remaining = activeWorkers.decrementAndGet();
+ handleWorkerExit();
+ }
+ }
+
+ private void handleWorkerExit() {
Review Comment:
I think we could do better simplification around booleans here and get rid
of hasRemainingWork, and some unneccessary comments:
```
private void handleWorkerExit() {
int remainingActiveWorkers = activeWorkers.decrementAndGet();
boolean isLastWorker = remainingActiveWorkers == 0;
boolean hasWorkLeft =
!planTasks.isEmpty() || !initialFileScanTasks.isEmpty();
boolean isShuttingDown = shutdown.get();
if (isLastWorker && (!hasWorkLeft || isShuttingDown)) {
signalCompletion();
} else if (isLastWorker && hasWorkLeft) {
shutdown.set(true);
failure.compareAndSet(
null,
new IllegalStateException("Workers have exited but there is still
work to be done"));
}
}
```
--
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]