-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25005][SS]Support non-consecutive offsets for Kafka #22042
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 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc18a6f
Support non-consecutive offsets for Kafka
zsxwing dfea7e3
minor
zsxwing baef29f
address
zsxwing a9b00b4
update comment
zsxwing c98bf50
reuse FetchedRecord
zsxwing f379d47
one more place
zsxwing a06742f
Add FetchedData
zsxwing 3c72b80
Merge remote-tracking branch 'origin/master' into kafka-transaction-read
zsxwing f4b5f72
Merge remote-tracking branch 'origin/master' into kafka-transaction-read
zsxwing e0d2c4d
Address TD's comments
zsxwing 603e0bc
minor
zsxwing 0d0b8c5
Merge remote-tracking branch 'origin/master' into kafka-transaction-read
zsxwing 7a02921
address
zsxwing ea804cf
Merge remote-tracking branch 'origin/master' into kafka-transaction-read
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
address
- Loading branch information
commit 7a02921950cda865e3cd45f1d1635212c2f707c0
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
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
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 |
|---|---|---|
|
|
@@ -159,13 +159,10 @@ abstract class KafkaSourceTest extends StreamTest with SharedSQLContext with Kaf | |
| s"AddKafkaData(topics = $topics, data = $data, message = $message)" | ||
| } | ||
|
|
||
| object WithKafkaProducer { | ||
| def apply( | ||
| topic: String, | ||
| producer: KafkaProducer[String, String])( | ||
| func: KafkaProducer[String, String] => Unit): AssertOnQuery = { | ||
| object WithOffsetSync { | ||
| def apply(topic: String)(func: () => Unit): StreamAction = { | ||
| Execute("Run Kafka Producer")(_ => { | ||
| func(producer) | ||
| func() | ||
| // This is a hack for the race condition that the committed message may be not visible to | ||
| // consumer for a short time. | ||
| // Looks like after the following call returns, the consumer can always read the committed | ||
|
|
@@ -661,7 +658,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| StartStream(ProcessingTime(100), clock), | ||
| waitUntilBatchProcessed, | ||
| CheckAnswer(), | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages. They should be visible only after being committed. | ||
| producer.beginTransaction() | ||
| (0 to 4).foreach { i => | ||
|
|
@@ -672,7 +669,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| waitUntilBatchProcessed, | ||
| // Should not see any uncommitted messages | ||
| CheckNewAnswer(), | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| producer.commitTransaction() | ||
| }, | ||
| AdvanceManualClock(100), | ||
|
|
@@ -681,7 +678,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(3, 4), // offset: 3, 4, 5* [* means it's not a committed data message] | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages and abort the transaction. They should not be read. | ||
| producer.beginTransaction() | ||
| (6 to 10).foreach { i => | ||
|
|
@@ -695,7 +692,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(), // offset: 9*, 10*, 11* | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages again. The consumer should skip the above aborted messages and read | ||
| // them. | ||
| producer.beginTransaction() | ||
|
|
@@ -710,7 +707,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(15, 16), // offset: 15, 16, 17* | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| producer.beginTransaction() | ||
| producer.send(new ProducerRecord[String, String](topic, "18")).get() | ||
| producer.commitTransaction() | ||
|
|
@@ -783,7 +780,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| StartStream(ProcessingTime(100), clock), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(), | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages. They should be visible only after being committed. | ||
|
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. Why so? This read_uncommitted, right? |
||
| producer.beginTransaction() | ||
| (0 to 4).foreach { i => | ||
|
|
@@ -793,13 +790,13 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(0, 1, 2), // offset 0, 1, 2 | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| producer.commitTransaction() | ||
| }, | ||
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(3, 4), // offset: 3, 4, 5* [* means it's not a committed data message] | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages and abort the transaction. They should not be read. | ||
| producer.beginTransaction() | ||
| (6 to 10).foreach { i => | ||
|
|
@@ -813,7 +810,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(9, 10), // offset: 9, 10, 11* | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| // Send 5 messages again. The consumer should skip the above aborted messages and read | ||
| // them. | ||
| producer.beginTransaction() | ||
|
|
@@ -828,7 +825,7 @@ abstract class KafkaMicroBatchSourceSuiteBase extends KafkaSourceSuiteBase { | |
| AdvanceManualClock(100), | ||
| waitUntilBatchProcessed, | ||
| CheckNewAnswer(15, 16), // offset: 15, 16, 17* | ||
| WithKafkaProducer(topic, producer) { producer => | ||
| WithOffsetSync(topic) { () => | ||
| producer.beginTransaction() | ||
| producer.send(new ProducerRecord[String, String](topic, "18")).get() | ||
| producer.commitTransaction() | ||
|
|
||
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.
Why is this
waitUntilBatchProcessedneeded? CheckAnswer waits for the batch to complete anyways.