KAFKA-8428: Always require a single batch with compressed messages#6816
Conversation
|
github somehow makes a lot of diff out of it, but actually no logical changes here except removing one forloop with |
hachikuji
left a comment
There was a problem hiding this comment.
The fix LGTM. Could we have a test case?
…uire-only-one-batch-in-compressed-data
|
@hachikuji Thanks for the review, added unit tests. |
hachikuji
left a comment
There was a problem hiding this comment.
Thanks @guozhangwang . Left a couple comments.
| } | ||
| } | ||
|
|
||
| private[kafka] def validateRecords(records: MemoryRecords): RecordBatch = { |
There was a problem hiding this comment.
Maybe name should be validateCompressedRecords?
| outputBuffer.put(inputBuffer); | ||
|
|
||
| // write again | ||
| inputBuffer = inputRecords.buffer().duplicate (); |
There was a problem hiding this comment.
nit: unneeded space. A couple of these above also.
| return builder.build(); | ||
| } | ||
|
|
||
| // for testing only, create a new memory-records that contains duplicated |
There was a problem hiding this comment.
Seems like it would be easier to create a record set with two batches... Here's an example:
ByteBuffer buffer = ByteBuffer.allocate(2048);
MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, magic, compression, TimestampType.CREATE_TIME, 0L);
builder.append(10L, "1".getBytes(), "a".getBytes());
builder.close();
builder = MemoryRecords.builder(buffer, magic, compression, TimestampType.CREATE_TIME, 1L);
builder.append(11L, "2".getBytes(), "b".getBytes());
builder.append(12L, "3".getBytes(), "c".getBytes());
builder.close();
buffer.flip();In any case, perhaps we can move this to LogValidatorTest since we are not likely to need it elsewhere?
There was a problem hiding this comment.
builder.close(); would reset the position so that the next batch would overwrite the first one. Let me change a bit to make it work.
There was a problem hiding this comment.
It only resets the position of a dup. We use the pattern above in several existing test cases
…uire-only-one-batch-in-compressed-data
|
Addressed comments. |
hachikuji
left a comment
There was a problem hiding this comment.
Thanks, just one more comment.
| } | ||
|
|
||
| private def checkOnlyOneBatchCompressed(magic: Byte) { | ||
| LogValidator.validateCompressedRecords(createRecords(magic, 0L, CompressionType.GZIP)) |
There was a problem hiding this comment.
I wonder if it would be better to validate through validateMessagesAndAssignOffsets since that is the method which Log actually calls. Also, we may as well add a similar check to ensure that non-compressed v2 only accepts one batch.
There was a problem hiding this comment.
I thought about that too and was a bit lazy getting to pass in all those parameters, I can change that again.
Regarding the check for uncompressed V2: yeah I can do that too.
…uire-only-one-batch-in-compressed-data
| val id: Int = 23 | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Looks like we didn't need this?
There was a problem hiding this comment.
Ack. Was trying to create a KAFKA_LATEST case object but ended up with a different approach.
…ges (#6816) I think it's better just to make single-batch as a universal requirement for all versions for compressed messages, and for V2 and beyond uncompressed messages as well. Reviewers: Jason Gustafson <jason@confluent.io>
|
Cherry-picked to 2.3. |
|
Why did we cherry pick this to 2.3? |
|
@ijuma : @hachikuji and I discussed about this, and we suggested to get this check in as early version as possible since additional validation stops us from accepting bad data -- if it breaks any clients in the wild, better break it earlier than later. |
|
@guozhangwang did you check if this breaks any other clients like librdkafka? I disagree that we should risk breaking clients so late in the cycle without discussing with the release manager at least. We are one day away from code freeze after all. |
|
Just to clarify, having multiple compressed batches in a single produce payload was already broken. We would have accepted the data without properly assigning offsets beyond the first batch. |
|
@ijuma The way we look at it is that it is more about fixing a bug than adding an extra check: in log validator, after the first pass our logic is the following: 1) if |
|
The change is definitely good. I just don't see the need to backport to 2.3 so late in the cycle. In any case, it's done. |
…ges (apache#6816) I think it's better just to make single-batch as a universal requirement for all versions for compressed messages, and for V2 and beyond uncompressed messages as well. Reviewers: Jason Gustafson <jason@confluent.io>
|
Some problems were identified and the change was reverted in 2.3 via 0701a79. |
…ges (apache#6816) I think it's better just to make single-batch as a universal requirement for all versions for compressed messages, and for V2 and beyond uncompressed messages as well. Reviewers: Jason Gustafson <jason@confluent.io>
Committer Checklist (excluded from commit message)