-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18682][SS] Batch Source for Kafka #16686
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
Closed
Closed
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d371758
add kafka relation and refactor kafka source
b6c3055
update
4c81812
update
ab02a4c
single kafka provider for both stream and batch
e6b57ed
added uninterruptible thread version of kafka offset reader
ff94ed8
added uninterruptible thread version of kafka offset reader
f8fd34c
update tests
41271e2
resolve conflicts in KafakSource
74d96fc
update comments
d31fc81
address comments from @zsxwing
1db1649
update
3b0d48b
Merge branch 'master' of https://github.com/apache/spark into SPARK-1…
a5b0269
address comments from @zsxwing
c08c01f
late binding offsets
79d335e
update to late binding logic
b597cf1
remove kafka log4j debug
2487a72
address comments from @zsxwing
789d3af
update
5b48fc6
address comments from @tdas
5776009
address feedback from @tdas and @sxwing
aef89bc
fix indent
4e56f8c
address comments from @zsxwing
3bc7c4c
address comments from @zsxwing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ private[kafka010] case class CachedKafkaConsumer private( | |
|
|
||
| private val groupId = kafkaParams.get(ConsumerConfig.GROUP_ID_CONFIG).asInstanceOf[String] | ||
|
|
||
| private var consumer = createConsumer | ||
| var rawConsumer = createConsumer | ||
|
|
||
| /** Iterator to the already fetch data */ | ||
| private var fetchedData = ju.Collections.emptyIterator[ConsumerRecord[Array[Byte], Array[Byte]]] | ||
|
|
@@ -224,8 +224,8 @@ private[kafka010] case class CachedKafkaConsumer private( | |
|
|
||
| /** Create a new consumer and reset cached states */ | ||
| private def resetConsumer(): Unit = { | ||
| consumer.close() | ||
| consumer = createConsumer | ||
| rawConsumer.close() | ||
| rawConsumer = createConsumer | ||
| resetFetchedData() | ||
| } | ||
|
|
||
|
|
@@ -271,15 +271,15 @@ private[kafka010] case class CachedKafkaConsumer private( | |
| } | ||
| } | ||
|
|
||
| private def close(): Unit = consumer.close() | ||
| private def close(): Unit = rawConsumer.close() | ||
|
|
||
| private def seek(offset: Long): Unit = { | ||
| logDebug(s"Seeking to $groupId $topicPartition $offset") | ||
| consumer.seek(topicPartition, offset) | ||
| rawConsumer.seek(topicPartition, offset) | ||
| } | ||
|
|
||
| private def poll(pollTimeoutMs: Long): Unit = { | ||
| val p = consumer.poll(pollTimeoutMs) | ||
| val p = rawConsumer.poll(pollTimeoutMs) | ||
| val r = p.records(topicPartition) | ||
| logDebug(s"Polled $groupId ${p.partitions()} ${r.size}") | ||
| fetchedData = r.iterator | ||
|
|
@@ -290,10 +290,10 @@ private[kafka010] case class CachedKafkaConsumer private( | |
| * and the latest offset. | ||
| */ | ||
| private def getAvailableOffsetRange(): (Long, Long) = { | ||
| consumer.seekToBeginning(Set(topicPartition).asJava) | ||
| val earliestOffset = consumer.position(topicPartition) | ||
| consumer.seekToEnd(Set(topicPartition).asJava) | ||
| val latestOffset = consumer.position(topicPartition) | ||
| rawConsumer.seekToBeginning(Set(topicPartition).asJava) | ||
| val earliestOffset = rawConsumer.position(topicPartition) | ||
| rawConsumer.seekToEnd(Set(topicPartition).asJava) | ||
| val latestOffset = rawConsumer.position(topicPartition) | ||
| (earliestOffset, latestOffset) | ||
| } | ||
| } | ||
|
|
@@ -334,14 +334,15 @@ private[kafka010] object CachedKafkaConsumer extends Logging { | |
| def getOrCreate( | ||
| topic: String, | ||
| partition: Int, | ||
| kafkaParams: ju.Map[String, Object]): CachedKafkaConsumer = synchronized { | ||
| kafkaParams: ju.Map[String, Object], | ||
| reuse: Boolean): CachedKafkaConsumer = synchronized { | ||
|
||
| val groupId = kafkaParams.get(ConsumerConfig.GROUP_ID_CONFIG).asInstanceOf[String] | ||
| val topicPartition = new TopicPartition(topic, partition) | ||
| val key = CacheKey(groupId, topicPartition) | ||
|
|
||
| // If this is reattempt at running the task, then invalidate cache and start with | ||
| // a new consumer | ||
| if (TaskContext.get != null && TaskContext.get.attemptNumber > 1) { | ||
| if (!reuse || TaskContext.get != null && TaskContext.get.attemptNumber > 1) { | ||
| val removedConsumer = cache.remove(key) | ||
| if (removedConsumer != null) { | ||
| removedConsumer.close() | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
exposing internal var is generally not a good idea. A better approach is be to add the necessary methods (for which you need the consumer) in the class CachedKafkaConsumer.
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.
and why renamed?