singhpk234 commented on code in PR #14824:
URL: https://github.com/apache/iceberg/pull/14824#discussion_r2617420624
##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -137,16 +131,47 @@ 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() {
+ boolean isLastWorker = activeWorkers.decrementAndGet() == 0;
+ boolean hasWorkLeft = !planTasks.isEmpty() ||
!initialFileScanTasks.isEmpty();
+ boolean isShuttingDown = shutdown.get();
+
+ if (isLastWorker && (!hasWorkLeft || isShuttingDown)) {
+ signalCompletion();
+ } else if (isLastWorker && hasWorkLeft) {
+ failure.compareAndSet(
+ null,
+ new IllegalStateException("Workers have exited but there is still
work to be done"));
+ shutdown.set(true);
+ }
+ }
+
+ private void signalCompletion() {
+ try {
+ taskQueue.put(DUMMY_TASK);
Review Comment:
Thats a nice call out i added a utility to use offer and test for seeing if
the workers are done producing incase the consumer blows up due to other
thread, in close() we clear the taskQueue
##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -137,16 +131,47 @@ 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() {
+ boolean isLastWorker = activeWorkers.decrementAndGet() == 0;
+ boolean hasWorkLeft = !planTasks.isEmpty() ||
!initialFileScanTasks.isEmpty();
+ boolean isShuttingDown = shutdown.get();
+
+ if (isLastWorker && (!hasWorkLeft || isShuttingDown)) {
+ signalCompletion();
+ } else if (isLastWorker && hasWorkLeft) {
+ failure.compareAndSet(
+ null,
+ new IllegalStateException("Workers have exited but there is still
work to be done"));
+ shutdown.set(true);
+ }
+ }
+
+ private void signalCompletion() {
+ try {
+ taskQueue.put(DUMMY_TASK);
Review Comment:
Thats a nice call out i added a utility to use offer and test for seeing if
the workers are done producing incase the consumer blows up due to other thread
--
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]