lianetm commented on code in PR #14835:
URL: https://github.com/apache/kafka/pull/14835#discussion_r1406257828


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManager.java:
##########
@@ -417,4 +394,129 @@ private void updateHeartbeatIntervalMs(final long 
heartbeatIntervalMs) {
             this.heartbeatTimer.updateAndReset(heartbeatIntervalMs);
         }
     }
+
+    /**
+     * Builds the heartbeat requests correctly, ensuring that all information 
is sent according to
+     * the protocol, but subsequent requests do not send information which has 
not changed. This
+     * is important to ensure that reconciliation completes succesfully.
+     */
+    static class HeartbeatState {
+        private final SubscriptionState subscriptions;
+        private final MembershipManager membershipManager;
+        private final int rebalanceTimeoutMs;
+
+        // Fields of ConsumerHeartbeatRequest sent in the most recent request
+        private String sentInstanceId;
+        private int sentRebalanceTimeoutMs;
+        private TreeSet<String> sentSubscribedTopicNames;
+        // private String sentSubscribedTopicRegex;
+        private String sentServerAssignor;
+        private TreeSet<String> sentTopicPartitions;
+
+        public HeartbeatState(
+            final SubscriptionState subscriptions,
+            final MembershipManager membershipManager,
+            final int rebalanceTimeoutMs) {
+            this.subscriptions = subscriptions;
+            this.membershipManager = membershipManager;
+            this.rebalanceTimeoutMs = rebalanceTimeoutMs;
+            this.sentInstanceId = null;
+            this.sentRebalanceTimeoutMs = -1;
+            this.sentSubscribedTopicNames = null;
+            this.sentServerAssignor = null;
+            this.sentTopicPartitions = null;
+        }
+
+
+        public void reset() {
+            sentInstanceId = null;
+            sentRebalanceTimeoutMs = -1;
+            sentSubscribedTopicNames = null;
+            sentServerAssignor = null;
+            sentTopicPartitions = null;
+        }
+
+        public ConsumerGroupHeartbeatRequestData buildRequestData() {
+            ConsumerGroupHeartbeatRequestData data = new 
ConsumerGroupHeartbeatRequestData();
+
+            // GroupId - always sent
+            data.setGroupId(membershipManager.groupId());
+
+            // MemberId - always sent, after it has been received from the 
coordinator
+            if (membershipManager.memberId() != null) {

Review Comment:
   we should check for empty string (`memberId` defaults to empty string and is 
then updated when received from the coordinator)



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