nicktelford commented on code in PR #16922:
URL: https://github.com/apache/kafka/pull/16922#discussion_r1736196540


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java:
##########
@@ -519,6 +563,33 @@ private void handleTasksPendingInitialization() {
         }
     }
 
+    private void handleInitialTaskReuse(final Map<TaskId, Set<TopicPartition>> 
activeTasksToCreate,
+                                        final Map<TaskId, Set<TopicPartition>> 
standbyTasksToCreate,
+                                        final Map<TaskId, RuntimeException> 
failedTasks) {
+        final Map<Task, Set<TopicPartition>> initialStandbyTasksToRecycle = 
assignInitialTasks(activeTasksToCreate, logPrefix, topologyMetadata, 
changelogReader);
+        final Map<Task, Set<TopicPartition>> initialStandbyTasksToUse = 
assignInitialTasks(standbyTasksToCreate, logPrefix, topologyMetadata, 
changelogReader);
+
+        // if this was the last local thread to receive its assignment, close 
all the remaining Tasks, as they are not needed
+        stateDirectory.closeInitialTasksIfLastAssginedThread();
+
+        // recycle the initial standbys to active, and remove them from the 
set of actives that need to be created
+        if (!initialStandbyTasksToRecycle.isEmpty()) {
+            final Set<Task> tasksToCloseDirty = new HashSet<>();
+            for (final Map.Entry<Task, Set<TopicPartition>> entry : 
initialStandbyTasksToRecycle.entrySet()) {
+                final Task task = entry.getKey();
+                final Set<TopicPartition> inputPartitions = entry.getValue();
+                recycleTaskFromStateUpdater(task, inputPartitions, 
tasksToCloseDirty, failedTasks);
+                activeTasksToCreate.remove(task.id());
+            }
+        }
+
+        // use initial Standbys as real Standby tasks
+        if (!initialStandbyTasksToUse.isEmpty()) {

Review Comment:
   Yeah, this is more about taste than anything. I think it helps to group 
together the following statements and makes it clear that they only have an 
effect when we have some existing standbys. But if you prefer I can remove it.



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