-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9310: Handle UnknownProducerId from RecordCollector.send #7845
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 1 commit
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.errors.ProducerFencedException; | ||
| import org.apache.kafka.common.errors.TimeoutException; | ||
| import org.apache.kafka.common.errors.UnknownProducerIdException; | ||
| import org.apache.kafka.common.header.Header; | ||
| import org.apache.kafka.common.header.Headers; | ||
| import org.apache.kafka.common.header.internals.RecordHeader; | ||
|
|
@@ -199,6 +200,44 @@ public synchronized Future<RecordMetadata> send(final ProducerRecord record, fin | |
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
|
Member
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. What is the reason for this?
Contributor
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. Missing generics in the method. I fixed it. |
||
| @Test(expected = RecoverableClientException.class) | ||
|
Member
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. we should avoid to use this construct but use
Member
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. Should we also verify the root cause? |
||
| public void shouldThrowRecoverableExceptionOnProducerFencedException() { | ||
| final RecordCollector collector = new RecordCollectorImpl( | ||
| "test", | ||
| logContext, | ||
| new DefaultProductionExceptionHandler(), | ||
| new Metrics().sensor("dropped-records") | ||
| ); | ||
| collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) { | ||
| @Override | ||
| public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) { | ||
| throw new KafkaException(new ProducerFencedException("asdf")); | ||
| } | ||
| }); | ||
|
|
||
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test(expected = RecoverableClientException.class) | ||
|
Member
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. as above |
||
| public void shouldThrowRecoverableExceptionOnUnknownProducerException() { | ||
| final RecordCollector collector = new RecordCollectorImpl( | ||
| "test", | ||
| logContext, | ||
| new DefaultProductionExceptionHandler(), | ||
| new Metrics().sensor("dropped-records") | ||
| ); | ||
| collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) { | ||
| @Override | ||
| public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) { | ||
| throw new KafkaException(new UnknownProducerIdException("asdf")); | ||
| } | ||
| }); | ||
|
|
||
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test(expected = RecoverableClientException.class) | ||
| public void shouldThrowRecoverableExceptionWhenProducerFencedInCallback() { | ||
|
|
@@ -219,6 +258,26 @@ public synchronized Future<RecordMetadata> send(final ProducerRecord record, fin | |
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test(expected = RecoverableClientException.class) | ||
| public void shouldThrowRecoverableExceptionWhenProducerForgottenInCallback() { | ||
| final RecordCollector collector = new RecordCollectorImpl( | ||
| "test", | ||
| logContext, | ||
| new DefaultProductionExceptionHandler(), | ||
| new Metrics().sensor("skipped-records")); | ||
| collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) { | ||
| @Override | ||
| public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) { | ||
| callback.onCompletion(null, new UnknownProducerIdException("asdf")); | ||
| return null; | ||
| } | ||
| }); | ||
|
|
||
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Test | ||
| public void shouldThrowStreamsExceptionOnSubsequentCallIfASendFailsWithDefaultExceptionHandler() { | ||
|
|
||
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.
The error message of
RecoverableClientExceptiondoes not match any longer... (I would recommend to not add the error name to begin with, as the root cause exception is pass into the constructor anyway)