cadonna commented on code in PR #15870:
URL: https://github.com/apache/kafka/pull/15870#discussion_r1591261680


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java:
##########
@@ -602,6 +608,47 @@ private void removeUnusedTaskFromStateUpdater(final TaskId 
taskId) {
         tasks.addPendingTaskToCloseClean(taskId);
     }
 
+    private void addToTasksToClose(final Map<TaskId, 
CompletableFuture<StateUpdater.RemovedTaskResult>> futures,
+                                   final Set<Task> 
tasksToCloseCleanFromStateUpdater,
+                                   final Set<Task> 
tasksToCloseDirtyFromStateUpdater) {
+        iterateAndActOnFuture(futures, removedTaskResult -> {
+            final Task task = removedTaskResult.task();
+            final Optional<RuntimeException> exception = 
removedTaskResult.exception();
+            if (exception.isPresent()) {
+                tasksToCloseDirtyFromStateUpdater.add(task);
+            } else {
+                tasksToCloseCleanFromStateUpdater.add(task);
+            }
+        });
+    }
+
+    private void iterateAndActOnFuture(final Map<TaskId, 
CompletableFuture<StateUpdater.RemovedTaskResult>> futures,
+                                       final 
java.util.function.Consumer<StateUpdater.RemovedTaskResult> action) {
+        for (final Map.Entry<TaskId, 
CompletableFuture<StateUpdater.RemovedTaskResult>> entry : futures.entrySet()) {
+            final TaskId taskId = entry.getKey();
+            final CompletableFuture<StateUpdater.RemovedTaskResult> future = 
entry.getValue();
+            try {
+                final StateUpdater.RemovedTaskResult removedTaskResult = 
waitForFuture(taskId, future);
+                action.accept(removedTaskResult);
+            } catch (final ExecutionException executionException) {
+                log.warn("An exception happened when removing task {} from the 
state updater. The exception will be handled later: ",
+                    taskId, executionException);
+            } catch (final InterruptedException ignored) { }

Review Comment:
   We are quite inconsistent on how we treat `InterruptedException`. In some 
places we ignore them because they should not happen and in others we treat 
them as fatal and throw an `IllegalStateException` because they should not 
happen [1].
   
   [1] 
https://github.com/apache/kafka/blob/b36cf4ef977fb14bc57683630a9f3f3680705550/streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopicManager.java#L597
   



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to