gaborgsomogyi commented on a change in pull request #23747:
[SPARK-26848][SQL][SS] Introduce new option to Kafka source: offset by
timestamp (starting/ending)
URL: https://github.com/apache/spark/pull/23747#discussion_r324701923
##########
File path:
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaOffsetReader.scala
##########
@@ -315,25 +358,40 @@ private[kafka010] class KafkaOffsetReader(
if (newPartitions.isEmpty) {
Map.empty[TopicPartition, Long]
} else {
- runUninterruptibly {
- withRetriesWithoutInterrupt {
- // Poll to get the latest assigned partitions
- consumer.poll(0)
- val partitions = consumer.assignment()
- consumer.pause(partitions)
- logDebug(s"\tPartitions assigned to consumer: $partitions")
-
- // Get the earliest offset of each partition
- consumer.seekToBeginning(partitions)
- val partitionOffsets = newPartitions.filter { p =>
- // When deleting topics happen at the same time, some partitions
may not be in
- // `partitions`. So we need to ignore them
- partitions.contains(p)
- }.map(p => p -> consumer.position(p)).toMap
- logDebug(s"Got earliest offsets for new partitions:
$partitionOffsets")
- partitionOffsets
- }
+ partitionsAssignedToConsumer(partitions => {
+ // Get the earliest offset of each partition
+ consumer.seekToBeginning(partitions)
+ val partitionOffsets = newPartitions.filter { p =>
+ // When deleting topics happen at the same time, some partitions may
not be in
+ // `partitions`. So we need to ignore them
+ partitions.contains(p)
+ }.map(p => p -> consumer.position(p)).toMap
+ logDebug(s"Got earliest offsets for new partitions: $partitionOffsets")
+ partitionOffsets
+ }, fetchingEarliestOffset = true)
+ }
+ }
+
+ private def partitionsAssignedToConsumer(
+ body: ju.Set[TopicPartition] => Map[TopicPartition, Long],
+ fetchingEarliestOffset: Boolean = false)
+ : Map[TopicPartition, Long] = runUninterruptibly {
+
+ withRetriesWithoutInterrupt {
+ // Poll to get the latest assigned partitions
+ consumer.poll(0)
Review comment:
Visiting this PR back it's nice that we've compacted the problematic old
API. It will be easier to replace when new API is available...
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]