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/04 13:00:58 UTC

[GitHub] [kafka] showuon commented on a diff in pull request #12729: KAFKA-14285: Delete quota node in zookeeper when configs are empty

showuon commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1013994799


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -355,18 +355,43 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
    * @param entityName The entityName of the entityType
    * @param configs The config of the entityName
    */
-  def changeConfigs(entityType: String, entityName: String, configs: Properties): Unit = {
+  def changeConfigs(entityType: String, entityName: String, configs: Properties, isUserClientId: Boolean = false): Unit = {
 
     entityType match {
       case ConfigType.Topic => changeTopicConfig(entityName, configs)
       case ConfigType.Client => changeClientIdConfig(entityName, configs)
-      case ConfigType.User => changeUserOrUserClientIdConfig(entityName, configs)
+      case ConfigType.User => changeUserOrUserClientIdConfig(entityName, configs, isUserClientId)
       case ConfigType.Broker => changeBrokerConfig(parseBroker(entityName), configs)
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
   }
 
+  private def tryCleanQuotaNodes(entityType: String, entityName: String, isUserClientId: Boolean = false): Boolean = {
+    val currPath = ConfigEntityZNode.path(entityType, entityName)
+    if (zkClient.getChildren(currPath).isEmpty) {
+      var pathToDelete = currPath
+      if (isUserClientId) {
+        val user = entityName.substring(0, entityName.indexOf("/"))
+        val clientId = entityName.substring(entityName.lastIndexOf("/") + 1)
+        val clientsPath = ConfigEntityZNode.path(ConfigType.User, user + "/" + ConfigType.Client)
+        val clientsChildren = zkClient.getChildren(clientsPath)
+        if (clientsChildren == Seq(clientId)) {
+          pathToDelete = clientsPath
+          val userData = fetchEntityConfig(ConfigType.User, user)
+          val userPath = ConfigEntityZNode.path(ConfigType.User, user)
+          val userChildren = zkClient.getChildren(userPath)
+          if (userData.isEmpty && userChildren == Seq(ConfigType.Client)) {
+            pathToDelete = userPath
+          }
+        }
+      }
+      zkClient.deletePath(pathToDelete)

Review Comment:
   Should we log here about zk node deleted?



##########
core/src/test/scala/unit/kafka/zk/AdminZkClientTest.scala:
##########
@@ -355,4 +358,69 @@ class AdminZkClientTest extends QuorumTestHarness with Logging with RackAwareTes
     val assignment = zkClient.getReplicaAssignmentForTopics(Set("foo"))
     assertEquals(numPartitions, assignment.size)
   }
+
+  @Test
+  def testChangeUserOrUserClientIdConfigWithUserAndClientId(): Unit = {
+    val config = new Properties()
+    config.put(QuotaConfigs.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG, producerByteRate)
+    adminZkClient.changeUserOrUserClientIdConfig("user01/clients/client01", config, isUserClientId = true)
+    var props = zkClient.getEntityConfigs(ConfigType.User, "user01/clients/client01")
+    assertEquals(props.getProperty(QuotaConfigs.PRODUCER_BYTE_RATE_OVERRIDE_CONFIG), producerByteRate)

Review Comment:
   The 1st parameter of assertEquals method should be `expected result`. Same comments also apply to below. 



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -355,18 +355,43 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
    * @param entityName The entityName of the entityType
    * @param configs The config of the entityName
    */
-  def changeConfigs(entityType: String, entityName: String, configs: Properties): Unit = {
+  def changeConfigs(entityType: String, entityName: String, configs: Properties, isUserClientId: Boolean = false): Unit = {

Review Comment:
   Please update the javddoc above.



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