jolshan commented on code in PR #17698: URL: https://github.com/apache/kafka/pull/17698#discussion_r1847090257
########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -564,33 +592,10 @@ class TransactionCoordinator(txnConfig: TransactionConfig, else PrepareAbort - // Maybe allocate new producer ID if we are bumping epoch and epoch is exhausted - val nextProducerIdOrErrors = - if (clientTransactionVersion.supportsEpochBump() && !txnMetadata.pendingState.contains(PrepareEpochFence) && txnMetadata.isProducerEpochExhausted) { - try { - Right(producerIdManager.generateProducerId()) - } catch { - case e: Exception => Left(Errors.forException(e)) - } - } else { - Right(RecordBatch.NO_PRODUCER_ID) - } - - if (nextState == PrepareAbort && txnMetadata.pendingState.contains(PrepareEpochFence)) { - // We should clear the pending state to make way for the transition to PrepareAbort and also bump - // the epoch in the transaction metadata we are about to append. - isEpochFence = true - txnMetadata.pendingState = None - txnMetadata.producerEpoch = producerEpoch - txnMetadata.lastProducerEpoch = RecordBatch.NO_PRODUCER_EPOCH - } - - nextProducerIdOrErrors.flatMap { - nextProducerId => - Right(coordinatorEpoch, txnMetadata.prepareAbortOrCommit(nextState, clientTransactionVersion, nextProducerId.asInstanceOf[Long], time.milliseconds())) - } + generateTxnTransitMetadataForTxnCompletion(nextState) case CompleteCommit => - if (txnMarkerResult == TransactionResult.COMMIT) + // The epoch should be valid as it is checked above + if (txnMarkerResult == TransactionResult.COMMIT || currentTxnMetadataIsAtLeastTransactionsV2) Review Comment: Why dud we add this additional case here but not for the abort case? ########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -564,33 +592,10 @@ class TransactionCoordinator(txnConfig: TransactionConfig, else PrepareAbort - // Maybe allocate new producer ID if we are bumping epoch and epoch is exhausted - val nextProducerIdOrErrors = - if (clientTransactionVersion.supportsEpochBump() && !txnMetadata.pendingState.contains(PrepareEpochFence) && txnMetadata.isProducerEpochExhausted) { - try { - Right(producerIdManager.generateProducerId()) - } catch { - case e: Exception => Left(Errors.forException(e)) - } - } else { - Right(RecordBatch.NO_PRODUCER_ID) - } - - if (nextState == PrepareAbort && txnMetadata.pendingState.contains(PrepareEpochFence)) { - // We should clear the pending state to make way for the transition to PrepareAbort and also bump - // the epoch in the transaction metadata we are about to append. - isEpochFence = true - txnMetadata.pendingState = None - txnMetadata.producerEpoch = producerEpoch - txnMetadata.lastProducerEpoch = RecordBatch.NO_PRODUCER_EPOCH - } - - nextProducerIdOrErrors.flatMap { - nextProducerId => - Right(coordinatorEpoch, txnMetadata.prepareAbortOrCommit(nextState, clientTransactionVersion, nextProducerId.asInstanceOf[Long], time.milliseconds())) - } + generateTxnTransitMetadataForTxnCompletion(nextState) case CompleteCommit => - if (txnMarkerResult == TransactionResult.COMMIT) + // The epoch should be valid as it is checked above + if (txnMarkerResult == TransactionResult.COMMIT || currentTxnMetadataIsAtLeastTransactionsV2) Review Comment: Why did we add this additional case here but not for the abort case? -- 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