Copilot commented on code in PR #22864:
URL: https://github.com/apache/kafka/pull/22864#discussion_r4522919436
##########
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:
`onlyStandbyTasksUpdating()` scans every updating task when they are all
standbys, even when the reader is already in standby mode and no transition is
possible. Calling this helper for every standby addition, resumption, pause, or
removal therefore introduces quadratic work for a batch of standby tasks on the
state updater thread. Check `changelogReader.isRestoringActive()` first to skip
those unnecessary scans without changing the transition logic.
##########
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:
This test can now fail depending on thread scheduling: the updater may
process and pause `task1` before the test submits `task2`. The updating set is
then temporarily empty, so the new transition helper legitimately calls
`enforceRestoreActive()`, violating the later `never()` assertion even though
the implementation is correct. Queue both tasks before starting the updater so
another standby is guaranteed to be present when `task1` is paused.
--
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]