-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9645: Fallback to unsubscribe during Task Migrated #8220
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 all commits
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import org.apache.kafka.clients.consumer.InvalidOffsetException; | ||
| import org.apache.kafka.clients.consumer.MockConsumer; | ||
| import org.apache.kafka.clients.consumer.OffsetResetStrategy; | ||
| import org.apache.kafka.clients.consumer.internals.MockRebalanceListener; | ||
| import org.apache.kafka.clients.producer.MockProducer; | ||
| import org.apache.kafka.clients.producer.Producer; | ||
| import org.apache.kafka.common.Cluster; | ||
|
|
@@ -807,6 +808,66 @@ public void shouldShutdownTaskManagerOnClose() { | |
| EasyMock.verify(taskManager); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotReturnDataAfterTaskMigrated() { | ||
| final TaskManager taskManager = EasyMock.createNiceMock(TaskManager.class); | ||
|
|
||
| internalTopologyBuilder = EasyMock.createNiceMock(InternalTopologyBuilder.class); | ||
|
|
||
| EasyMock.expect(internalTopologyBuilder.sourceTopicCollection()).andReturn(Collections.singletonList(topic1)).times(2); | ||
|
|
||
| final MockConsumer<byte[], byte[]> consumer = new MockConsumer<>(OffsetResetStrategy.LATEST); | ||
|
|
||
| consumer.subscribe(Collections.singletonList(topic1), new MockRebalanceListener()); | ||
| consumer.rebalance(Collections.singletonList(t1p1)); | ||
| consumer.updateEndOffsets(Collections.singletonMap(t1p1, 10L)); | ||
| consumer.seekToEnd(Collections.singletonList(t1p1)); | ||
|
|
||
| final ChangelogReader changelogReader = new MockChangelogReader() { | ||
|
|
||
| @Override | ||
| public void restore() { | ||
| consumer.addRecord(new ConsumerRecord<>(topic1, 1, 11, new byte[0], new byte[0])); | ||
| consumer.addRecord(new ConsumerRecord<>(topic1, 1, 12, new byte[1], new byte[0])); | ||
|
|
||
| throw new TaskMigratedException( | ||
| "Changelog restore found task migrated", new RuntimeException("restore task migrated")); | ||
| } | ||
| }; | ||
|
|
||
| taskManager.handleLostAll(); | ||
|
|
||
| EasyMock.replay(taskManager, internalTopologyBuilder); | ||
|
|
||
| final StreamsMetricsImpl streamsMetrics = | ||
| new StreamsMetricsImpl(metrics, CLIENT_ID, StreamsConfig.METRICS_LATEST); | ||
|
|
||
| final StreamThread thread = new StreamThread( | ||
| mockTime, | ||
| config, | ||
| null, | ||
| consumer, | ||
| consumer, | ||
| changelogReader, | ||
| null, | ||
| taskManager, | ||
| streamsMetrics, | ||
| internalTopologyBuilder, | ||
| CLIENT_ID, | ||
| new LogContext(""), | ||
| new AtomicInteger() | ||
| ).updateThreadMetadata(getSharedAdminClientId(CLIENT_ID)); | ||
|
|
||
| final IllegalStateException thrown = assertThrows( | ||
| IllegalStateException.class, thread::run); | ||
|
|
||
| EasyMock.verify(taskManager); | ||
|
|
||
| // The Mock consumer shall throw as the assignment has been wiped out, but records are assigned. | ||
|
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. Hmm :) it reminds me that the mock consumer's behavior is not exactly the same as the actual consumer (the later would filter, the former would throw), but perhaps this worth a different PR to cleanup. @abbccdda could you file a JIRA for it?
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. Sounds good to me! https://issues.apache.org/jira/browse/KAFKA-9679 |
||
| assertEquals("No current assignment for partition topic1-1", thrown.getMessage()); | ||
| assertFalse(consumer.shouldRebalance()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldShutdownTaskManagerOnCloseWithoutStart() { | ||
| final Consumer<byte[], byte[]> consumer = EasyMock.createNiceMock(Consumer.class); | ||
|
|
||
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.
Nice.