dajac commented on a change in pull request #9318:
URL: https://github.com/apache/kafka/pull/9318#discussion_r498717745



##########
File path: core/src/main/resources/common/message/OffsetCommitKey.json
##########
@@ -0,0 +1,25 @@
+// 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.
+
+{
+  "type": "data",
+  "name": "OffsetCommitKey",
+  "validVersions": "0-2",

Review comment:
       `0-1`?

##########
File path: core/src/main/resources/common/message/OffsetCommitKey.json
##########
@@ -0,0 +1,25 @@
+// 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.
+
+{
+  "type": "data",
+  "name": "OffsetCommitKey",
+  "validVersions": "0-2",
+  "fields": [
+    { "name": "group", "type": "string", "versions": "0-2" },

Review comment:
       `0-1`?

##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -1405,39 +1189,36 @@ object GroupMetadataManager {
       null
     } else {
       val version = buffer.getShort
-      val valueSchema = schemaForGroupValue(version)
-      val value = valueSchema.read(buffer)
-
       if (version >= 0 && version <= 
CURRENT_GROUP_METADATA_VALUE_SCHEMA_VERSION) {
-        val generationId = value.get(GENERATION_KEY).asInstanceOf[Int]
-        val protocolType = value.get(PROTOCOL_TYPE_KEY).asInstanceOf[String]
-        val protocol = value.get(PROTOCOL_KEY).asInstanceOf[String]
-        val leaderId = value.get(LEADER_KEY).asInstanceOf[String]
-        val memberMetadataArray = value.getArray(MEMBERS_KEY)
+        val value = new GroupMetadataValue(new ByteBufferAccessor(buffer), 
version)
+        val generationId = value.generation
+        val protocolType = value.protocolType
+        val protocol = value.protocol
+        val leaderId = value.leader
+        val memberMetadataArray = value.members.asScala
         val initialState = if (memberMetadataArray.isEmpty) Empty else Stable
         val currentStateTimestamp: Option[Long] =
-          if (version >= 2 && value.hasField(CURRENT_STATE_TIMESTAMP_KEY)) {
-            val timestamp = value.getLong(CURRENT_STATE_TIMESTAMP_KEY)
+          if (version >= 2) {
+            val timestamp = value.currentStateTimestamp

Review comment:
       I am not sure if this is worth it but we could avoid checking the 
version by putting `-1` as default value for `currentStateTimestamp` in the 
schema.

##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -1405,39 +1189,36 @@ object GroupMetadataManager {
       null
     } else {
       val version = buffer.getShort
-      val valueSchema = schemaForGroupValue(version)
-      val value = valueSchema.read(buffer)
-
       if (version >= 0 && version <= 
CURRENT_GROUP_METADATA_VALUE_SCHEMA_VERSION) {

Review comment:
       nit: Here we could use `GroupMetadataValue.LOWEST_SUPPORTED_VERSION` and 
`GroupMetadataValue.HIGHEST_SUPPORTED_VERSION`.

##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -1174,15 +1013,11 @@ object GroupMetadataManager {
    * @return key for offset commit message
    */
   def offsetCommitKey(groupId: String, topicPartition: TopicPartition): 
Array[Byte] = {
-    val key = new Struct(CURRENT_OFFSET_KEY_SCHEMA)
-    key.set(OFFSET_KEY_GROUP_FIELD, groupId)
-    key.set(OFFSET_KEY_TOPIC_FIELD, topicPartition.topic)
-    key.set(OFFSET_KEY_PARTITION_FIELD, topicPartition.partition)
-
-    val byteBuffer = ByteBuffer.allocate(2 /* version */ + key.sizeOf)
-    byteBuffer.putShort(CURRENT_OFFSET_KEY_SCHEMA_VERSION)
-    key.writeTo(byteBuffer)
-    byteBuffer.array()
+    serializeMessage(CURRENT_OFFSET_KEY_SCHEMA_VERSION,
+      new OffsetCommitKey()
+        .setGroup(groupId)
+        .setTopic(topicPartition.topic())
+        .setPartition(topicPartition.partition()))

Review comment:
       nit: I think that the parenthesis after `topic` and `partition` could be 
removed in both cases.

##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -998,173 +997,13 @@ object GroupMetadataManager {
   val LoadTimeSensor: String = "GroupPartitionLoadTime"
 
   private val CURRENT_OFFSET_KEY_SCHEMA_VERSION = 1.toShort

Review comment:
       Could we also add a comment for this one like you did for the other? 

##########
File path: 
core/src/main/scala/kafka/coordinator/group/GroupMetadataManager.scala
##########
@@ -1405,39 +1189,36 @@ object GroupMetadataManager {
       null
     } else {
       val version = buffer.getShort
-      val valueSchema = schemaForGroupValue(version)
-      val value = valueSchema.read(buffer)
-
       if (version >= 0 && version <= 
CURRENT_GROUP_METADATA_VALUE_SCHEMA_VERSION) {
-        val generationId = value.get(GENERATION_KEY).asInstanceOf[Int]
-        val protocolType = value.get(PROTOCOL_TYPE_KEY).asInstanceOf[String]
-        val protocol = value.get(PROTOCOL_KEY).asInstanceOf[String]
-        val leaderId = value.get(LEADER_KEY).asInstanceOf[String]
-        val memberMetadataArray = value.getArray(MEMBERS_KEY)
+        val value = new GroupMetadataValue(new ByteBufferAccessor(buffer), 
version)
+        val generationId = value.generation
+        val protocolType = value.protocolType
+        val protocol = value.protocol
+        val leaderId = value.leader
+        val memberMetadataArray = value.members.asScala
         val initialState = if (memberMetadataArray.isEmpty) Empty else Stable
         val currentStateTimestamp: Option[Long] =
-          if (version >= 2 && value.hasField(CURRENT_STATE_TIMESTAMP_KEY)) {
-            val timestamp = value.getLong(CURRENT_STATE_TIMESTAMP_KEY)
+          if (version >= 2) {
+            val timestamp = value.currentStateTimestamp
             if (timestamp == -1) None else Some(timestamp)
           } else None
 
         val members = memberMetadataArray.map { memberMetadataObj =>
-          val memberMetadata = memberMetadataObj.asInstanceOf[Struct]
-          val memberId = memberMetadata.get(MEMBER_ID_KEY).asInstanceOf[String]
+          val memberId = memberMetadataObj.memberId
           val groupInstanceId =
             if (version >= 3)
-              
Some(memberMetadata.get(GROUP_INSTANCE_ID_KEY).asInstanceOf[String])
+              Some(memberMetadataObj.groupInstanceId)

Review comment:
       Same here. We could have `groupInstanceId` be `null` by default in the 
schema.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to