ModernGroup<?> getOrMaybeCreatePersistedGroup(
        String groupId,
        boolean createIfNotExists,
        GroupType groupType
    ) throws GroupIdNotFoundException {
        if (groupType == CONSUMER) {
            return getOrMaybeCreatePersistedConsumerGroup(groupId, createIfNotExists);
        } else if (groupType == SHARE) {
            return getOrMaybeCreatePersistedShareGroup(groupId, createIfNotExists);
        }
        throw new IllegalArgumentException("Invalid group type: " + groupType);
    }
The method should be called on the replay path.
Gets or maybe creates a consumer group and updates the groups map if a new group is created.

@param groupId           The group id.
@param createIfNotExists A boolean indicating whether the group should be
                         created if it does not exist.

@return A ConsumerGroup.
@throws IllegalStateException if the group does not exist and createIfNotExists is false or
                              if the group is not a consumer group.
Package private for testing.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java