Copilot commented on code in PR #24166:
URL: https://github.com/apache/kafka/pull/24166#discussion_r4600784653


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsGroup.java:
##########
@@ -643,6 +649,21 @@ public void updateHeartbeatVersion(String memberId, int 
heartbeatVersion) {
         heartbeatVersions.put(memberId, heartbeatVersion);
     }
 
+    /**
+     * Records the current assignment epoch as the one at which the 
coordinator loaded the group.
+     */
+    public void recordAssignmentEpochAtLoad() {
+        assignmentEpochAtLoad = assignmentEpoch();
+    }
+
+    /**
+     * @return Whether the intermediate assignment of the given assignment 
epoch was derived by a previous coordinator,
+     *         which is the case for any epoch up to the one at which the 
coordinator loaded the group.
+     */
+    public boolean wasMintedBeforeLoad(int assignmentEpoch) {
+        return assignmentEpoch <= assignmentEpochAtLoad;
+    }
+
     /**

Review Comment:
   `wasMintedBeforeLoad` uses domain-specific jargon (`minted`) that’s not very 
self-explanatory for readers new to the code. Consider renaming it to something 
more explicit about the comparison, e.g. `isAssignmentEpochAtOrBeforeLoad(...)` 
or `isPreLoadAssignmentEpoch(...)`, to make call sites (like 
`refinedAssignmentForEpoch`) easier to understand.



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsGroup.java:
##########
@@ -239,14 +239,20 @@ public static class DeadlineAndEpoch {
     private final Map<String, MemberTaskOffsets> taskOffsets = new HashMap<>();
 
     /**
-     * The version of the latest streams group heartbeat of each member, keyed 
by member ID, which tells the
-     * {@link AssignmentRefiner} which members report their task offsets. A 
member that is missing has not heartbeated
-     * since the coordinator loaded the group. Like {@link #taskOffsets}, it 
is transient: written in the heartbeat
-     * path, dropped when the member is removed and lost on coordinator 
failover. It is not persisted, so that it can
-     * never outlive the client that sent it.
+     * The version of the latest streams group heartbeat of each member, keyed 
by member ID. A member that is missing
+     * has not heartbeated since the coordinator loaded the group. Like {@link 
#taskOffsets}, it is transient: written
+     * in the heartbeat path, dropped when the member is removed and lost on 
coordinator failover. It is not persisted,
+     * so that it can never outlive the client that sent it.
      */
     private final Map<String, Integer> heartbeatVersions = new HashMap<>();
 
+    /**
+     * The assignment epoch of the group when the coordinator loaded it, or -1 
if the group was created after the load.
+     * The intermediate assignment of this epoch and of earlier ones was 
derived by a previous coordinator and is lost,
+     * while members may already have reconciled to it.
+     */
+    private int assignmentEpochAtLoad = -1;

Review Comment:
   Using `-1` as a sentinel makes the state machine harder to reason about and 
easier to misuse. Consider introducing a named constant (e.g. 
`UNINITIALIZED_ASSIGNMENT_EPOCH = -1`) or using an `OptionalInt` to make the 
‘not loaded / created after load’ state explicit. This would also make it 
clearer what values are valid and reduce future edge-case mistakes.



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