Chia-Ping Tsai created KAFKA-21607:
--------------------------------------
Summary: AlterPartitionRequest.Builder should not modify its own
data when building an old version
Key: KAFKA-21607
URL: https://issues.apache.org/jira/browse/KAFKA-21607
Project: Kafka
Issue Type: Bug
Reporter: Chia-Ping Tsai
{code:java}
[2026-11-20 22:59:31,116] ERROR Request AlterPartitionRequestData(brokerId=2,
brokerEpoch=212, topics=[TopicData(topicId=QOFR6TgeTKKaZ_3SuYeO6g,
partitions=[PartitionData(partitionIndex=2, leaderEpoch=1, newIsr=[1, 2, 3],
newIsrWithEpochs=[], leaderRecoveryState=0, partitionEpoch=1)])]) failed due to
unsupported version error
(org.apache.kafka.server.NodeToControllerRequestThread)
org.apache.kafka.common.errors.UnsupportedVersionException: Attempted to write
a non-default newIsr at version 3
{code}
I noticed the above error when testing a rolling downgrade. One controller gets
downgraded, so the builder (see the code below) modifies its data. When the
request fails and then gets retried, it hits the above error because the target
controller is the new version.
We should just make a copy when downgrading the version. BTW, this error is
handled by DefaultAlterPartitionManager, which creates a whole new builder
later.
{code:java}
@Override
public AlterPartitionRequest build(short version) {
if (version < 3) {
data.topics().forEach(topicData ->
topicData.partitions().forEach(partitionData -> {
// The newIsrWithEpochs will be empty after build. Then
we can skip the conversion if the build
// is called again.
if (!partitionData.newIsrWithEpochs().isEmpty()) {
List<Integer> newIsr = new
ArrayList<>(partitionData.newIsrWithEpochs().size());
partitionData.newIsrWithEpochs().forEach(brokerState ->
newIsr.add(brokerState.brokerId())
);
partitionData.setNewIsr(newIsr);
partitionData.setNewIsrWithEpochs(List.of());
}
})
);
}
return new AlterPartitionRequest(data, version);
}
{code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)