Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ public int partition() {
return partition;
}

public int leaderId() {
return leader == null ? -1 : leader.id();
}

public Node leader() {
return leader;
}
Expand All @@ -482,7 +486,7 @@ public List<Node> offlineReplicas() {

@Override
public String toString() {
return "(type=PartitionMetadata," +
return "(type=PartitionMetadata" +
", error=" + error +
", partition=" + partition +
", leader=" + leader +
Expand Down Expand Up @@ -531,7 +535,7 @@ protected Struct toStruct(short version) {
Struct partitionData = topicData.instance(PARTITION_METADATA_KEY_NAME);
partitionData.set(ERROR_CODE, partitionMetadata.error.code());
partitionData.set(PARTITION_ID, partitionMetadata.partition);
partitionData.set(LEADER_KEY_NAME, partitionMetadata.leader.id());
partitionData.set(LEADER_KEY_NAME, partitionMetadata.leaderId());
ArrayList<Integer> replicas = new ArrayList<>(partitionMetadata.replicas.size());
for (Node node : partitionMetadata.replicas)
replicas.add(node.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ private MetadataResponse createMetadataResponse() {
asList(new MetadataResponse.PartitionMetadata(Errors.NONE, 1, node, replicas, isr, offlineReplicas))));
allTopicMetadata.add(new MetadataResponse.TopicMetadata(Errors.LEADER_NOT_AVAILABLE, "topic2", false,
Collections.<MetadataResponse.PartitionMetadata>emptyList()));
allTopicMetadata.add(new MetadataResponse.TopicMetadata(Errors.NONE, "topic3", false,
asList(new MetadataResponse.PartitionMetadata(Errors.LEADER_NOT_AVAILABLE, 0, null,
replicas, isr, offlineReplicas))));

return new MetadataResponse(asList(node), null, MetadataResponse.NO_CONTROLLER_ID, allTopicMetadata);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/kafka/server/KafkaApis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ class KafkaApis(val requestChannel: RequestChannel,
val coordinatorEndpoint = topicMetadata.partitionMetadata.asScala
.find(_.partition == partition)
.map(_.leader)
.flatMap(p => Option(p))

coordinatorEndpoint match {
case Some(endpoint) if !endpoint.isEmpty =>
Expand Down