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/10/10 13:11:50 UTC

[GitHub] [kafka] aglicacha opened a new pull request, #12729: KAFKA-14285: Delete quota node in zookeeper when configs are empty

aglicacha opened a new pull request, #12729:
URL: https://github.com/apache/kafka/pull/12729

   The PR resolve issue KAFKA-14285. After doing changeConfigs, check and clean quota nodes if configs are empty, to avoid infinite increasement of quota nodes in zookeeper
   related PR: https://github.com/apache/kafka/pull/12727
   @showuon 


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1022873007


##########
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:
   Done.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r996423424


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(clientId)) {

Review Comment:
   Done.



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(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.size == 1 && userChildren.head.equals(ConfigType.Client)) {

Review Comment:
   Done.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1022874148


##########
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:
   Done.



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -483,9 +508,19 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
     DynamicConfig.Broker.validate(configs)
   }
 
-  private def changeEntityConfig(rootEntityType: String, fullSanitizedEntityName: String, configs: Properties): Unit = {
+  private def changeEntityConfig(rootEntityType: String, fullSanitizedEntityName: String, configs: Properties, isUserClientId: Boolean = false): Unit = {
     val sanitizedEntityPath = rootEntityType + '/' + fullSanitizedEntityName
-    zkClient.setOrCreateEntityConfigs(rootEntityType, fullSanitizedEntityName, configs)
+    var needUpdateConfigs = true
+    // If the entityType is quota and node is empty, which means the configs are empty and no children left,

Review Comment:
   Done.



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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1344016944

   Thanks for the update. It failed many tests in jdk17, should be infra's issue. Rerunning the tests: https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-12729/7/


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r996423711


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(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.size == 1 && userChildren.head.equals(ConfigType.Client)) {
+              pathToDelete = userPath
+            }
+          }
+        }
+        zkClient.deletePath(pathToDelete)

Review Comment:
   Right. Scenario 2 will happen if the user configs are not empty but clients under the user is empty. I have added test case to cover this scenario. Thank you.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1343708253

   > @aglicacha , there is compile error, could you take a look?
   
   The error was caused by the unnecessary default value of param isUserClientId in method tryCleanQuotaNodes. I have fixed it. Thanks.


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


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

Posted by GitBox <gi...@apache.org>.
soarez commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r993735973


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(clientId)) {

Review Comment:
   ```suggestion
             if (clientsChildren == Seq(clientId)) {
   ```



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(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.size == 1 && userChildren.head.equals(ConfigType.Client)) {
+              pathToDelete = userPath
+            }
+          }
+        }
+        zkClient.deletePath(pathToDelete)

