Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-9592

Safely abort Producer transactions during application shutdown

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.5.0
    • None
    • producer

    Description

      Today if a transactional producer hits a fatal exception, the caller usually catches the exception and handle it by closing the producer, and abort the transaction:

       

      try {
        producer.beginTxn();
        producer.send(xxx);
        producer.sendOffsets(xxx);
        producer.commit();
      } catch (ProducerFenced | UnknownPid e) {
        ...
        producer.abortTxn();
        producer.close();
      }

      This is what the current API suggests user to do. Another scenario is during an informed shutdown, people with EOS producer would also like to end an ongoing transaction before closing the producer as it sounds more clean.

      The tricky scenario is that `abortTxn` is not a safe call when the producer is already in an error state, which means user has to do another try-catch with the first layer catch block, making the error handling pretty annoying. 

      There are several ways to make this API robust and guide user to a safe usage:

      1. Internally abort any ongoing transaction within `producer.close`, and comment on `abortTxn` call to warn user not to do it manually. 
      2. Similar to 1, but get a new `close(boolean abortTxn)` API call in case some users want to handle transaction state by themselves.
      3. Introduce a new abort transaction API with a boolean flag indicating whether the producer is in error state, instead of throwing exceptions
      4. Introduce a public API `isInError` on producer for user to validate before doing any transactional API calls

      I personally favor 1 & 2 most as it is simple and does not require any API change. Considering the change scope, I would still recommend a small KIP.

       

      Attachments

        Activity

          People

            iamabug Xiang Zhang
            bchen225242 Boyang Chen
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: