From 5f77615f6adc4dbdebcfd0d35524c228508b400f Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 29 Jun 2026 22:54:46 +0530 Subject: [PATCH 1/2] KAFKA-20738: Allow InitProducerId v6 when 2PC fields set --- .../kafka/common/requests/InitProducerIdRequest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clients/src/main/java/org/apache/kafka/common/requests/InitProducerIdRequest.java b/clients/src/main/java/org/apache/kafka/common/requests/InitProducerIdRequest.java index 500e0ee898dae..5bbdbfa987e5d 100644 --- a/clients/src/main/java/org/apache/kafka/common/requests/InitProducerIdRequest.java +++ b/clients/src/main/java/org/apache/kafka/common/requests/InitProducerIdRequest.java @@ -16,6 +16,7 @@ */ package org.apache.kafka.common.requests; +import org.apache.kafka.common.errors.UnsupportedVersionException; import org.apache.kafka.common.message.InitProducerIdRequestData; import org.apache.kafka.common.message.InitProducerIdResponseData; import org.apache.kafka.common.protocol.ApiKeys; @@ -28,12 +29,18 @@ public static class Builder extends AbstractRequest.Builder Date: Mon, 29 Jun 2026 22:54:58 +0530 Subject: [PATCH 2/2] KAFKA-20738: Add InitProducerIdRequest builder version tests --- .../requests/InitProducerIdRequestTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 clients/src/test/java/org/apache/kafka/common/requests/InitProducerIdRequestTest.java diff --git a/clients/src/test/java/org/apache/kafka/common/requests/InitProducerIdRequestTest.java b/clients/src/test/java/org/apache/kafka/common/requests/InitProducerIdRequestTest.java new file mode 100644 index 0000000000000..d52fe957a6416 --- /dev/null +++ b/clients/src/test/java/org/apache/kafka/common/requests/InitProducerIdRequestTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.common.requests; + +import org.apache.kafka.common.message.InitProducerIdRequestData; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class InitProducerIdRequestTest { + + private InitProducerIdRequestData baseData() { + return new InitProducerIdRequestData() + .setTransactionalId("txn-2pc") + .setTransactionTimeoutMs(10); + } + + @Test + public void testBuilderAllowsV6WhenEnable2PcSet() { + // enable2Pc is a v6-only field (KIP-939); the builder must allow v6 so + // NetworkClient can negotiate it against a 2PC-capable broker. + InitProducerIdRequest.Builder builder = + new InitProducerIdRequest.Builder(baseData().setEnable2Pc(true)); + assertEquals((short) 6, builder.latestAllowedVersion()); + } + + @Test + public void testBuilderAllowsV6WhenKeepPreparedTxnSet() { + InitProducerIdRequest.Builder builder = + new InitProducerIdRequest.Builder(baseData().setKeepPreparedTxn(true)); + assertEquals((short) 6, builder.latestAllowedVersion()); + } + + @Test + public void testBuilderCapsAtStableVersionWithout2Pc() { + // Control: a plain producer keeps the stable cap, unaffected by the fix. + InitProducerIdRequest.Builder builder = new InitProducerIdRequest.Builder(baseData()); + assertEquals((short) 5, builder.latestAllowedVersion()); + } +}