Skip to content
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

Avoid StackOverflowException when Kafka.poll() 'timeout' param is 0 #2

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class KafkaRDD[K: ClassTag, V: ClassTag, R: ClassTag] private[spark] (
messageHandler: ConsumerRecord[K, V] => R
) extends RDD[R](sc, Nil) with Logging with HasOffsetRanges {

private val KAFKA_DEFAULT_POLL_TIME: String = "0"
private val KAFKA_DEFAULT_POLL_TIME: String = "100"
private val pollTime = kafkaParams.get("spark.kafka.poll.time")
.getOrElse(KAFKA_DEFAULT_POLL_TIME).toInt

Expand Down Expand Up @@ -169,7 +169,10 @@ class KafkaRDD[K: ClassTag, V: ClassTag, R: ClassTag] private[spark] (

private def fetchBatch: Iterator[ConsumerRecord[K, V]] = {
consumer.seek(new TopicPartition(part.topic, part.partition), requestOffset)
val recs = consumer.poll(pollTime)
var recs: ConsumerRecords[K, V] = null
do {
recs = consumer.poll(pollTime)
} while (recs.isEmpty && requestOffset < part.untilOffset)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @mariobriggs
Should we take out the recursive call below then?

I think the whole if clause can go then?

      if (!iter.hasNext) {
        if ( requestOffset < part.untilOffset ) {
          return getNext()
        }
        assert(requestOffset == part.untilOffset, errRanOutBeforeEnd(part))
        finished = true
        null.asInstanceOf[R]
      } else {

Because iter.hasNext will always be true when fetchBatch returns since it won't return until it has something non-empty to return.

BTW, we should definitely test to make sure this works when the topic is empty and doesn't stall. I will take care of that. Let me know what you think of the above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the removal of recursive call is right.

make sure this works when the topic is empty
<<
the '&& requestOffset < part.untilOffset' catches that i think

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

recs.records(new TopicPartition(part.topic, part.partition)).iterator().asScala
}

Expand Down