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


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java:
##########
@@ -673,44 +772,11 @@ private void handleRemovedTasksFromStateUpdater() {
         final Set<Task> tasksToCloseDirty = new 
TreeSet<>(Comparator.comparing(Task::id));
 
         for (final Task task : stateUpdater.drainRemovedTasks()) {
-            final TaskId taskId = task.id();
             Set<TopicPartition> inputPartitions;
             if ((inputPartitions = 
tasks.removePendingTaskToRecycle(task.id())) != null) {
-                try {
-                    final Task newTask = task.isActive() ?
-                        convertActiveToStandby((StreamTask) task, 
inputPartitions) :
-                        convertStandbyToActive((StandbyTask) task, 
inputPartitions);
-                    newTask.initializeIfNeeded();
-                    stateUpdater.add(newTask);
-                } catch (final RuntimeException e) {
-                    final String uncleanMessage = String.format("Failed to 
recycle task %s cleanly. " +
-                        "Attempting to handle remaining tasks before 
re-throwing:", taskId);
-                    log.error(uncleanMessage, e);
-
-                    if (task.state() != State.CLOSED) {
-                        tasksToCloseDirty.add(task);
-                    }
-
-                    taskExceptions.putIfAbsent(taskId, e);
-                }
+                recycleTask(task, inputPartitions, tasksToCloseDirty, 
taskExceptions);
             } else if (tasks.removePendingTaskToCloseClean(task.id())) {
-                try {
-                    task.suspend();
-                    task.closeClean();
-                    if (task.isActive()) {
-                        
activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(task.id());
-                    }
-                } catch (final RuntimeException e) {
-                    final String uncleanMessage = String.format("Failed to 
close task %s cleanly. " +
-                        "Attempting to handle remaining tasks before 
re-throwing:", task.id());
-                    log.error(uncleanMessage, e);
-
-                    if (task.state() != State.CLOSED) {
-                        tasksToCloseDirty.add(task);
-                    }
-
-                    taskExceptions.putIfAbsent(task.id(), e);
-                }
+                closeTaskClean(task, tasksToCloseDirty, taskExceptions);

Review Comment:
   I think reducing code duplication makes a lot of sense. However, can we 
postpone this refactorings after we have a running system with state updater?
   I tried to apply your suggestions regarding 
`tryHandleTasksFromStateUpdater()` but I do not like the idea of using a 
boolean to distinguish between removed and restored tasks. I think it would be 
better to merge the queue of restored and removed tasks as I proposed in our 
last discussion.  



-- 
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]

Reply via email to