KAFKA-6292: Improved FileLogInputStream batch position checks in order to avoid type overflow related errors#4928
KAFKA-6292: Improved FileLogInputStream batch position checks in order to avoid type overflow related errors#4928hachikuji merged 7 commits intoapache:trunkfrom SuppieRK:rkhlebnov
Conversation
…ng unnecessary type conversion.
|
Thanks for the PR. Since this is fixing a bug, it would be great to add some unit tests. |
|
@ijuma I added simple Unit test to cover this corner case, although it seems to me as a good idea to update documentation or add explicit checks for the |
hachikuji
left a comment
There was a problem hiding this comment.
Thanks for the fix! Left a couple minor comments.
| } | ||
|
|
||
| @Test | ||
| public void testNextBatchSelectionAtMaxIntValue() throws IOException { |
There was a problem hiding this comment.
Maybe worth a test case which ensures correct behavior with start and end = 0 as well? Another good one would be to have a single batch which is truncated in the middle.
There was a problem hiding this comment.
This would be a good idea, but if the case includes position equal to size we will always get null. The case I covered was about type overflow when both parameters were set to their maximum values, so I think about renaming this method instead.
|
|
||
| @Test | ||
| public void testNextBatchSelectionAtMaxIntValue() throws IOException { | ||
| if (magic == 0 && compression == CompressionType.NONE) { |
There was a problem hiding this comment.
Seems no harm running this test case for every parameterization. I know it's redundant since we are not using either of the fields, but it feels less arbitrary.
|
@hachikuji can you check my additions, please? |
hachikuji
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the patch!
… type overflow (apache#4928) Switch from sum operations to subtraction to avoid type casting in checks and type overflow during `FlieLogInputStream` work, especially in cases where property `log.segment.bytes` was set close to the `Integer.MAX_VALUE` and used as a `position` inside `nextBatch()` function. Reviewers: Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
… type overflow (#4928) Switch from sum operations to subtraction to avoid type casting in checks and type overflow during `FlieLogInputStream` work, especially in cases where property `log.segment.bytes` was set close to the `Integer.MAX_VALUE` and used as a `position` inside `nextBatch()` function. Reviewers: Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
… type overflow (#4928) Switch from sum operations to subtraction to avoid type casting in checks and type overflow during `FlieLogInputStream` work, especially in cases where property `log.segment.bytes` was set close to the `Integer.MAX_VALUE` and used as a `position` inside `nextBatch()` function. Reviewers: Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
…:1.1.1-sync to 1.1-nflx * commit '9611672e287c1a7933a78590e3f381da2ae7d136': (57 commits) MINOR: increase dev version from 1.1.1-SNAPSHOT to 1.1.2-SNAPSHOT (apache#5409) MINOR: Add thread dumps if broker node cannot be stopped (apache#5373) MINOR: update release.py MINOR: fix upgrade docs for Streams (apache#5392) MINOR: improve docs version numbers (apache#5372) Update version on the branch to 1.1.2-SNAPSHOT KAFKA-6292; Improve FileLogInputStream batch position checks to avoid type overflow (apache#4928) HOTFIX: Fix checkstyle errors in MetricsTest (apache#5345) KAFKA-7136: Avoid deadlocks in synchronized metrics reporters (apache#5341) MINOR: Close timing window in SimpleAclAuthorizer startup (apache#5318) MINOR: Use kill_java_processes when killing ConsoleConsumer in system tests (apache#5297) KAFKA-7104: More consistent leader's state in fetch response (apache#5305) Revert "MINOR: Avoid coarse lock in Pool#getAndMaybePut (apache#5258)" MINOR: Avoid coarse lock in Pool#getAndMaybePut (apache#5258) MINOR: bugfix streams total metrics (apache#5277) KAFKA-7082: Concurrent create topics may throw NodeExistsException (apache#5259) MINOR: Upgrade to Gradle 4.8.1 KAFKA-7012: Don't process SSL channels without data to process (apache#5237) KAFKA-7058: Comparing schema default values using Objects#deepEquals() KAFKA-7047: Added SimpleHeaderConverter to plugin isolation whitelist ...
Basically, my change was very simple - switch from sum operations to subtraction to avoid type casting in checks and type overflow during FlieLogInputStream work, especially in cases where property
log.segment.byteswas set close to theInteger.MAX_VALUEand used as apositioninsidenextBatch()function.All related Unit tests are working as intended. No new tests (probably) required.