mjsax commented on code in PR #20326:
URL: https://github.com/apache/kafka/pull/20326#discussion_r2626789263
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/InternalTopicManager.java:
##########
@@ -461,121 +467,159 @@ public Set<String> makeReady(final Map<String,
InternalTopicConfig> topics) {
// have existed with the expected number of partitions, or some create
topic returns fatal errors.
log.debug("Starting to validate internal topics {} in partition
assignor.", topics);
- long currentWallClockMs = time.milliseconds();
+ final long currentWallClockMs = time.milliseconds();
final long deadlineMs = currentWallClockMs + retryTimeoutMs;
- Set<String> topicsNotReady = new HashSet<>(topics.keySet());
+ final Set<String> topicsNotReady = new HashSet<>(topics.keySet());
final Set<String> newlyCreatedTopics = new HashSet<>();
while (!topicsNotReady.isEmpty()) {
final Set<String> tempUnknownTopics = new HashSet<>();
- topicsNotReady = validateTopics(topicsNotReady, topics,
tempUnknownTopics);
- newlyCreatedTopics.addAll(topicsNotReady);
+ // Only consider the not-ready subset on each iteration
+ final Map<String, InternalTopicConfig> notReadyTopicsMap =
topics.entrySet().stream()
+ .filter(e -> topicsNotReady.contains(e.getKey()))
+ .collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue));
+ final Set<NewTopic> topicsToCreate =
computeTopicsToCreate(notReadyTopicsMap, tempUnknownTopics);
+
+ topicsNotReady.retainAll(notReadyTopicsMap.keySet());
+
+ final boolean noTopicsToCreate = topicsToCreate.isEmpty() &&
tempUnknownTopics.isEmpty();
+
+ if (noTopicsToCreate) {
+ // Nothing left to create - all remaining topics were already
ready
+ break;
+ }
+ if (!topicsToCreate.isEmpty()) {
+ final Set<String> createdTopics = createTopics(topicsToCreate,
topicsNotReady, deadlineMs);
+ topicsNotReady.removeAll(createdTopics);
+ newlyCreatedTopics.addAll(createdTopics);
+ }
if (!topicsNotReady.isEmpty()) {
- final Set<NewTopic> newTopics = new HashSet<>();
+ maybeThrowTimeout(new TimeoutContext(
+ Collections.singleton("makeReadyCheck"), // dummy
collection just to trigger if `topicsNotReady` is non-empty
Review Comment:
Thanks. Did a small follow up PR for it:
https://github.com/apache/kafka/pull/21165
--
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]