jolshan commented on code in PR #16840:
URL: https://github.com/apache/kafka/pull/16840#discussion_r1711919427
##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java:
##########
@@ -980,6 +998,49 @@ void handleCoordinatorReady() {
null;
this.coordinatorSupportsBumpingEpoch = initProducerIdVersion != null &&
initProducerIdVersion.maxVersion() >= 3;
+
+ if (nodeApiVersions == null) return;
+
+ if (nodeApiVersions.supportedFeatures() != null) {
+ /*
+ To enable the transaction V2, it requires:
+ 1. transaction.version max version >= 2
+ 2. The ProduceRequest max version >
ProducerRequest.LAST_BEFORE_TRANSACTION_V2_VERSION
+ 3. The TxnOffsetCommitRequest max version >
TxnOffsetCommitRequest.LAST_BEFORE_TRANSACTION_V2_VERSION
+ */
+ ApiVersion produceVersion =
nodeApiVersions.apiVersion(ApiKeys.PRODUCE);
+ ApiVersion txnOffsetCommitVersion =
nodeApiVersions.apiVersion(ApiKeys.TXN_OFFSET_COMMIT);
+ SupportedVersionRange transactionVersion =
nodeApiVersions.supportedFeatures().get("transaction.version");
+ if (produceVersion != null &&
+ produceVersion.maxVersion() >
ProduceRequest.LAST_BEFORE_TRANSACTION_V2_VERSION &&
+ txnOffsetCommitVersion != null &&
+ txnOffsetCommitVersion.maxVersion() >
TxnOffsetCommitRequest.LAST_BEFORE_TRANSACTION_V2_VERSION &&
+ transactionVersion != null &&
+ transactionVersion.max() >= (short) 2) {
+ this.coordinatorSupportsTransactionV2 = true;
+ return;
+ }
+ }
+ // Now, the broker does not support transaction V2. Let's downgrade
the Produce and TxnOffsetCommitRequest
+ // max versions.
+ downgradeApiVersionsIfNotUsingTransactionV2();
+ }
+
+ // Set the ProducerRequest and TxnOffsetCommitRequest versions at their
LAST_BEFORE_TRANSACTION_V2_VERSION.
+ private void downgradeApiVersionsIfNotUsingTransactionV2() {
+ NodeApiVersions nodeApiVersions = transactionCoordinator != null ?
+ apiVersions.get(transactionCoordinator.idString()) :
+ null;
+ if (nodeApiVersions == null) return;
+ if (nodeApiVersions.apiVersion(ApiKeys.PRODUCE) != null &&
+ nodeApiVersions.apiVersion(ApiKeys.PRODUCE).maxVersion() >
ProduceRequest.LAST_BEFORE_TRANSACTION_V2_VERSION) {
+
nodeApiVersions.apiVersion(ApiKeys.PRODUCE).setMaxVersion(ProduceRequest.LAST_BEFORE_TRANSACTION_V2_VERSION);
Review Comment:
I hadn't considered an approach where we change the values here. Is there
any concern for race conditions with the nodeApiVersions? Can it be updated by
a client at the same time as being updated here?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]