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


##########
server/src/main/java/org/apache/kafka/server/DefaultAutoTopicCreationManager.java:
##########
@@ -323,25 +323,22 @@ private void sendCreateTopicRequestWithErrorCaching(
     }
 
     private void cacheTopicCreationErrors(Set<String> topicNames, String 
errorMessage, long ttlMs) {
-        for (String topicName : topicNames) {
-            topicCreationErrorCache.put(topicName, errorMessage, ttlMs);
-        }
+        topicCreationErrorCache.put(topicNames.stream()
+            .collect(Collectors.toMap(topicName -> topicName, topicName -> 
errorMessage)), ttlMs);
     }
 
     private void cacheTopicCreationErrorsFromResponse(CreateTopicsResponse 
response, long ttlMs) {
-        response.data().topics().forEach(topicResult -> {
-            if (topicResult.errorCode() != Errors.NONE.code()) {
+        topicCreationErrorCache.put(response.data().topics().stream()
+            .filter(topicResult -> topicResult.errorCode() != 
Errors.NONE.code())
+            
.collect(Collectors.toMap(CreateTopicsResponseData.CreatableTopicResult::name, 
topicResult -> {
                 var errorMessage = 
Optional.ofNullable(topicResult.errorMessage())
-                        .filter(s -> !s.isEmpty())
-                        
.orElse(Errors.forCode(topicResult.errorCode()).message());
-                topicCreationErrorCache.put(topicResult.name(), errorMessage, 
ttlMs);
-                LOGGER.debug("Cached topic creation error for {}: {}", 
topicResult.name(), errorMessage);
-            }
-        });
+                    .filter(s -> !s.isEmpty())
+                    .orElse(Errors.forCode(topicResult.errorCode()).message());
+                LOGGER.debug("Create topic creation error for {}: {}", 
topicResult.name(), errorMessage);
+                return errorMessage;
+            })), ttlMs);
     }
 
     @Override
-    public void close() {
-        topicCreationErrorCache.clear();
-    }
+    public void close() { }

Review Comment:
   Sure



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