jeffkbkim commented on code in PR #13644: URL: https://github.com/apache/kafka/pull/13644#discussion_r1185332905
########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/generic/GenericGroupMember.java: ########## @@ -0,0 +1,499 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.coordinator.group.generic; + +import org.apache.kafka.common.message.JoinGroupResponseData; +import org.apache.kafka.common.message.SyncGroupResponseData; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * This class encapsulates a generic group member's metadata. + * + * Member metadata contains the following: + * + * Heartbeat metadata: + * 1. negotiated heartbeat session timeout + * 2. timestamp of the latest heartbeat + * + * Protocol metadata: + * 1. the list of supported protocols (ordered by preference) + * 2. the metadata associated with each protocol + * + * In addition, it also contains the following state information: + * + * 1. Awaiting rebalance callback: when the group is in the prepare-rebalance state, + * its rebalance callback will be kept in the metadata if the + * member has sent the join group request + * 2. Awaiting sync callback: when the group is in the awaiting-sync state, its sync callback + * is kept in metadata until the leader provides the group assignment + * and the group transitions to stable + */ +public class GenericGroupMember { + + private static class MemberSummary { + private final String memberId; + private final Optional<String> groupInstanceId; + private final String clientId; + private final String clientHost; + private final byte[] metadata; + private final byte[] assignment; + + public MemberSummary(String memberId, + Optional<String> groupInstanceId, + String clientId, + String clientHost, + byte[] metadata, + byte[] assignment) { + + this.memberId = memberId; + this.groupInstanceId = groupInstanceId; + this.clientId = clientId; + this.clientHost = clientHost; + this.metadata = metadata; + this.assignment = assignment; + } + + public String memberId() { + return memberId; + } + + public Optional<String> getGroupInstanceId() { + return groupInstanceId; + } + + public String clientId() { + return clientId; + } + + public String clientHost() { + return clientHost; + } + + public byte[] metadata() { + return metadata; + } + + public byte[] assignment() { + return assignment; + } + + } + + /** + * The member id. + */ + private final String memberId; + + /** + * The group instance id. + */ + private final Optional<String> groupInstanceId; + + /** + * The client id. + */ + private final String clientId; Review Comment: i removed the final keyword and added a setter method in https://github.com/apache/kafka/pull/13663/files#diff-7ec3bedcac3e1a182a8aed96e4e40f0b5ac3295c90bbc862799b7b57e07f983dR494-R499 as it's only used by the group metadata. should i refactor it here or keep it as is and change it in https://github.com/apache/kafka/pull/13663? ########## group-coordinator/src/main/java/org/apache/kafka/coordinator/group/generic/GenericGroupMember.java: ########## @@ -0,0 +1,499 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.coordinator.group.generic; + +import org.apache.kafka.common.message.JoinGroupResponseData; +import org.apache.kafka.common.message.SyncGroupResponseData; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * This class encapsulates a generic group member's metadata. + * + * Member metadata contains the following: + * + * Heartbeat metadata: + * 1. negotiated heartbeat session timeout + * 2. timestamp of the latest heartbeat + * + * Protocol metadata: + * 1. the list of supported protocols (ordered by preference) + * 2. the metadata associated with each protocol + * + * In addition, it also contains the following state information: + * + * 1. Awaiting rebalance callback: when the group is in the prepare-rebalance state, + * its rebalance callback will be kept in the metadata if the + * member has sent the join group request + * 2. Awaiting sync callback: when the group is in the awaiting-sync state, its sync callback + * is kept in metadata until the leader provides the group assignment + * and the group transitions to stable + */ +public class GenericGroupMember { + + private static class MemberSummary { + private final String memberId; + private final Optional<String> groupInstanceId; + private final String clientId; + private final String clientHost; + private final byte[] metadata; + private final byte[] assignment; + + public MemberSummary(String memberId, + Optional<String> groupInstanceId, + String clientId, + String clientHost, + byte[] metadata, + byte[] assignment) { + + this.memberId = memberId; + this.groupInstanceId = groupInstanceId; + this.clientId = clientId; + this.clientHost = clientHost; + this.metadata = metadata; + this.assignment = assignment; + } + + public String memberId() { + return memberId; + } + + public Optional<String> getGroupInstanceId() { + return groupInstanceId; + } + + public String clientId() { + return clientId; + } + + public String clientHost() { + return clientHost; + } + + public byte[] metadata() { + return metadata; + } + + public byte[] assignment() { + return assignment; + } + + } + + /** + * The member id. + */ + private final String memberId; + + /** + * The group instance id. + */ + private final Optional<String> groupInstanceId; + + /** + * The client id. + */ + private final String clientId; + + /** + * The client host. + */ + private final String clientHost; + + /** + * The rebalance timeout in milliseconds. + */ + private final int rebalanceTimeoutMs; + + /** + * The session timeout in milliseconds. + */ + private final int sessionTimeoutMs; + + /** + * The protocol type. + */ + private final String protocolType; + + /** + * The list of supported protocols. + */ + private final List<Protocol> supportedProtocols; + + /** + * The assignment stored by the client assignor. + */ + private final byte[] assignment; + + /** + * The callback that is invoked once this member joins the group. + */ + private CompletableFuture<JoinGroupResponseData> awaitingJoinCallback = null; + + /** + * The callback that is invoked once this member completes the sync group phase. + */ + private CompletableFuture<SyncGroupResponseData> awaitingSyncCallback = null; + + /** + * Indicates whether the member is a new member of the group. + */ + private boolean isNew = false; + + /** + * This variable is used to track heartbeat completion through the delayed + * heartbeat purgatory. When scheduling a new heartbeat expiration, we set + * this value to `false`. Upon receiving the heartbeat (or any other event + * indicating the liveness of the client), we set it to `true` so that the + * delayed heartbeat can be completed. + */ + private boolean heartbeatSatisfied = false; + + + public GenericGroupMember( + String memberId, + Optional<String> groupInstanceId, + String clientId, + String clientHost, + int rebalanceTimeoutMs, + int sessionTimeoutMs, + String protocolType, + List<Protocol> supportedProtocols + ) { + this( + memberId, + groupInstanceId, + clientId, + clientHost, + rebalanceTimeoutMs, + sessionTimeoutMs, + protocolType, + supportedProtocols, + new byte[0] Review Comment: thanks for the suggestion! -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org