[ 
https://issues.apache.org/jira/browse/KAFKA-5604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17058327#comment-17058327
 ] 

Xiang Zhang commented on KAFKA-5604:
------------------------------------

[~mjsax] I notice that beginTransaction(), sendOffsesToTransaction(), 
commitTransaction(), abortTransaction() call maybeFailWithError() before 
anything.  myabeFailWithError() is defined as : 
{code:java}
private void maybeFailWithError() {
    if (hasError()) {
        // for ProducerFencedException, do not wrap it as a KafkaException 
        // but create a new instance without the call trace since it was not 
thrown because of the current call 
        if (lastError instanceof ProducerFencedException) {
            throw new ProducerFencedException("The producer has been rejected 
from the broker because " + "it tried to use an old epoch with the 
transactionalId"); 
        } else { 
            throw new KafkaException("Cannot execute transactional method 
because we are in an error state", lastError); 
        } 
    } 
}
{code}
[https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java#L1084]

If lastError indeed tracks last error, it seems it will throw 
ProducerFencedException for the second time as expected.

> All producer methods should raise `ProducerFencedException` after the first 
> time.
> ---------------------------------------------------------------------------------
>
>                 Key: KAFKA-5604
>                 URL: https://issues.apache.org/jira/browse/KAFKA-5604
>             Project: Kafka
>          Issue Type: Bug
>            Reporter: Apurva Mehta
>            Assignee: Apurva Mehta
>            Priority: Major
>
> Currently, when a `ProducerFencedException` is raised from a transactional 
> producer, the expectation is that the application should call `close` 
> immediately. However, if the application calls other producer methods, they 
> would get a `KafkaException`. This is a bit confusing, and results in tickets 
> like : https://issues.apache.org/jira/browse/KAFKA-5603. 
> We should update the producer so that calls to any method other than `close` 
> should raise a `ProducerFencedException` after the first time it is raised.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to