-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8428: Always require a single batch with compressed messages #6816
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 7 commits
d38251f
93bbe73
a94d206
918b4d5
f173eb1
8a6de04
888733a
d3e25bb
6f05943
7fa8c55
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,20 +22,43 @@ import java.util.concurrent.TimeUnit | |
| import kafka.api.{ApiVersion, KAFKA_2_0_IV1} | ||
| import kafka.common.LongRef | ||
| import kafka.message._ | ||
| import org.apache.kafka.common.errors.{InvalidTimestampException, UnsupportedCompressionTypeException, UnsupportedForMessageFormatException} | ||
| import org.apache.kafka.common.errors.{InvalidTimestampException, KafkaStorageException, UnsupportedCompressionTypeException, UnsupportedForMessageFormatException} | ||
| import org.apache.kafka.common.record._ | ||
| import org.apache.kafka.common.utils.Time | ||
| import org.apache.kafka.test.TestUtils | ||
| import org.junit.Assert._ | ||
| import org.junit.Test | ||
| import org.scalatest.Assertions.intercept | ||
| import org.scalatest.Assertions.{assertThrows, intercept} | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| class LogValidatorTest { | ||
|
|
||
| val time = Time.SYSTEM | ||
|
|
||
| @Test | ||
| def testOnlyOneBatchCompressedV0(): Unit = { | ||
| checkOnlyOneBatchCompressed(RecordBatch.MAGIC_VALUE_V0) | ||
| } | ||
|
|
||
| @Test | ||
| def testOnlyOneBatchCompressedV1(): Unit = { | ||
| checkOnlyOneBatchCompressed(RecordBatch.MAGIC_VALUE_V1) | ||
| } | ||
|
|
||
| @Test | ||
| def testOnlyOneBatchCompressedV2(): Unit = { | ||
| checkOnlyOneBatchCompressed(RecordBatch.MAGIC_VALUE_V2) | ||
| } | ||
|
|
||
| private def checkOnlyOneBatchCompressed(magic: Byte) { | ||
| LogValidator.validateCompressedRecords(createRecords(magic, 0L, CompressionType.GZIP)) | ||
|
Contributor
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. I wonder if it would be better to validate through
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. 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. |
||
|
|
||
| assertThrows[InvalidRecordException] { | ||
| LogValidator.validateCompressedRecords(createTwoBatchedRecords(magic, 0L, CompressionType.GZIP)) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| def testLogAppendTimeNonCompressedV1() { | ||
| checkLogAppendTimeNonCompressed(RecordBatch.MAGIC_VALUE_V1) | ||
|
|
@@ -1137,6 +1160,22 @@ class LogValidatorTest { | |
| builder.build() | ||
| } | ||
|
|
||
| def createTwoBatchedRecords(magicValue: Byte, | ||
| timestamp: Long = RecordBatch.NO_TIMESTAMP, | ||
| codec: CompressionType): MemoryRecords = { | ||
| val buf = ByteBuffer.allocate(2048) | ||
| var builder = MemoryRecords.builder(buf, magicValue, codec, TimestampType.CREATE_TIME, 0L) | ||
| builder.append(10L, "1".getBytes(), "a".getBytes()) | ||
| builder.close() | ||
| builder = MemoryRecords.builder(buf, magicValue, codec, TimestampType.CREATE_TIME, 1L) | ||
| builder.append(11L, "2".getBytes(), "b".getBytes()) | ||
| builder.append(12L, "3".getBytes(), "c".getBytes()) | ||
| builder.close() | ||
|
|
||
| buf.flip() | ||
| MemoryRecords.readableRecords(buf.slice()) | ||
| } | ||
|
|
||
| /* check that offsets are assigned consecutively from the given base offset */ | ||
| def checkOffsets(records: MemoryRecords, baseOffset: Long) { | ||
| assertTrue("Message set should not be empty", records.records.asScala.nonEmpty) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.