chia7712 commented on code in PR #22423:
URL: https://github.com/apache/kafka/pull/22423#discussion_r3695981595
##########
server/src/main/java/org/apache/kafka/server/DefaultAutoTopicCreationManager.java:
##########
@@ -321,25 +321,19 @@ 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 -> {
Review Comment:
This will create extra map collection. Could we keep using foreach?
--
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]