jolshan commented on code in PR #14088: URL: https://github.com/apache/kafka/pull/14088#discussion_r1275549290
########## clients/src/test/java/org/apache/kafka/clients/producer/internals/SenderTest.java: ########## @@ -3107,6 +3099,45 @@ public void testReceiveFailedBatchTwiceWithTransactions() throws Exception { txnManager.beginTransaction(); } + @Test + public void testInvalidTxnStateIsAnAbortableError() throws Exception { + ProducerIdAndEpoch producerIdAndEpoch = new ProducerIdAndEpoch(123456L, (short) 0); + apiVersions.update("0", NodeApiVersions.create(ApiKeys.INIT_PRODUCER_ID.id, (short) 0, (short) 3)); + TransactionManager txnManager = new TransactionManager(logContext, "testInvalidTxnState", 60000, 100, apiVersions); + + setupWithTransactionState(txnManager); + doInitTransactions(txnManager, producerIdAndEpoch); + + txnManager.beginTransaction(); + txnManager.maybeAddPartition(tp0); + client.prepareResponse(buildAddPartitionsToTxnResponseData(0, Collections.singletonMap(tp0, Errors.NONE))); + sender.runOnce(); + + Future<RecordMetadata> request = appendToAccumulator(tp0); + sender.runOnce(); // send request + sendIdempotentProducerResponse(0, tp0, Errors.INVALID_TXN_STATE, -1); + + // Return InvalidTxnState error. It should be abortable. + sender.runOnce(); + assertFutureFailure(request, InvalidTxnStateException.class); + assertTrue(txnManager.hasAbortableError()); + TransactionalRequestResult result = txnManager.beginAbort(); + sender.runOnce(); + + // Once the transaction is aborted, we should be able to begin a new one. + respondToEndTxn(Errors.NONE); + sender.runOnce(); + assertTrue(txnManager::isInitializing); + prepareInitProducerResponse(Errors.NONE, producerIdAndEpoch.producerId, producerIdAndEpoch.epoch); Review Comment: The places we call: ``` if (canBumpEpoch()) { epochBumpRequired = true; KafkaException exception = new KafkaException(unackedMessagesErr + "It is safe to abort " + "the transaction and continue."); transitionToAbortableError(exception); ``` ``` public synchronized void maybeTransitionToErrorState(RuntimeException exception) { if (exception instanceof ClusterAuthorizationException || exception instanceof TransactionalIdAuthorizationException || exception instanceof ProducerFencedException || exception instanceof UnsupportedVersionException) { transitionToFatalError(exception); } else if (isTransactional()) { if (canBumpEpoch() && !isCompleting()) { epochBumpRequired = true; } transitionToAbortableError(exception); } ``` and a third that sometimes does and sometimes doesn't. I think the path for this specific produce request error is the second one so we may not bump epoch in some cases? -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org