junrao commented on code in PR #15968:
URL: https://github.com/apache/kafka/pull/15968#discussion_r2072181804


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -396,57 +396,72 @@ class KafkaApis(val requestChannel: RequestChannel,
       }
     }
 
-    val unauthorizedTopicResponses = mutable.Map[TopicPartition, 
PartitionResponse]()
-    val nonExistingTopicResponses = mutable.Map[TopicPartition, 
PartitionResponse]()
-    val invalidRequestResponses = mutable.Map[TopicPartition, 
PartitionResponse]()
-    val authorizedRequestInfo = mutable.Map[TopicPartition, MemoryRecords]()
+    val unauthorizedTopicResponses = mutable.Map[TopicIdPartition, 
PartitionResponse]()
+    val nonExistingTopicResponses = mutable.Map[TopicIdPartition, 
PartitionResponse]()
+    val invalidRequestResponses = mutable.Map[TopicIdPartition, 
PartitionResponse]()
+    val authorizedRequestInfo = mutable.Map[TopicIdPartition, MemoryRecords]()
+    val topicIdToPartitionData = new mutable.ArrayBuffer[(TopicIdPartition, 
ProduceRequestData.PartitionProduceData)]
+
+    produceRequest.data.topicData.forEach { topic =>
+      topic.partitionData.forEach { partition =>
+        val (topicName, topicId) = if (topic.topicId().equals(Uuid.ZERO_UUID)) 
{
+          (topic.name(), metadataCache.getTopicId(topic.name()))
+        } else {
+          (metadataCache.getTopicName(topic.topicId).orElse(topic.name), 
topic.topicId())
+        }
+
+        val topicPartition = new TopicPartition(topicName, partition.index())
+        if (topicName.isEmpty)
+          nonExistingTopicResponses += new TopicIdPartition(topicId, 
topicPartition) -> new PartitionResponse(Errors.UNKNOWN_TOPIC_ID)
+        else if (!metadataCache.contains(topicPartition))
+          nonExistingTopicResponses += new TopicIdPartition(topicId, 
topicPartition) -> new PartitionResponse(Errors.UNKNOWN_TOPIC_OR_PARTITION)

Review Comment:
   It seems that the Fetch request does the right thing. If an old version of 
the fetch request includes topic name that doesn't exist, it will go through 
the authorization check first.
   
   ```
         // Regular Kafka consumers need READ permission on each partition they 
are fetching.
         val partitionDatas = new mutable.ArrayBuffer[(TopicIdPartition, 
FetchRequest.PartitionData)]
         fetchContext.foreachPartition { (topicIdPartition, partitionData) =>
           if (topicIdPartition.topic == null)
             erroneous += topicIdPartition -> 
FetchResponse.partitionResponse(topicIdPartition, Errors.UNKNOWN_TOPIC_ID)
           else
             partitionDatas += topicIdPartition -> partitionData
         }
         val authorizedTopics = authHelper.filterByAuthorized(request.context, 
READ, TOPIC, partitionDatas)(_._1.topicPartition.topic)
         partitionDatas.foreach { case (topicIdPartition, data) =>
           if (!authorizedTopics.contains(topicIdPartition.topic))
             erroneous += topicIdPartition -> 
FetchResponse.partitionResponse(topicIdPartition, 
Errors.TOPIC_AUTHORIZATION_FAILED)
           else if (!metadataCache.contains(topicIdPartition.topicPartition))
             erroneous += topicIdPartition -> 
FetchResponse.partitionResponse(topicIdPartition, 
Errors.UNKNOWN_TOPIC_OR_PARTITION)
   
   ```



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

Reply via email to