You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/11/30 21:58:41 UTC

[GitHub] [kafka] artemlivshits commented on a diff in pull request #12902: KAFKA-14367; Add `OffsetDelete` to the new `GroupCoordinator` interface

artemlivshits commented on code in PR #12902:
URL: https://github.com/apache/kafka/pull/12902#discussion_r1036399725


##########
core/src/main/scala/kafka/coordinator/group/GroupCoordinatorAdapter.scala:
##########
@@ -0,0 +1,131 @@
+/**
+ * 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 kafka.coordinator.group
+
+import kafka.server.RequestLocal
+import kafka.utils.Implicits.MapExtensionMethods
+import org.apache.kafka.common.TopicPartition
+import org.apache.kafka.common.message.{JoinGroupRequestData, JoinGroupResponseData, OffsetDeleteRequestData, OffsetDeleteResponseData}
+import org.apache.kafka.common.protocol.Errors
+import org.apache.kafka.common.requests.RequestContext
+import org.apache.kafka.common.utils.BufferSupplier
+
+import java.util.concurrent.CompletableFuture
+import scala.collection.mutable
+import scala.jdk.CollectionConverters._
+
+/**
+ * GroupCoordinatorAdapter is a thin wrapper around kafka.coordinator.group.GroupCoordinator
+ * that exposes the new org.apache.kafka.coordinator.group.GroupCoordinator interface.
+ */
+class GroupCoordinatorAdapter(
+  val coordinator: GroupCoordinator
+) extends org.apache.kafka.coordinator.group.GroupCoordinator {
+
+  override def joinGroup(

Review Comment:
   As we starting a fairly new piece of code, can we add JavaDocs for all methods and a little bit more comments in the code?



##########
core/src/main/scala/kafka/coordinator/group/GroupCoordinatorAdapter.scala:
##########
@@ -0,0 +1,131 @@
+/**
+ * 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 kafka.coordinator.group
+
+import kafka.server.RequestLocal
+import kafka.utils.Implicits.MapExtensionMethods
+import org.apache.kafka.common.TopicPartition
+import org.apache.kafka.common.message.{JoinGroupRequestData, JoinGroupResponseData, OffsetDeleteRequestData, OffsetDeleteResponseData}
+import org.apache.kafka.common.protocol.Errors
+import org.apache.kafka.common.requests.RequestContext
+import org.apache.kafka.common.utils.BufferSupplier
+
+import java.util.concurrent.CompletableFuture
+import scala.collection.mutable
+import scala.jdk.CollectionConverters._
+
+/**
+ * GroupCoordinatorAdapter is a thin wrapper around kafka.coordinator.group.GroupCoordinator
+ * that exposes the new org.apache.kafka.coordinator.group.GroupCoordinator interface.
+ */
+class GroupCoordinatorAdapter(
+  val coordinator: GroupCoordinator
+) extends org.apache.kafka.coordinator.group.GroupCoordinator {
+
+  override def joinGroup(
+    context: RequestContext,
+    request: JoinGroupRequestData,
+    bufferSupplier: BufferSupplier
+  ): CompletableFuture[JoinGroupResponseData] = {
+    val future = new CompletableFuture[JoinGroupResponseData]()
+
+    def callback(joinResult: JoinGroupResult): Unit = {
+      future.complete(new JoinGroupResponseData()
+        .setErrorCode(joinResult.error.code)
+        .setGenerationId(joinResult.generationId)
+        .setProtocolType(joinResult.protocolType.orNull)
+        .setProtocolName(joinResult.protocolName.orNull)
+        .setLeader(joinResult.leaderId)
+        .setSkipAssignment(joinResult.skipAssignment)
+        .setMemberId(joinResult.memberId)
+        .setMembers(joinResult.members.asJava)
+      )
+    }
+
+    val groupInstanceId = Option(request.groupInstanceId)
+
+    // Only return MEMBER_ID_REQUIRED error if joinGroupRequest version is >= 4
+    // and groupInstanceId is configured to unknown.
+    val requireKnownMemberId = context.apiVersion >= 4 && groupInstanceId.isEmpty
+
+    val protocols = request.protocols.valuesList.asScala.map { protocol =>
+      (protocol.name, protocol.metadata)
+    }.toList
+
+    val supportSkippingAssignment = context.apiVersion >= 9
+
+    coordinator.handleJoinGroup(
+      request.groupId,
+      request.memberId,
+      groupInstanceId,
+      requireKnownMemberId,
+      supportSkippingAssignment,
+      context.clientId,
+      context.clientAddress.toString,
+      request.rebalanceTimeoutMs,
+      request.sessionTimeoutMs,
+      request.protocolType,
+      protocols,
+      callback,
+      Option(request.reason),
+      RequestLocal(bufferSupplier)
+    )
+
+    future
+  }
+
+  override def deleteOffsets(
+    context: RequestContext,
+    request: OffsetDeleteRequestData,
+    bufferSupplier: BufferSupplier
+  ): CompletableFuture[OffsetDeleteResponseData] = {
+    val future = new CompletableFuture[OffsetDeleteResponseData]()
+
+    val partitions = mutable.ArrayBuffer[TopicPartition]()
+    request.topics.forEach { topic =>
+      topic.partitions.forEach { partition =>
+        partitions += new TopicPartition(topic.name, partition.partitionIndex)
+      }
+    }
+
+    val (groupError, topicPartitionResults) = coordinator.handleDeleteOffsets(
+      request.groupId,
+      partitions,
+      RequestLocal(bufferSupplier)
+    )
+
+    if (groupError != Errors.NONE) {
+      future.completeExceptionally(groupError.exception)
+    } else {
+      val response = new OffsetDeleteResponseData()
+      topicPartitionResults.forKeyValue { (topicPartition, error) =>
+        var topic = response.topics.find(topicPartition.topic)
+        if (topic == null) {
+          topic = new OffsetDeleteResponseData.OffsetDeleteResponseTopic().setName(topicPartition.topic)
+          response.topics.add(topic)
+        }
+        topic.partitions.add(new OffsetDeleteResponseData.OffsetDeleteResponsePartition()
+          .setPartitionIndex(topicPartition.partition)
+          .setErrorCode(error.code))
+      }
+
+      future.complete(response)
+    }
+
+    future

Review Comment:
   Looks like we're moving to a different async model, is there a design doc to read about this?



-- 
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-unsubscribe@kafka.apache.org

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