muralibasani commented on code in PR #21676:
URL: https://github.com/apache/kafka/pull/21676#discussion_r3581466826
##########
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java:
##########
@@ -1169,18 +1170,32 @@ private Future<RecordMetadata> doSend(ProducerRecord<K,
V> record, Callback call
// take into account broker load, the amount of data produced to
each partition, etc.).
int partition = partition(record, serializedKey, serializedValue,
cluster);
- setReadOnly(record.headers());
- Header[] headers = record.headers().toArray();
-
- int serializedSize =
AbstractRecords.estimateSizeInBytesUpperBound(RecordBatch.CURRENT_MAGIC_VALUE,
- compression.type(), serializedKey, serializedValue,
headers);
- ensureValidRecordSize(serializedSize);
long timestamp = record.timestamp() == null ? nowMs :
record.timestamp();
- // Append the record to the accumulator. Note, that the actual
partition may be
- // calculated there and can be accessed via
appendCallbacks.topicPartition.
- RecordAccumulator.RecordAppendResult result =
accumulator.append(record.topic(), partition, timestamp, serializedKey,
- serializedValue, headers, appendCallbacks,
remainingWaitMs, nowMs, cluster);
+ final RecordAccumulator.RecordAppendResult result;
+ // Fast path: if the record carries headers that are already
serialized in the wire
+ // format and were never read/modified (e.g. Kafka Streams
changelog writes), hand the
+ // bytes straight to the accumulator without a
deserialize/re-serialize round trip. If
+ // anything materialized them (interceptor, serializer, headers()
read), rawIfUnmodified()
+ // returns null and we take the normal Header[] path.
+ byte[] rawHeaders = record.headers() instanceof
PreSerializedHeaders
Review Comment:
Agree. Added tests for both the paths.
--
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]