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


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java:
##########
@@ -1265,12 +1298,12 @@ public void 
shouldPauseActiveTaskAndTransitToUpdateStandby() throws Exception {
         verifyExceptionsAndFailedTasks();
         // shutdown ensures that the test does not end before changelog reader 
methods verified below are called
         stateUpdater.shutdown(Duration.ofMinutes(1));
-        verify(changelogReader, times(1)).enforceRestoreActive();
+        verify(changelogReader, times(2)).enforceRestoreActive();
         verify(changelogReader, times(1)).transitToUpdateStandby();
     }
 
     @Test
-    public void shouldPauseStandbyTaskAndNotTransitToRestoreActive() throws 
Exception {
+    public void 
shouldPauseStandbyTaskAndNotTransitToRestoreActiveIfAnotherStandbyIsUpdating() 
throws Exception {

Review Comment:
   Agreed, queueing both tasks before `start()` removes the race.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdater.java:
##########
@@ -767,15 +758,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 (onlyStandbyTasksUpdating() && 
changelogReader.isRestoringActive()) {

Review Comment:
   Agreed, checking `isRestoringActive()` first is cheap and avoids the scan 
when the reader is already in standby mode. (It stops at the first active task, 
so it is not really quadratic, but there is no reason to scan when no 
transition is possible.)



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdater.java:
##########
@@ -448,7 +446,7 @@ private void 
addToExceptionsAndFailedTasksThenRemoveFromPausedTasks(final Except
                 exceptionsAndFailedTasks.add(exceptionAndTask);
                 pausedTasks.remove(exceptionAndTask.task().id());
                 if (exceptionAndTask.task().isActive()) {

Review Comment:
   nit: removing a task from `pausedTasks` does not change `updatingTasks`, so 
this call cannot do anything here (and if it could, a standby would need it as 
much as an active task). I think the whole `if` block can go.



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