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


##########
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:
   Can we remove this friendless method?



##########
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);

Review Comment:
   `Create` -> `Cached`?



##########
server/src/main/java/org/apache/kafka/server/ExpiringErrorCache.java:
##########
@@ -50,14 +50,17 @@ private record Entry(String topicName, String errorMessage, 
long expirationTimeM
         this.time = time;
     }
 
-    void put(String topicName, String errorMessage, long ttlMs) {
+    void put(Map<String, String> topicErrorMessages, 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);
+            for (var topicErrorMessage : topicErrorMessages.entrySet()) {

Review Comment:
   ```java
               topicErrorMessages.forEach((topicName, errorMessage) -> {
                   var entry = new Entry(topicName, errorMessage, 
expirationTimeMs);
                   byTopic.put(topicName, entry);
                   expiryQueue.add(entry);
               });
   ```



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