chia7712 commented on code in PR #22423:
URL: https://github.com/apache/kafka/pull/22423#discussion_r4424573379


##########
server/src/main/java/org/apache/kafka/server/ExpiringErrorCache.java:
##########
@@ -50,29 +54,62 @@ private record Entry(String topicName, String errorMessage, 
long expirationTimeM
         this.time = time;
     }
 
-    void put(String topicName, String errorMessage, long ttlMs) {
+    void put(Collection<CreateTopicsResponseData.CreatableTopicResult> 
creatableTopicResults, long ttlMs) {
         lock.lock();
         try {
             var currentTimeMs = time.milliseconds();
             var expirationTimeMs = currentTimeMs + ttlMs;
-            var entry = new Entry(topicName, errorMessage, expirationTimeMs);
-            byTopic.put(topicName, entry);
-            expiryQueue.add(entry);
+            creatableTopicResults.stream()
+                .filter(result -> result.errorCode() != Errors.NONE.code())
+                .forEach(result -> {
+                    var errorMessage = 
Optional.ofNullable(result.errorMessage())
+                        .filter(s -> !s.isEmpty())
+                        .orElse(Errors.forCode(result.errorCode()).message());
+                    var entry = new Entry(result.name(), errorMessage, 
expirationTimeMs);
+                    byTopic.put(result.name(), entry);
+                    expiryQueue.add(entry);
+                    // Keep oversized batches from growing the cache far 
beyond its configured capacity.
+                    if (byTopic.size() > maxSize) {
+                        evictExpiredOrOverCapacity(currentTimeMs);
+                    }
+                });
+            evictExpiredOrOverCapacity(currentTimeMs);
+        } finally {
+            lock.unlock();
+        }
+    }
 
-            // Clean up expired entries and enforce capacity
-            while (!expiryQueue.isEmpty() &&
-                    (expiryQueue.peek().expirationTimeMs <= currentTimeMs || 
byTopic.size() > maxSize)) {
-                var evicted = expiryQueue.poll();
-                var current = byTopic.get(evicted.topicName);
-                if (current != null && current == evicted) {
-                    byTopic.remove(evicted.topicName);
+    void put(Set<String> topicNames, String errorMessage, long ttlMs) {
+        lock.lock();
+        try {
+            var currentTimeMs = time.milliseconds();
+            var expirationTimeMs = currentTimeMs + ttlMs;
+            topicNames.forEach(topicName -> {
+                var entry = new Entry(topicName, errorMessage, 
expirationTimeMs);
+                byTopic.put(topicName, entry);
+                expiryQueue.add(entry);
+                // Keep oversized batches from growing the cache far beyond 
its configured capacity.
+                if (byTopic.size() > maxSize) {

Review Comment:
   Are there any tests covering this new logic? The existing tests only insert 
one entry per put, so this branch is never exercised.



##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1290,8 +1289,7 @@ class KafkaApis(val requestChannel: RequestChannel,
       val topicMetadata = metadataCache.getTopicMetadata(internalTopics, 
request.context.listenerName, false, false).asScala
 
       if (topicMetadata.headOption.isEmpty) {
-        val controllerMutationQuota = 
quotas.controllerMutation.newPermissiveQuotaFor(request.session, 
request.header.clientId)

Review Comment:
   This is a good cleanup, but the side effect is the broker won’t create the 
ControllerMutation quota sensors (mutation-rate, throttle-time) for this client 
anymore. Those sensors were never recorded on the broker in KRaft, so this 
should be fine, but the PR description should mention 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to