artemlivshits commented on code in PR #17698: URL: https://github.com/apache/kafka/pull/17698#discussion_r1870211891
########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -524,15 +757,16 @@ class TransactionCoordinator(txnConfig: TransactionConfig, producerIdCopy = txnMetadata.producerId producerEpochCopy = txnMetadata.producerEpoch // PrepareEpochFence has slightly different epoch bumping logic so don't include it here. - val currentTxnMetadataIsAtLeastTransactionsV2 = !txnMetadata.pendingState.contains(PrepareEpochFence) && txnMetadata.clientTransactionVersion.supportsEpochBump() + // Note that, it can only happen when the current state is Ongoing. + val isPrepareEpochFence = txnMetadata.pendingState.contains(PrepareEpochFence) Review Comment: What's the reason to have `isEpochFence` and `isPrepareEpochFence`? ########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -506,6 +507,238 @@ class TransactionCoordinator(txnConfig: TransactionConfig, clientTransactionVersion: TransactionVersion, responseCallback: EndTxnCallback, requestLocal: RequestLocal): Unit = { + if (clientTransactionVersion.supportsEpochBump()) { + endTransactionWithEpochBumpSupported( Review Comment: Can we name the new functionality endTransaction? This way the new code will be default and old will be back-compat path, so if one looks at the code a year from now could understand what the main logic is. Also, can we encapsulate the redirect to backward-compatible function inside the endTransaction, so we don't have to do checks and call different functions in multiple places? ########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -723,9 +980,8 @@ class TransactionCoordinator(txnConfig: TransactionConfig, // When a client and server support V2, every endTransaction call bumps the producer epoch. When checking epoch, we want to // check epoch + 1. Epoch bumps from PrepareEpochFence state are handled separately, so this method should not be used to check that case. // Returns true if the transaction state epoch is the specified producer epoch + 1 and epoch bump on every transaction is expected. - private def endTxnEpochBumped(txnMetadata: TransactionMetadata, producerEpoch: Short): Boolean = { - !txnMetadata.pendingState.contains(PrepareEpochFence) && txnMetadata.clientTransactionVersion.supportsEpochBump() && - txnMetadata.producerEpoch == producerEpoch + 1 + private def endTxnEpochBumped(txnMetadata: TransactionMetadata, producerEpoch: Short, supportsEpochBump: Boolean): Boolean = { + !txnMetadata.pendingState.contains(PrepareEpochFence) && supportsEpochBump && txnMetadata.producerEpoch == producerEpoch + 1 Review Comment: Shouldn't we change `supportsEpochBump` to be `isEpochFence` and make the condition to be `!sEpochFence && txnMetadata.producerEpoch == producerEpoch + 1`? ########## core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala: ########## @@ -506,6 +507,238 @@ class TransactionCoordinator(txnConfig: TransactionConfig, clientTransactionVersion: TransactionVersion, responseCallback: EndTxnCallback, requestLocal: RequestLocal): Unit = { + if (clientTransactionVersion.supportsEpochBump()) { + endTransactionWithEpochBumpSupported( + transactionalId, + producerId, + producerEpoch, + txnMarkerResult, + isFromClient = isFromClient, + clientTransactionVersion, + responseCallback, + requestLocal) + } else { + endTransactionWithTV1(transactionalId, + producerId, + producerEpoch, + txnMarkerResult, + isFromClient = isFromClient, + responseCallback, + requestLocal) + } + } + + private def endTransactionWithTV1(transactionalId: String, Review Comment: Can we add a javadoc for this function? -- 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