[
https://issues.apache.org/jira/browse/KAFKA-20734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18091041#comment-18091041
]
Artem Livshits commented on KAFKA-20734:
----------------------------------------
The fix would be something like this:
{code:java}
public Optional<Node> getPartitionLeaderEndpoint(String topicName, int
partitionId, ListenerName listenerName) {
MetadataImage image = currentImage;
return Optional.ofNullable(image.topics().getTopic(topicName))
.flatMap(topic ->
Optional.ofNullable(topic.partitions().get(partitionId)))
.flatMap(partition -> {
// If partition is found we must return non-empty optional.
BrokerRegistration broker =
image.cluster().broker(partition.leader);
Node node = (broker == null)
? Node.noNode()
:
broker.node(listenerName.value()).orElse(Node.noNode());
return Optional.of(node);
});
} {code}
> Offline partition can cause loss of transaction markers
> -------------------------------------------------------
>
> Key: KAFKA-20734
> URL: https://issues.apache.org/jira/browse/KAFKA-20734
> Project: Kafka
> Issue Type: Bug
> Affects Versions: 4.3.0
> Reporter: Alyssa Huang
> Priority: Blocker
>
> During the rewrite of the KRaftMetadataCache (as part of KAFKA-17573), a bug
> was introduced which causes transaction coordinator to drop transaction
> markers for a partition if the leader is missing (offline). Specifically,
> {{metadataCache.getPartitionLeaderEndpoint}} returns {{None}} instead of
> {{Some(Node.noNode).}}
> This bug can cause hanging transaction and lost commit markers. Thanks
> [~alivshits] for the identification of this issue.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)