-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MINOR] Guard against crashing on invalid key range queries #6521
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 6 commits
1167df5
09ace6b
ac27e85
b961d0a
cef3de5
f2a556b
b2deb14
61e86c8
bf38b11
892b1e9
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import org.apache.kafka.common.serialization.StringSerializer; | ||
| import org.apache.kafka.streams.KeyValue; | ||
| import org.apache.kafka.streams.processor.ProcessorContext; | ||
| import org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender; | ||
| import org.apache.kafka.streams.state.KeyValueIterator; | ||
| import org.apache.kafka.streams.state.KeyValueStore; | ||
| import org.apache.kafka.streams.state.KeyValueStoreTestDriver; | ||
|
|
@@ -38,6 +39,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.hasItem; | ||
| import static org.hamcrest.core.IsEqual.equalTo; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
@@ -389,4 +391,17 @@ public void shouldNotThrowConcurrentModificationException() { | |
|
|
||
| assertEquals(new KeyValue<>(0, "zero"), results.next()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotThrowInvalidRangeExceptionWithNegativeFromKey() { | ||
| LogCaptureAppender.setClassLoggerToDebug(InMemoryWindowStore.class); | ||
| final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(); | ||
|
|
||
| store.range(-1, 1); | ||
|
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. You can use
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. Ah thanks, will add to tests
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. Could you add a check to verify that the returned iterator is empty. Something along the lines of Could you also add a test for a range query where the start key is equal to the end key? Such a unit test ensures correct behaviour for this special case. nit: I would rename the test to These comments apply also to the unit tests below.
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. Ack Re: verify returned iterator is empty, add unit tests for equal start/end keys Regarding your third point, this patch is mostly aimed at the bug in [https://issues.apache.org/jira/browse/KAFKA-8159] which went undiscovered for a while because there were no tests of range queries with a negative key. I actually think it's fair to say we make no guarantees about what will happen if your app makes an invalid query; however we definitely shouldn't crash on what appears to be a valid query range (ie [-1,1]), which is the key point here
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. Fair enough |
||
|
|
||
| final List<String> messages = appender.getMessages(); | ||
| assertThat(messages, hasItem("Returning empty iterator for fetch with invalid key range: from > to. " | ||
| + "This may be due to serdes that don't preserve ordering when lexicographically comparing the serialized bytes. " | ||
| + "Note that the built-in numerical serdes do not follow this for negative numbers")); | ||
| } | ||
| } | ||
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.
ditto here and below