lucasbru commented on code in PR #22864:
URL: https://github.com/apache/kafka/pull/22864#discussion_r4531120072


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -574,9 +587,14 @@ private void pauseResumePartitions(final Map<TaskId, Task> 
tasks,
                                        final Set<TopicPartition> 
restoringChangelogs) {
         if (state == ChangelogReaderState.ACTIVE_RESTORING) {
             updatePartitionsByType(tasks, restoringChangelogs, 
TaskType.ACTIVE);
-        }
-        if (state == ChangelogReaderState.STANDBY_UPDATING) {
+        } else {
             updatePartitionsByType(tasks, restoringChangelogs, 
TaskType.STANDBY);
+            // Paused active tasks keep their changelogs registered and 
restoring, so pause them explicitly while
+            // updating standbys.
+            final Set<TopicPartition> activeRestoringChangelogs = 
activeRestoringChangelogs();
+            if (!activeRestoringChangelogs.isEmpty()) {
+                restoreConsumer.pause(activeRestoringChangelogs);
+            }
         }

Review Comment:
   The enum only has these two states, and the `else` predates this PR. Leaving 
as is.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdater.java:
##########
@@ -767,15 +755,17 @@ private void maybeCompleteRestoration(final StreamTask 
task,
                     changelogReader.unregister(changelogPartitions);
                     addToRestoredTasks(task);
                     log.info("Stateful active task " + task.id() + " completed 
restoration");
-                    transitToUpdateStandbysIfOnlyStandbysLeft();
+                    maybeTransitionChangelogReader();
                 } catch (final StreamsException streamsException) {
                     handleStreamsExceptionWithTask(streamsException, 
task.id());
                 }
             }
         }
 
-        private void transitToUpdateStandbysIfOnlyStandbysLeft() {
-            if (onlyStandbyTasksUpdating()) {
+        private void maybeTransitionChangelogReader() {
+            if (updatingTasks.isEmpty() && 
!changelogReader.isRestoringActive()) {
+                changelogReader.enforceRestoreActive();
+            } else if (changelogReader.isRestoringActive() && 
onlyStandbyTasksUpdating()) {

Review Comment:
   Only the state updater thread touches the reader, so the state cannot change 
between the two reads. Leaving as is.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -448,6 +448,15 @@ private Set<TopicPartition> activeRestoringChangelogs() {
             .collect(Collectors.toSet());
     }
 
+    private Set<TopicPartition> activeRestoringChangelogsOf(final Map<TaskId, 
Task> tasks) {
+        return changelogs.values().stream()
+            .filter(metadata -> metadata.changelogState == 
ChangelogState.RESTORING &&
+                metadata.stateManager.taskType() == Task.TaskType.ACTIVE &&
+                tasks.containsKey(metadata.stateManager.taskId()))

Review Comment:
   Already renamed to `activeRestoringChangelogsOf` after the earlier review; 
keeping that name.



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