abbccdda commented on a change in pull request #9579:
URL: https://github.com/apache/kafka/pull/9579#discussion_r570492431



##########
File path: core/src/main/scala/kafka/server/KafkaApis.scala
##########
@@ -1234,19 +1171,28 @@ class KafkaApis(val requestChannel: RequestChannel,
     // In versions 5 and below, we returned LEADER_NOT_AVAILABLE if a matching 
listener was not found on the leader.
     // From version 6 onwards, we return LISTENER_NOT_FOUND to enable 
diagnosis of configuration errors.
     val errorUnavailableListeners = requestVersion >= 6
-    val topicMetadata =
+    val (topicMetadata, nonExistTopicMetadata) =
       if (authorizedTopics.isEmpty)
-        Seq.empty[MetadataResponseTopic]
-      else {
-        getTopicMetadata(
-          metadataRequest.allowAutoTopicCreation,
-          metadataRequest.isAllTopics,
-          authorizedTopics,
-          request.context.listenerName,
-          errorUnavailableEndpoints,
-          errorUnavailableListeners
-        )
+        (Seq.empty[MetadataResponseTopic], Seq.empty[MetadataResponseTopic])
+      else
+        getTopicMetadata(metadataRequest.isAllTopics, authorizedTopics,
+          request.context.listenerName, errorUnavailableEndpoints, 
errorUnavailableListeners)
+
+    nonExistTopicMetadata.foreach(metadata =>
+      try {
+        // Validate topic name and propagate error if failed
+        Topic.validate(metadata.name())
+      } catch {
+        case e: Exception =>
+          metadata.setErrorCode(Errors.forException(e).code)
       }
+    )
+
+    if (nonExistTopicMetadata.nonEmpty && 
metadataRequest.allowAutoTopicCreation && config.autoCreateTopicsEnable) {
+      val controllerMutationQuota = 
quotas.controllerMutation.newQuotaFor(request, strictSinceVersion = 6)
+      autoTopicCreationManager.createTopics(
+        nonExistTopicMetadata.map(metadata => 
getTopicConfigs(metadata.name())).toSet, controllerMutationQuota)

Review comment:
       I guess we could rely on admin manager to do the validation for us.




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

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


Reply via email to