Seamus O Ceanainn created KAFKA-13448:
-----------------------------------------

             Summary: Kafka Producer Client Callback behaviour does not align 
with Javadoc
                 Key: KAFKA-13448
                 URL: https://issues.apache.org/jira/browse/KAFKA-13448
             Project: Kafka
          Issue Type: Bug
          Components: clients
    Affects Versions: 1.1.0
            Reporter: Seamus O Ceanainn


In PR [#4188|https://github.com/apache/kafka/pull/4188] as part of KAFKA-6180, 
a breaking change was accidentally introduced in the behaviour of Callbacks for 
the producer client.

Previously, whenever an exception was thrown when producing an event, the value 
for 'metadata' passed to the Callback.onCompletion method was always null. In 
PR [#4188|https://github.com/apache/kafka/pull/4188], in one part of the code 
where Callback.onCompletion is called, the behaviour was changed so that 
instead of passing a null value for metadata, a 'placeholder' value was 
provided instead (see 
[here|https://github.com/apache/kafka/pull/4188/files#diff-42d8f5166459ee28f201ff9cec0080fc7845544a0089ac9e8f3e16864cc1193eR1196]
 and 
[here|https://github.com/apache/kafka/pull/4188/files#diff-42d8f5166459ee28f201ff9cec0080fc7845544a0089ac9e8f3e16864cc1193eR1199]).
  This placeholder contained only topic and partition information, and with all 
other fields set to '-1'.

This change only impacted a subset of exceptions, so that in the case of 
ApiExceptions metadata would still be null (see 
[here|https://github.com/apache/kafka/commit/aa42a11dfd99ee9ab24d2e9a7521ef1c97ae1ff4#diff-42d8f5166459ee28f201ff9cec0080fc7845544a0089ac9e8f3e16864cc1193eR843]),
 but for all other exceptions the placeholder value would be used. The 
behaviour at the time of writing remains the same.

This issue was first reported in KAFKA-7412 when a user first noticed the 
difference between the documented behaviour of Callback.onCompletion and the 
implemented behaviour.

At the time it was assumed that the behaviour when errors occur was to always 
provide a placeholder metadata value to Callback.onCompletion, and the 
documentation was updated at that time to reflect this assumption in [PR 
#5798|https://github.com/apache/kafka/pull/5798]. The documentation now states 
that when an exception occurs that the method will be called with an empty 
metadata value (see 
[here|https://github.com/apache/kafka/blob/3.1/clients/src/main/java/org/apache/kafka/clients/producer/Callback.java#L30-L31]).
 However, there is still one case where Callback.onCompletion is called with a 
null value for metadata (see 
[here|https://github.com/apache/kafka/blob/3.1/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java#L1002]),
 so there is still a discrepancy between the documented behaviour and the 
implementation of Callback.onCompletion.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to