Review Comment:
   Looking at this block of code, there are apparently three different scenarios for the value of `pathToDelete`, from lines:
   
   1. 372 `var pathToDelete = currPath`
   2. 379 `pathToDelete = clientsPath`
   3. 384 `pathToDelete = userPath`
   
    But following through the test cases we only seem to hit two of those. `testChangeConfigsWithUserAndClientId` hits 3. and all the other current tests stick to 1. Should we have an extra test case to cover scenario 2. or, if that scenario should never happen, should this logic be re-structured?



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {
+      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.size == 1 && clientsChildren.head.equals(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.size == 1 && userChildren.head.equals(ConfigType.Client)) {

Review Comment:
   ```suggestion
               if (userData.isEmpty && userChildren == Seq(ConfigType.Client)) {
   ```



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {

Review Comment:
   Should we add a line or two with a comment explaining why we're adding this change here?



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+

Review Comment:
   It seems that the switch/match block above ends up calling `changeEntityConfig` regardless of the entity type. As a final step, `changeEntityConfig` creates a ZK notification. Would it be better to perform the cleanup before the ZK notification is triggered?  



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r996423147


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+
+    if ((ConfigType.Client.equals(entityType) || ConfigType.User.equals(entityType) || ConfigType.Ip.equals(entityType)) && configs.isEmpty) {

Review Comment:
   Yeah, I have added some annotation to explain it.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1038983468


##########
core/src/main/scala/kafka/admin/ConfigCommand.scala:
##########
@@ -133,8 +133,12 @@ object ConfigCommand extends Logging {
     val entityType = entity.root.entityType
     val entityName = entity.fullSanitizedName
     val errorMessage = s"--bootstrap-server option must be specified to update $entityType configs: {add: $configsToBeAdded, delete: $configsToBeDeleted}"
+    var isUserClientId = false
 
     if (entityType == ConfigType.User) {
+      if (entity.child.exists(e => ConfigType.Client.equals(e.entityType))) {

Review Comment:
   Right, thanks for the advice. I have fixed it.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1336432757

   Add some test results with zk data before and after this change: 
   
   test1:
   	operation:
   		1.add quota(producer_byte_rate=1024) for user01, user02, user03
   		2.add quota(producer_byte_rate=1024) for client01, client02, client03
   		3.add quota(producer_byte_rate=1024) for userClient user01/client11, user01/client12, user01/client13
   		4.delete quota(producer_byte_rate) for user01, user02, user03
   		5.delete quota(producer_byte_rate) for client01, client02, client03
   		6.delete quota(producer_byte_rate) for userClient user01/client11, user01/client12, user01/client13
   
   	zk data result(before this change):
   		/config
   		 |-- /users: null
   			  |-- /user01: {"version":1,"config":{}}
   				   |-- /clients: null
   					    |-- /client11: {"version":1,"config":{}}
   					    |-- /client12: {"version":1,"config":{}}
   					    |-- /client13: {"version":1,"config":{}}
   			  |-- /user02: {"version":1,"config":{}}
   			  |-- /user03: {"version":1,"config":{}}
   		 |-- /clients: null
   		      |-- client01: {"version":1,"config":{}}
   	              |-- client02: {"version":1,"config":{}}
   		      |-- client03: {"version":1,"config":{}}
   			
   	zk data result(after this change):
   		/config
   		 |-- /users: null
   		 |-- /clients: null
   		 
   test2:
   	operation:
   		1.add quota(producer_byte_rate=1024) for user01, user02
   		2.add quota(producer_byte_rate=1024) for userClient user01/client01, user02/client02
   		3.delete quota(producer_byte_rate) for userClient user01/client01
   		4.delete quota(producer_byte_rate) for user02
   		
   	zk data result(before this change):
   		/config
   		 |-- /users: null
   			  |-- /user01: {"version":1,"config":{"producer_byte_rate":"1024"}}
   				   |-- /clients: null
   					    |-- /client01: {"version":1,"config":{}}
   			  |-- /user02: {"version":1,"config":{}}
   				   |-- /clients: null
   					    |-- /client02: {"version":1,"config":{"producer_byte_rate":"1024"}}
   		 |-- /clients: null
   	
   	zk data result(after this change):
   		/config
   		 |-- /users: null
   			  |-- /user01: {"version":1,"config":{"producer_byte_rate":"1024"}}
   			  |-- /user02: {"version":1,"config":{}}
   				   |-- /clients: null
   					    |-- /client02: {"version":1,"config":{"producer_byte_rate":"1024"}}
   		 |-- /clients: null
   		 
   test3:
   	operation:
   		1.add quota(producer_byte_rate=1024) for userClient user01/client01, user01/client02	
   		2.delete quota(producer_byte_rate) for userClient user01/client01
   
   	zk data result(before this change):
   		/config
   		 |-- /users: null
   			  |-- /user01: null
   				   |-- /clients: null
   					    |-- /client01: {"version":1,"config":{}}
   					    |-- /client02: {"version":1,"config":{"producer_byte_rate":"1024"}}
   		 |-- /clients: null
   		 
   	zk data result(after this change):
   		/config
   		 |-- /users: null
   			  |-- /user01: null
   				   |-- /clients: null
   					    |-- /client02: {"version":1,"config":{"producer_byte_rate":"1024"}}
   		 |-- /clients: null
   
   All test results are in line with expectations.


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1336433267

   > Thanks for this fix @aglicacha , can you also test this change locally and get the ZK data before and after this change, and add them in the PR description to make sure there is no harmful effect.
   
   I have added some test results in the comment.


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r996422546


##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -365,6 +365,29 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
       case ConfigType.Ip => changeIpConfig(entityName, configs)
       case _ => throw new IllegalArgumentException(s"$entityType is not a known entityType. Should be one of ${ConfigType.all}")
     }
+

Review Comment:
   Agree with that. I have moved the clean logic to method changeEntityConfig before zk notification is triggered.



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


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

Posted by GitBox <gi...@apache.org>.
dengziming commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1032088188


##########
core/src/main/scala/kafka/admin/ConfigCommand.scala:
##########
@@ -133,8 +133,12 @@ object ConfigCommand extends Logging {
     val entityType = entity.root.entityType
     val entityName = entity.fullSanitizedName
     val errorMessage = s"--bootstrap-server option must be specified to update $entityType configs: {add: $configsToBeAdded, delete: $configsToBeDeleted}"
+    var isUserClientId = false
 
     if (entityType == ConfigType.User) {
+      if (entity.child.exists(e => ConfigType.Client.equals(e.entityType))) {

Review Comment:
   I think we can use `isUserClientId = entity.child.exists(e => ConfigType.Client.equals(e.entityType))` directly?



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


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

Posted by GitBox <gi...@apache.org>.
showuon merged PR #12729:
URL: https://github.com/apache/kafka/pull/12729


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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1347975073

   Thanks for the contribution, @aglicacha !


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


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

Posted by GitBox <gi...@apache.org>.
vongosling commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1377220368

   Good catch, after merging the trunks, I wonder which versions have been resolved, and I see that a large number of users are using 1.1.0 :-)


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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1378161208

   This issue will be fixed in v3.4.1, v3.5.0 and later. Thanks.


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1022874575


##########
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 = {

Review Comment:
   Done.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1022873755


##########
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:
   Done.



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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1299420427

   @mimaison @showuon  could you review this, please?


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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #12729:
URL: https://github.com/apache/kafka/pull/12729#discussion_r1014593992


##########
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 = {

Review Comment:
   Could we add some javadoc above this method? And also some inline comments for `isUserClientId` case below, to explain what nodes we're trying to delete for each case. Thanks.



##########
core/src/main/scala/kafka/zk/AdminZkClient.scala:
##########
@@ -483,9 +508,19 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging {
     DynamicConfig.Broker.validate(configs)
   }
 
-  private def changeEntityConfig(rootEntityType: String, fullSanitizedEntityName: String, configs: Properties): Unit = {
+  private def changeEntityConfig(rootEntityType: String, fullSanitizedEntityName: String, configs: Properties, isUserClientId: Boolean = false): Unit = {
     val sanitizedEntityPath = rootEntityType + '/' + fullSanitizedEntityName
-    zkClient.setOrCreateEntityConfigs(rootEntityType, fullSanitizedEntityName, configs)
+    var needUpdateConfigs = true
+    // If the entityType is quota and node is empty, which means the configs are empty and no children left,

Review Comment:
   nit: which means [if] the configs are ....



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


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

Posted by GitBox <gi...@apache.org>.
mimaison commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1300993928

   Sorry for the delay, I'll try to take a look this week.


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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1338855328

   @aglicacha , there is compile error, could you take a look?


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1273969267

   @soarez Ready to review.


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1284844573

   @soarez Ready to review.


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


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

Posted by GitBox <gi...@apache.org>.
aglicacha commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1315409085

   @showuon Thanks for the comments. I have fixed them. Please to review again, thanks.


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


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

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #12729:
URL: https://github.com/apache/kafka/pull/12729#issuecomment-1347970742

   Failed tests are unrelated
   ```
       Build / JDK 11 and Scala 2.13 / kafka.api.PlaintextEndToEndAuthorizationTest.testNoConsumeWithoutDescribeAclViaSubscribe(String).quorum=zk
       Build / JDK 8 and Scala 2.12 / org.apache.kafka.streams.integration.EosIntegrationTest.shouldWriteLatestOffsetsToCheckpointOnShutdown[exactly_once]
       Build / JDK 17 and Scala 2.13 / org.apache.kafka.streams.integration.SmokeTestDriverIntegrationTest.[1] true
   ```


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