-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7140: Remove deprecated poll usages #5319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
910317a
fe77b3c
ab31aea
a359c53
87a57b7
68c6197
6ad6f5e
3482e73
608624e
131b422
581292f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,14 @@ | |
| package kafka.tools | ||
|
|
||
| import java.nio.charset.StandardCharsets | ||
| import java.time.Duration | ||
| import java.util | ||
| import java.util.{Arrays, Collections, Properties} | ||
|
|
||
| import kafka.utils.Exit | ||
| import org.apache.kafka.clients.consumer.{ConsumerConfig, KafkaConsumer} | ||
| import org.apache.kafka.clients.producer._ | ||
| import org.apache.kafka.common.TopicPartition | ||
| import org.apache.kafka.common.utils.Utils | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
@@ -69,9 +72,7 @@ object EndToEndLatency { | |
| consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer") | ||
| consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer") | ||
| consumerProps.put(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG, "0") //ensure we have no temporal batching | ||
|
|
||
| val consumer = new KafkaConsumer[Array[Byte], Array[Byte]](consumerProps) | ||
| consumer.subscribe(Collections.singletonList(topic)) | ||
|
|
||
| val producerProps = loadProps | ||
| producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList) | ||
|
|
@@ -88,10 +89,18 @@ object EndToEndLatency { | |
| consumer.close() | ||
| } | ||
|
|
||
| //Ensure we are at latest offset. seekToEnd evaluates lazily, that is to say actually performs the seek only when | ||
| //a poll() or position() request is issued. Hence we need to poll after we seek to ensure we see our first write. | ||
| consumer.seekToEnd(Collections.emptyList()) | ||
| consumer.poll(0) | ||
| val topics = consumer.listTopics() | ||
| val tp = topics.get(topic) | ||
| if (tp == null) { | ||
| finalise() | ||
| throw new RuntimeException("The tested topic doesn't exist in the cluster") | ||
| } | ||
| val topicPartitions = tp.asScala | ||
| .map(pi => new TopicPartition(pi.topic(), pi.partition())) | ||
| .to[List].asJava | ||
| consumer.assign(topicPartitions) | ||
| consumer.seekToEnd(topicPartitions) | ||
| consumer.assignment().asScala.foreach(consumer.position) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, the assignment will be empty here. I don't think the old code worked either as intended because it did the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change to manual assignment, something like this (which seems to work). |
||
|
|
||
| var totalTime = 0.0 | ||
| val latencies = new Array[Long](numMessages) | ||
|
|
@@ -103,7 +112,7 @@ object EndToEndLatency { | |
|
|
||
| //Send message (of random bytes) synchronously then immediately poll for it | ||
| producer.send(new ProducerRecord[Array[Byte], Array[Byte]](topic, message)).get() | ||
| val recordIter = consumer.poll(timeout).iterator | ||
| val recordIter = consumer.poll(Duration.ofMillis(timeout)).iterator | ||
|
|
||
| val elapsed = System.nanoTime - begin | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
| import org.apache.kafka.clients.consumer.OffsetAndTimestamp; | ||
| import org.apache.kafka.common.KafkaFuture; | ||
| import org.apache.kafka.common.PartitionInfo; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
| import org.apache.kafka.common.serialization.ByteArrayDeserializer; | ||
|
|
@@ -47,6 +48,7 @@ | |
| import java.text.SimpleDateFormat; | ||
| import java.util.Arrays; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
|
|
@@ -57,6 +59,7 @@ | |
| import java.util.Set; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * {@link StreamsResetter} resets the processing state of a Kafka Streams application so that, for example, you can reprocess its input from scratch. | ||
|
|
@@ -313,10 +316,14 @@ private int maybeResetInputAndSeekToEndIntermediateTopicOffsets(final Map consum | |
| config.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false"); | ||
|
|
||
| try (final KafkaConsumer<byte[], byte[]> client = new KafkaConsumer<>(config, new ByteArrayDeserializer(), new ByteArrayDeserializer())) { | ||
| client.subscribe(topicsToSubscribe); | ||
| client.poll(1); | ||
| Map<String, List<PartitionInfo>> pi = client.listTopics(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not final yet, will refactor it a bit as suggested in earlier comments. |
||
| Collection<TopicPartition> partitions = pi.entrySet().stream() | ||
| .filter(entry -> topicsToSubscribe.contains(entry.getKey())) | ||
| .flatMap(entry -> entry.getValue().stream()) | ||
| .map(info -> new TopicPartition(info.topic(), info.partition())) | ||
| .collect(Collectors.toList()); | ||
| client.assign(partitions); | ||
|
|
||
| final Set<TopicPartition> partitions = client.assignment(); | ||
| final Set<TopicPartition> inputTopicPartitions = new HashSet<>(); | ||
| final Set<TopicPartition> intermediateTopicPartitions = new HashSet<>(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here it seems the old code assumed that there is a topic. Now I added a check that there must be a topic beforehand. the producer would anyway create it according to the default settings but I think that most of the latency tests executed by users won't depend on the default settings and they rather want to create topics manually according to their likings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess another approach might be to produce a dummy record to the topic first before assigning the partitions to the consumer and starting the test. That would let us retain the existing behavior.