mjsax commented on code in PR #23969:
URL: https://github.com/apache/kafka/pull/23969#discussion_r4594411135


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1153,11 +1118,23 @@ private static boolean isStateful(
      *        that no role it has been granted accounts for. How far behind 
that state is cannot be measured, because
      *        a member reports an end offset only for a task it is restoring. 
A process with no such task has no
      *        entry.
+     * @param processLoad
+     *        How loaded each process running at least one member is, so that 
the derivation can send work to the

Review Comment:
   > running at least one member
   
   How can a process run zero members? Of course, client side, all 
StreamsThreads could die, leaving the `KafkaStreams` client as "zombie". But if 
all members died, nobody would heartbeat and the whole process would disappear 
GC side, right?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target
+     * standby. Only a task that diverges from its target owner reads it -- to 
rank the copies to promote, and to find
+     * the placement a borrowed migration holds back -- so a derivation of a 
group that has converged never pays for
+     * the walk. The lookup is reachable only through {@link #holdersOf}, so 
every caller sees it built. It lives for

Review Comment:
   > The lookup is reachable only through {@link #holdersOf}, so every caller 
sees it built
   
   Not sure what this means, or what the point of this comment is?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target
+     * standby. Only a task that diverges from its target owner reads it -- to 
rank the copies to promote, and to find
+     * the placement a borrowed migration holds back -- so a derivation of a 
group that has converged never pays for
+     * the walk. The lookup is reachable only through {@link #holdersOf}, so 
every caller sees it built. It lives for
+     * one derivation, on one thread.
+     */
+    static final class TargetStandbyHolders {
+
+        private final Map<String, TasksTuple> targetAssignment;
+        private final SortedMap<String, ConfiguredSubtopology> subtopologies;
+        private Map<TaskId, Set<String>> holders;
+
+        TargetStandbyHolders(
+            final Map<String, TasksTuple> targetAssignment,
+            final SortedMap<String, ConfiguredSubtopology> subtopologies
+        ) {
+            this.targetAssignment = targetAssignment;
+            this.subtopologies = subtopologies;
+        }
+
+        /**
+         * The members the target assignment names as standby holders of the 
task; empty if it names none.
+         */
+        Set<String> holdersOf(final TaskId task) {
+            if (holders == null) {

Review Comment:
   Why don't we compute `holders` upfront in the constructor? This way, we 
don't need to keep `targetAssignment` and `sub-topologies`?
   
   Is this some kind of "lazy computation" optimization? If yes, would be worth 
a comment.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target
+     * standby. Only a task that diverges from its target owner reads it -- to 
rank the copies to promote, and to find
+     * the placement a borrowed migration holds back -- so a derivation of a 
group that has converged never pays for
+     * the walk. The lookup is reachable only through {@link #holdersOf}, so 
every caller sees it built. It lives for
+     * one derivation, on one thread.
+     */
+    static final class TargetStandbyHolders {
+
+        private final Map<String, TasksTuple> targetAssignment;
+        private final SortedMap<String, ConfiguredSubtopology> subtopologies;
+        private Map<TaskId, Set<String>> holders;
+
+        TargetStandbyHolders(
+            final Map<String, TasksTuple> targetAssignment,
+            final SortedMap<String, ConfiguredSubtopology> subtopologies
+        ) {
+            this.targetAssignment = targetAssignment;
+            this.subtopologies = subtopologies;
+        }
+
+        /**
+         * The members the target assignment names as standby holders of the 
task; empty if it names none.
+         */
+        Set<String> holdersOf(final TaskId task) {
+            if (holders == null) {

Review Comment:
   Curious how much this buys us? Do we have numbers in how many refiner() 
runs, we don't compute it with this optimization?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target
+     * standby. Only a task that diverges from its target owner reads it -- to 
rank the copies to promote, and to find

Review Comment:
   > Only a task that diverges from its target owner reads it
   
   Why is his important? This is a helper class, and is should not depend on 
how it's used, and should not describe how it's used itself -- if this is 
important, the caller should explain it, not the callee.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target
+     * standby. Only a task that diverges from its target owner reads it -- to 
rank the copies to promote, and to find
+     * the placement a borrowed migration holds back -- so a derivation of a 
group that has converged never pays for
+     * the walk. The lookup is reachable only through {@link #holdersOf}, so 
every caller sees it built. It lives for

Review Comment:
   > It lives for one derivation, on one thread.
   
   Similar.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1411,6 +1388,40 @@ private record StandbyConflicts(
     ) {
     }
 
+    /**
+     * The members the target assignment names as standby holders of each 
stateful task.
+     *
+     * <p>The lookup is built from the target assignment on the first {@link 
#holdersOf} call, which walks every target

Review Comment:
   > built from the target assignment on the first {@link #holdersOf} call
   
   Yes, this is what the code does -- why do we have this comment? Describing 
what the code does, is not useful -- I can read the code :)
   
   Comments should only explain stuff that is hard to extract from reading the 
code, and explain the _why_, and the _what_ only in rare occasions (the code 
itself is the _what_, no need to repeat in plain English).



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/AssignmentRefinerImpl.java:
##########
@@ -1153,11 +1118,23 @@ private static boolean isStateful(
      *        that no role it has been granted accounts for. How far behind 
that state is cannot be measured, because
      *        a member reports an end offset only for a task it is restoring. 
A process with no such task has no
      *        entry.
+     * @param processLoad
+     *        How loaded each process running at least one member is, so that 
the derivation can send work to the
+     *        process with the most room: the case analysis picks between 
equally good copies to promote, and the

Review Comment:
   > the case analysis picks
   
   We should not describe how this is used... Only the caller know how it's 
used, and this `record` should be agnostic to it's usage... The description 
should only describe what `processLoad` represent. Nothing more.
   
   (It's a weird Claude trait to add comments like this -- I added a rule in my 
CLAUDE.md to it stops doing this...)



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