-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-17872: Update consumed offsets on records with invalid timestamp #17710
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| import org.apache.kafka.common.serialization.Deserializer; | ||
| import org.apache.kafka.common.serialization.IntegerDeserializer; | ||
| import org.apache.kafka.common.serialization.IntegerSerializer; | ||
| import org.apache.kafka.common.serialization.Serdes; | ||
| import org.apache.kafka.common.serialization.LongSerializer; | ||
| import org.apache.kafka.common.serialization.Serializer; | ||
| import org.apache.kafka.common.utils.Bytes; | ||
| import org.apache.kafka.common.utils.LogContext; | ||
|
|
@@ -74,8 +74,7 @@ public class RecordQueueTest { | |
| private final StreamsMetricsImpl streamsMetrics = | ||
| new StreamsMetricsImpl(metrics, "mock", new MockTime()); | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| final InternalMockProcessorContext context = new InternalMockProcessorContext<>( | ||
| final InternalMockProcessorContext<Integer, Integer> context = new InternalMockProcessorContext<>( | ||
|
Member
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. Side cleanup to fix warnings |
||
| StateSerdes.withBuiltinTypes("anyName", Bytes.class, Bytes.class), | ||
| new MockRecordCollector(), | ||
| metrics | ||
|
|
@@ -88,19 +87,28 @@ public class RecordQueueTest { | |
| timestampExtractor, | ||
| new LogAndFailExceptionHandler(), | ||
| context, | ||
| new LogContext()); | ||
| new LogContext() | ||
| ); | ||
| private final RecordQueue queueThatSkipsDeserializeErrors = new RecordQueue( | ||
| new TopicPartition("topic", 1), | ||
| mockSourceNodeWithMetrics, | ||
| timestampExtractor, | ||
| new LogAndContinueExceptionHandler(), | ||
| context, | ||
| new LogContext()); | ||
| new LogContext() | ||
| ); | ||
| private final RecordQueue queueThatSkipsInvalidTimestamps = new RecordQueue( | ||
| new TopicPartition("topic", 1), | ||
| mockSourceNodeWithMetrics, | ||
| new LogAndSkipOnInvalidTimestamp(), | ||
| new LogAndFailExceptionHandler(), | ||
| context, | ||
| new LogContext() | ||
| ); | ||
|
|
||
| private final byte[] recordValue = intSerializer.serialize(null, 10); | ||
| private final byte[] recordKey = intSerializer.serialize(null, 1); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @BeforeEach | ||
| public void before() { | ||
| mockSourceNodeWithMetrics.init(context); | ||
|
|
@@ -340,7 +348,7 @@ public void shouldSetTimestampAndRespectMaxTimestampPolicy() { | |
|
|
||
| @Test | ||
| public void shouldThrowStreamsExceptionWhenKeyDeserializationFails() { | ||
| final byte[] key = Serdes.Long().serializer().serialize("foo", 1L); | ||
| final byte[] key = new LongSerializer().serialize("foo", 1L); | ||
|
Member
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. Side cleanup |
||
| final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList( | ||
| new ConsumerRecord<>("topic", 1, 1, 0L, TimestampType.CREATE_TIME, 0, 0, key, recordValue, | ||
| new RecordHeaders(), Optional.empty())); | ||
|
|
@@ -354,7 +362,7 @@ public void shouldThrowStreamsExceptionWhenKeyDeserializationFails() { | |
|
|
||
| @Test | ||
| public void shouldThrowStreamsExceptionWhenValueDeserializationFails() { | ||
| final byte[] value = Serdes.Long().serializer().serialize("foo", 1L); | ||
| final byte[] value = new LongSerializer().serialize("foo", 1L); | ||
| final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList( | ||
| new ConsumerRecord<>("topic", 1, 1, 0L, TimestampType.CREATE_TIME, 0, 0, recordKey, value, | ||
| new RecordHeaders(), Optional.empty())); | ||
|
|
@@ -368,7 +376,7 @@ public void shouldThrowStreamsExceptionWhenValueDeserializationFails() { | |
|
|
||
| @Test | ||
| public void shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHandler() { | ||
| final byte[] key = Serdes.Long().serializer().serialize("foo", 1L); | ||
| final byte[] key = new LongSerializer().serialize("foo", 1L); | ||
| final ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>("topic", 1, 1, 0L, | ||
| TimestampType.CREATE_TIME, 0, 0, key, recordValue, | ||
| new RecordHeaders(), Optional.empty()); | ||
|
|
@@ -381,7 +389,7 @@ public void shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHan | |
|
|
||
| @Test | ||
| public void shouldNotThrowStreamsExceptionWhenValueDeserializationFailsWithSkipHandler() { | ||
| final byte[] value = Serdes.Long().serializer().serialize("foo", 1L); | ||
| final byte[] value = new LongSerializer().serialize("foo", 1L); | ||
| final ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>("topic", 1, 1, 0L, | ||
| TimestampType.CREATE_TIME, 0, 0, recordKey, value, | ||
| new RecordHeaders(), Optional.empty()); | ||
|
|
@@ -404,7 +412,7 @@ public void shouldThrowOnNegativeTimestamp() { | |
| mockSourceNodeWithMetrics, | ||
| new FailOnInvalidTimestamp(), | ||
| new LogAndContinueExceptionHandler(), | ||
| new InternalMockProcessorContext(), | ||
| new InternalMockProcessorContext<>(), | ||
| new LogContext()); | ||
|
|
||
| final StreamsException exception = assertThrows( | ||
|
|
@@ -421,20 +429,25 @@ public void shouldThrowOnNegativeTimestamp() { | |
|
|
||
| @Test | ||
| public void shouldDropOnNegativeTimestamp() { | ||
| final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList( | ||
| new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, | ||
| new RecordHeaders(), Optional.empty())); | ||
| final ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>( | ||
| "topic", | ||
| 1, | ||
| 1, | ||
| -1L, // negative timestamp | ||
| TimestampType.CREATE_TIME, | ||
| 0, | ||
| 0, | ||
| recordKey, | ||
| recordValue, | ||
| new RecordHeaders(), | ||
| Optional.empty() | ||
| ); | ||
| final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(record); | ||
|
|
||
| final RecordQueue queue = new RecordQueue( | ||
| new TopicPartition("topic", 1), | ||
| mockSourceNodeWithMetrics, | ||
| new LogAndSkipOnInvalidTimestamp(), | ||
| new LogAndContinueExceptionHandler(), | ||
| new InternalMockProcessorContext(), | ||
| new LogContext()); | ||
| queue.addRawRecords(records); | ||
| queueThatSkipsInvalidTimestamps.addRawRecords(records); | ||
|
|
||
| assertEquals(0, queue.size()); | ||
| assertEquals(1, queueThatSkipsInvalidTimestamps.size()); | ||
| assertEquals(new CorruptedRecord(record), queueThatSkipsInvalidTimestamps.poll(0)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
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.
This is the actual fix -- we track the record with invalid ts as "corrupted record" instead of dropping it completely. The
CorrecuptedRecrodsallows us to update the offset later, but would be dropped by itself and not be processed.