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


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdater.java:
##########
@@ -632,9 +626,7 @@ private boolean removeUpdatingTask(final TaskId taskId,
             final Task task = updatingTasks.get(taskId);
             prepareUpdatingTaskForRemoval(task, suspendReason);
             updatingTasks.remove(taskId);
-            if (task.isActive()) {
-                transitToUpdateStandbysIfOnlyStandbysLeft();
-            }
+            maybeTransitionChangelogReader();

Review Comment:
   No test covers this call for a standby: if I guard it with `if 
(task.isActive())`, all tests in `DefaultStateUpdaterTest` and 
`StoreChangelogReaderTest` still pass. Removing the last updating standby and 
then resuming a paused standby is the sequence that crashed originally, so 
could we add a test that removes the only updating standby and verifies 
`enforceRestoreActive`? The failure path has 
`shouldRestoreActiveModeAfterLastStandbyTaskFailed`, removal has no equivalent.



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java:
##########
@@ -1399,9 +1432,11 @@ public void shouldIdleWhenAllTasksPaused() throws 
Exception {
     public void shouldResumeStandbyTask() throws Exception {
         final StandbyTask task = standbyTask(TASK_0_0, 
Set.of(TOPIC_PARTITION_A_0)).inState(State.RUNNING).build();
         shouldResumeStatefulTask(task);
+        assertEquals(Optional.empty(), stateUpdater.fatalException());
         // shutdown ensures that the test does not end before changelog reader 
methods verified below are called
         stateUpdater.shutdown(Duration.ofMinutes(1));
         verify(changelogReader, times(2)).transitToUpdateStandby();
+        verify(changelogReader, times(2)).enforceRestoreActive();

Review Comment:
   nit: `shutdown` itself accounts for one of these two calls 
(`failRemainingTasks` goes through the clear-all path, which now calls the 
helper and enforces active mode). So `times(2)` is "pause + shutdown", and the 
comment above reads as if shutdown only synchronizes. Same for the count in 
`shouldPauseActiveTaskAndTransitToUpdateStandby`. Maybe say so in the comment, 
or verify the count before shutdown?



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java:
##########
@@ -1399,9 +1432,11 @@ public void shouldIdleWhenAllTasksPaused() throws 
Exception {
     public void shouldResumeStandbyTask() throws Exception {
         final StandbyTask task = standbyTask(TASK_0_0, 
Set.of(TOPIC_PARTITION_A_0)).inState(State.RUNNING).build();
         shouldResumeStatefulTask(task);
+        assertEquals(Optional.empty(), stateUpdater.fatalException());

Review Comment:
   nit: `resumeTask` adds the task to `updatingTasks` before it calls the 
transition helper, so `verifyUpdatingTasks` can return before the second 
`transitToUpdateStandby` happens and this assertion can run too early. It would 
only catch the old crash if it ran after `shutdown(...)`.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -494,8 +503,9 @@ public Map<TopicPartition, Long> 
logicalChangelogEndOffsets() {
     public long restore(final Map<TaskId, Task> tasks) {
         initializeChangelogs(tasks, registeredChangelogs());
 
-        if (!activeRestoringChangelogs().isEmpty() && state == 
ChangelogReaderState.STANDBY_UPDATING) {
-            throw new IllegalStateException("Should not be in standby updating 
state if there are still un-completed active changelogs");
+        if (!activeRestoringChangelogsOf(tasks).isEmpty() && state == 
ChangelogReaderState.STANDBY_UPDATING) {

Review Comment:
   The PR description says the reader's defensive exception is unchanged, but 
this guard now only counts active changelogs of updating tasks, and 
`pauseResumePartitions` below now pauses active restoring changelogs in standby 
mode. That is the part that fixes paused active tasks, so I would mention it in 
the description, together with the new reader test. The test section also looks 
stale: it says 87 tests and only runs `DefaultStateUpdaterTest`, but the file 
has 100 tests now and `StoreChangelogReaderTest` is not covered by the command.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -574,9 +584,12 @@ 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);
+            final Set<TopicPartition> activeRestoringChangelogs = 
activeRestoringChangelogs();
+            if (!activeRestoringChangelogs.isEmpty()) {
+                restoreConsumer.pause(activeRestoringChangelogs);

Review Comment:
   nit: a one-line comment on why active changelogs can still be restoring here 
would help. Paused active tasks keep their changelogs registered, so they have 
to be paused explicitly in standby mode. Without it this looks redundant with 
the pause in `transitToUpdateStandby`.



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