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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org