Search in sources :

Example 1 with UNKNOWN

use of org.apache.kafka.streams.processor.internals.assignment.StreamsAssignmentProtocolVersions.UNKNOWN in project kafka by apache.

the class ChangelogTopics method setup.

public void setup() {
    // add tasks to state change log topic subscribers
    final Map<String, InternalTopicConfig> changelogTopicMetadata = new HashMap<>();
    for (final Map.Entry<Subtopology, TopicsInfo> entry : topicGroups.entrySet()) {
        final Subtopology subtopology = entry.getKey();
        final TopicsInfo topicsInfo = entry.getValue();
        final Set<TaskId> topicGroupTasks = tasksForTopicGroup.get(subtopology);
        if (topicGroupTasks == null) {
            log.debug("No tasks found for subtopology {}", subtopology);
            continue;
        } else if (topicsInfo.stateChangelogTopics.isEmpty()) {
            continue;
        }
        for (final TaskId task : topicGroupTasks) {
            final Set<TopicPartition> changelogTopicPartitions = topicsInfo.stateChangelogTopics.keySet().stream().map(topic -> new TopicPartition(topic, task.partition())).collect(Collectors.toSet());
            changelogPartitionsForStatefulTask.put(task, changelogTopicPartitions);
        }
        for (final InternalTopicConfig topicConfig : topicsInfo.nonSourceChangelogTopics()) {
            // the expected number of partitions is the max value of TaskId.partition + 1
            int numPartitions = UNKNOWN;
            for (final TaskId task : topicGroupTasks) {
                if (numPartitions < task.partition() + 1) {
                    numPartitions = task.partition() + 1;
                }
            }
            topicConfig.setNumberOfPartitions(numPartitions);
            changelogTopicMetadata.put(topicConfig.name(), topicConfig);
        }
        sourceTopicBasedChangelogTopics.addAll(topicsInfo.sourceTopicChangelogs());
    }
    final Set<String> newlyCreatedChangelogTopics = internalTopicManager.makeReady(changelogTopicMetadata);
    log.debug("Created state changelog topics {} from the parsed topology.", changelogTopicMetadata.values());
    for (final Map.Entry<TaskId, Set<TopicPartition>> entry : changelogPartitionsForStatefulTask.entrySet()) {
        final TaskId taskId = entry.getKey();
        final Set<TopicPartition> topicPartitions = entry.getValue();
        for (final TopicPartition topicPartition : topicPartitions) {
            if (!newlyCreatedChangelogTopics.contains(topicPartition.topic())) {
                preExistingChangelogPartitionsForTask.computeIfAbsent(taskId, task -> new HashSet<>()).add(topicPartition);
                if (!sourceTopicBasedChangelogTopics.contains(topicPartition.topic())) {
                    preExistingNonSourceTopicBasedChangelogPartitions.add(topicPartition);
                } else {
                    preExistingSourceTopicBasedChangelogPartitions.add(topicPartition);
                }
            }
        }
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Logger(org.slf4j.Logger) TaskId(org.apache.kafka.streams.processor.TaskId) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) TopicsInfo(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo) HashSet(java.util.HashSet) UNKNOWN(org.apache.kafka.streams.processor.internals.assignment.StreamsAssignmentProtocolVersions.UNKNOWN) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) Subtopology(org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology) Collections(java.util.Collections) TaskId(org.apache.kafka.streams.processor.TaskId) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TopicsInfo(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo) TopicPartition(org.apache.kafka.common.TopicPartition) HashMap(java.util.HashMap) Map(java.util.Map) Subtopology(org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology) HashSet(java.util.HashSet)

Aggregations

Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 LogContext (org.apache.kafka.common.utils.LogContext)1 TaskId (org.apache.kafka.streams.processor.TaskId)1 TopicsInfo (org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo)1 Subtopology (org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology)1 UNKNOWN (org.apache.kafka.streams.processor.internals.assignment.StreamsAssignmentProtocolVersions.UNKNOWN)1 Logger (org.slf4j.Logger)1