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 2021/08/28 03:48:16 UTC

[GitHub] [kafka] dengziming commented on a change in pull request #11186: KAFKA-13162: Ensure ElectLeaders is properly handled in KRaft

dengziming commented on a change in pull request #11186:
URL: https://github.com/apache/kafka/pull/11186#discussion_r697800147



##########
File path: core/src/main/scala/kafka/server/ControllerApis.scala
##########
@@ -488,6 +488,31 @@ class ControllerApis(val requestChannel: RequestChannel,
     handleRaftRequest(request, response => new DescribeQuorumResponse(response.asInstanceOf[DescribeQuorumResponseData]))
   }
 
+  def handleElectLeaders(request: RequestChannel.Request): Unit = {
+    val electLeadersRequest = request.body[ElectLeadersRequest]
+
+    def sendErrorResponse(exception: Throwable): Unit = {
+      requestHelper.sendResponseMaybeThrottle(request, throttleMs => {
+        electLeadersRequest.getErrorResponse(throttleMs, exception)
+      })
+    }
+
+    if (!authHelper.authorize(request.context, ALTER, CLUSTER, CLUSTER_NAME)) {
+      sendErrorResponse(Errors.CLUSTER_AUTHORIZATION_FAILED.exception)

Review comment:
       Why not call `authHelper.authorizeClusterOperation(request, ALTER)` as other methods, It seems unnecessary to define a `sendErrorResponse` method.

##########
File path: core/src/test/scala/unit/kafka/server/ControllerApisTest.scala
##########
@@ -732,6 +730,79 @@ class ControllerApisTest {
       controllerApis.createPartitions(request, false, _ => Set("foo", "bar")).get().asScala.toSet)
   }
 
+  @Test
+  def testElectLeadersAuthorization(): Unit = {

Review comment:
       Similar question: why not use `createControllerApis().handleElectLeaders` ?




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