You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/10/10 01:01:10 UTC

[GitHub] [flink] becketqin commented on a change in pull request #13574: [FLINK-18323] Add a Kafka source implementation based on FLIP-27.

becketqin commented on a change in pull request #13574:
URL: https://github.com/apache/flink/pull/13574#discussion_r502725093



##########
File path: flink-connectors/flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/enumerator/subscriber/TopicListSubscriber.java
##########
@@ -0,0 +1,67 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package org.apache.flink.connector.kafka.source.enumerator.subscriber;
+
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.common.PartitionInfo;
+import org.apache.kafka.common.TopicPartition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.flink.connector.kafka.source.enumerator.subscriber.KafkaSubscriberUtils.maybeLog;
+import static org.apache.flink.connector.kafka.source.enumerator.subscriber.KafkaSubscriberUtils.updatePartitionChanges;
+
+/**
+ * A subscriber to a fixed list of topics.
+ */
+class TopicListSubscriber implements KafkaSubscriber {
+	private static final long serialVersionUID = -6917603843104947866L;
+	private static final Logger LOG = LoggerFactory.getLogger(TopicListSubscriber.class);
+	private final List<String> topics;
+
+	TopicListSubscriber(List<String> topics) {
+		this.topics = topics;
+	}
+
+	@Override
+	public PartitionChange getPartitionChanges(
+			KafkaConsumer<?, ?> consumer,
+			Set<TopicPartition> currentAssignment) {
+		Set<TopicPartition> newPartitions = new HashSet<>();
+		Set<TopicPartition> removedPartitions = new HashSet<>(currentAssignment);
+
+		// We cannot call partitionsFor() directly on each topic because this may accidentally create the topic
+		// if the topic does not exist. In Kafka 2.3+ we can use the "allow.auto.create.topics" configuration on

Review comment:
       Usually fetching full metadata occasionally won't cause performance issue. But given that we have upgraded the Kafka dependency to 2.4.1, I'll just disable the auto topic creation on the client side. The caveat is that this won't work for the older Kafka versions. I'll add document to explain this.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org