NicoleYWDu commented on code in PR #24071:
URL: https://github.com/apache/kafka/pull/24071#discussion_r4602746561


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorShard.java:
##########
@@ -881,25 +881,37 @@ public CoordinatorResult<TxnOffsetCommitResponseData, 
CoordinatorRecord> commitT
     /**
      * Handles a ListGroups request.
      *
-     * @param statesFilter      The states of the groups we want to list.
-     *                          If empty, all groups are returned with their 
state.
-     *                          If invalid, no groups are returned.
-     * @param typesFilter       The types of the groups we want to list.
-     *                          If empty, all groups are returned with their 
type.
-     *                          If invalid, no groups are returned.
-     * @param committedOffset   A specified committed offset corresponding to 
this shard.
+     * @param statesFilter              The states of the groups we want to 
list.
+     *                                  If empty, all groups are returned with 
their state.
+     *                                  If invalid, no groups are returned.
+     * @param typesFilter               The types of the groups we want to 
list.
+     *                                  If empty, all groups are returned with 
their type.
+     *                                  If invalid, no groups are returned.
+     * @param requireCommittedOffsets   If true, only groups with at least one 
committed
+     *                                  offset are returned.
+     * @param committedOffset           A specified committed offset 
corresponding to this shard.
      * @return A list containing the ListGroupsResponseData.ListedGroup
      */
     public List<ListGroupsResponseData.ListedGroup> listGroups(
         List<String> statesFilter,
         List<String> typesFilter,
+        boolean requireCommittedOffsets,
         long committedOffset
     ) throws ApiException {
 
         Set<String> statesFilterSet = new HashSet<>(statesFilter);
         Set<String> typesFilterSet = new HashSet<>(typesFilter);
 
-        return groupMetadataManager.listGroups(statesFilterSet, 
typesFilterSet, committedOffset);
+        List<ListGroupsResponseData.ListedGroup> groups =
+            groupMetadataManager.listGroups(statesFilterSet, typesFilterSet, 
committedOffset);
+
+        if (!requireCommittedOffsets) {
+            return groups;
+        }
+
+        return groups.stream()
+            .filter(group -> 
offsetMetadataManager.hasCommittedOffsets(group.groupId(), committedOffset))
+            .toList();

Review Comment:
   Thanks, David. Updated `GroupMetadataManager.listGroups` to accept a 
group-ID predicate, applied after the state/type filters and before creating 
the `ListedGroup` objects. This avoids the intermediate list and unnecessary 
response objects.
   
   The shard supplies an offsets check using the same committed offset when the 
option is enabled, and an always-true predicate otherwise, so the offset 
manager is not accessed when the option is disabled.



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