OmniaGM commented on code in PR #24172:
URL: https://github.com/apache/kafka/pull/24172#discussion_r4616302714
##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -876,12 +876,17 @@ class KafkaApis(val requestChannel: RequestChannel,
.setLastStableOffset(partitionData.lastStableOffset)
.setLogStartOffset(partitionData.logStartOffset)
.setAbortedTransactions(partitionData.abortedTransactions)
- .setRecords(new LazyDownConversionRecords(tp.topicPartition,
unconvertedRecords, magic, fetchContext.getFetchOffset(tp).get, time))
+ .setRecords(new LazyDownConversionRecords(tp.topicPartition,
unconvertedRecords, magic, fetchContext.getFetchOffset(tp).get, time,
+
logConfig.map(_.maxDecompressedMessageBytes).getOrElse(Records.SOFT_MAX_ARRAY_LENGTH)))
.setPreferredReadReplica(partitionData.preferredReadReplica())
} catch {
case e: UnsupportedCompressionTypeException =>
trace("Received unsupported compression type error during
down-conversion", e)
FetchResponse.partitionResponse(tp,
Errors.UNSUPPORTED_COMPRESSION_TYPE)
+ case e: RecordSizeLimitExceededException =>
+ warn(s"Failed to down-convert records from partition $tp to
message format version $magic " +
Review Comment:
Small one: I think this warn with the full stack trace will be logged on
every fetch for the partition. Once the consumer reaches the oversized batch,
every re-fetch from that offset fails the eager conversion again, and older
clients just retry the unknown error. The `UnsupportedCompressionTypeException`
case just above logs at trace. Could we drop the stack trace here (the message
already has the partition, magic and client id) or lower it to debug? WDYT?
##########
clients/src/main/java/org/apache/kafka/common/record/LazyDownConversionRecordsSend.java:
##########
@@ -90,6 +93,15 @@ public int writeTo(TransferableChannel channel, int
previouslyWritten, int remai
// offset of the batch which has the unsupported compression
type. At that time, we will
// send back the UNSUPPORTED_COMPRESSION_TYPE error which will
allow the consumer to fail gracefully.
convertedRecords = buildOverflowBatch(remaining);
+ conversionFailed = true;
+ } catch (RecordSizeLimitExceededException e) {
+ // We have encountered a record whose decompressed body
exceeds the topic's
+ // max.decompressed.message.bytes. As above, we have already
committed to the fetch size, so we send
+ // an overflow batch. The consumer will then fetch from the
offset of the offending batch, at which
+ // point the eager conversion of the first batch fails and the
INVALID_RECORD error is returned.
+ log.warn("Failed to down-convert records for partition {},
sending an overflow batch instead", topicPartition(), e);
Review Comment:
Same as in `KafkaApis`: could we drop the stack trace here too? The
`UnsupportedCompressionTypeException` case above it doesn't log at all.
##########
clients/src/test/java/org/apache/kafka/common/record/DefaultRecordTest.java:
##########
@@ -561,6 +561,32 @@ public void
testReadFromStreamRejectsBodySizeExceedingConfiguredMax() throws IOE
}
}
+ // A body size that fits in an array but exceeds the configured limit is a
policy violation by a well-formed
+ // record and is reported as RecordSizeLimitExceededException; a size
above the array-length ceiling can never
+ // belong to a real record and remains a plain InvalidRecordException
(corruption).
+ @Test
+ public void
testOnlyAllocatableBodySizeExceedingConfiguredMaxIsReportedAsLimitViolation()
throws IOException {
+ try (InputStream in = new
ByteBufferInputStream(ByteBuffer.wrap(recordWithForgedBodySize(1000)))) {
+ assertThrows(RecordSizeLimitExceededException.class,
+ () -> DefaultRecord.readFrom(in, 0L, 0L,
RecordBatch.NO_SEQUENCE, null, 100));
+ }
+ // readPartiallyFrom is not used in the down-conversion path
+ try (InputStream in = new
ByteBufferInputStream(ByteBuffer.wrap(recordWithForgedBodySize(1000)))) {
+ assertThrows(InvalidRecordException.class,
Review Comment:
Nit: `assertThrows(InvalidRecordException.class, …)` also passes if
`readPartiallyFrom` throws `RecordSizeLimitExceededException`, so I think this
block doesn't check anything about the distinction. Should we either assert
`assertEquals(InvalidRecordException.class, e.getClass())` like the other
cases, or drop it since this path isn't used in down-conversion?
##########
clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java:
##########
@@ -86,6 +88,99 @@ private static Collection<Arguments> parameters() {
* than the number of bytes we get after conversion. This causes overflow
message batch(es) to be appended towards the
* end of the converted output.
*/
+ /**
Review Comment:
Nit: the new tests landed between the javadoc of `testConversion` (Test the
lazy down-conversion path. If overflow is true…) and the method, so that
javadoc now sits on top of the new test's javadoc. Could we move the new tests
below `testConversion`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]