Copilot commented on code in PR #22864:
URL: https://github.com/apache/kafka/pull/22864#discussion_r4528099005
##########
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:
`changelogReader.isRestoringActive()` is consulted twice, which can lead to
inconsistent decisions if the reader state can change between the two calls
(even within the same thread if the implementation evolves). Capture the value
once (eg, `final boolean restoringActive =
changelogReader.isRestoringActive();`) and use that for both branches to make
the transition decision atomic and easier to reason about.
##########
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:
Using `else` here treats any non-`ACTIVE_RESTORING` state as if it were
`STANDBY_UPDATING`. If `ChangelogReaderState` ever gains additional states (or
if an unexpected state is possible), this will silently apply standby logic in
the wrong mode. Prefer `else if (state ==
ChangelogReaderState.STANDBY_UPDATING)` (or a `switch`) and either no-op or
throw for unknown states to keep the control flow explicit and safer to evolve.
##########
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:
`activeRestoringChangelogsOf` and its parameter name `tasks` are ambiguous
in this context (this map is specifically the *updating* task set passed to
`restore`). Consider renaming to something like
`activeRestoringChangelogsForUpdatingTasks(final Map<TaskId, Task>
updatingTasks)` to make the invariant being enforced clearer.
--
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]